import swarm.Selector;
, ^1 M1 I% m& \5 o7 g/ h$ q
( r# v, ^, l+ ~* bpublic class SwarmUtils {
, K5 |. R, ~: t) h Q9 p6 w% | public static Selector getSelector(String name, String method) {
" m% O& A& {( v# d3 ~, b3 M5 E3 c Selector sel;
6 s; ~7 A' x* S7 R try {$ x# z+ L. ? T2 M* Z% J
sel = new Selector(Class.forName(name), method, false);/ O9 n1 p& z$ ^* Y
} catch (Exception e) {
, V' G1 ~8 w8 A# @% |- ~ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
) i: T3 t w2 w4 o5 H$ c0 h2 s System.err.println(name + "." + method + " returns " + e.getMessage()); r9 M+ m8 S3 _( F
System.err.println("The process will be terminated.");
` V# p4 k! F( r4 N- y* k3 s System.exit(1);$ l/ l: C V, v$ @. g7 N
return null;
+ O2 Q: a: ]8 j* Z ` }) r$ c' G$ K1 v @# u
return sel;
) R6 m5 t6 n9 t) P6 C! B7 C }
, S* K2 M! R9 l/ c
) j& |% r+ m5 N+ p: J( g public static Selector getSelector(Object obj, String method) {
0 U7 p8 f* U: f3 D Selector sel;
8 i @) m/ {7 E1 O' a4 q! Z$ c7 w! y try {
/ H- R8 @8 ~! X2 t! _% V- h sel = new Selector(obj.getClass(), method, false);1 V1 q. p5 z7 L7 |
} catch (Exception e) {
% U+ ]& s7 T& `2 J System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "; Y6 q- [( M$ w
+ (obj.getClass()).getName() + ".");4 Y7 G: t3 N! |, S
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());) {9 Z5 X! n9 K' P \, R6 U. E$ _
System.err.println("The process will be terminated.");
9 F! I+ f, t1 ^; @6 U3 _, U( R System.exit(1);
6 B! c. }& e# x, ^0 I return null;
$ x) r1 q( |5 Y$ A2 e9 P }( M( _* c, ?& o+ d$ q" @
return sel;0 g& `! x* O% r$ G+ q! y
}
& v: v) I: P6 R- H4 f1 s3 I1 W; b8 \) w} |