import swarm.Selector;
4 e6 Y9 w/ t6 y
) C) W. I( j3 O( J: V/ T8 K" fpublic class SwarmUtils {, N" {. w0 g% P; m- H' d2 _
public static Selector getSelector(String name, String method) {
# Y& n8 w3 P3 p+ E8 ^. y Y+ ~ Selector sel;8 x& g/ v9 S* p; W+ I
try {7 N5 j& \, h+ c+ x
sel = new Selector(Class.forName(name), method, false);
# \" t7 U/ m: T3 A7 M! }# s } catch (Exception e) {7 q8 `8 F! k0 ?9 n3 V9 P
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
) ]) H, u, P7 j' {/ E System.err.println(name + "." + method + " returns " + e.getMessage());$ P1 o1 A, S. u* w: Y3 Z& X
System.err.println("The process will be terminated.");
. W: q9 Y3 e; j% s4 S8 S System.exit(1);
4 k3 Y+ Z/ o8 v6 E; j6 F4 g return null;
" k5 I2 j, J Z+ B; e* z }
" Z, H4 @) K5 S return sel;
0 N* f+ _/ E$ r/ b }
Y" K' b7 G9 x5 \+ j. x! C- J3 ?2 r) l3 U I
public static Selector getSelector(Object obj, String method) {2 j8 b6 R1 n2 p9 @% K; l
Selector sel;
/ j( N1 |0 x# n' j; M try {* J C: O R y: b/ H
sel = new Selector(obj.getClass(), method, false);
( {! L* Q8 Z6 k9 e } catch (Exception e) {; n( B7 z( }* V9 K! ?
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ": k( T) M$ j, z& i2 g. h3 _
+ (obj.getClass()).getName() + ".");3 g: q# c! u7 y$ d' ~1 G5 u
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
$ s9 w3 w$ J9 ?3 V1 L8 L System.err.println("The process will be terminated.");
( Y8 R/ k& i$ s8 O4 H System.exit(1);
* Q% F$ Q+ `$ i% O* U( a |/ z9 \ return null;% k% V- t+ n6 V, v) f. ^# J
}+ T' Q+ p2 ^( g
return sel;0 p/ _/ Q7 \; O+ A
}" t; \/ R. u) E) o% x
} |