import swarm.Selector;- k8 k1 q; y1 _
9 n6 S( |1 m2 A# o
public class SwarmUtils {
) @( |2 G5 r* n- L+ | public static Selector getSelector(String name, String method) { j. M; b2 G7 ^
Selector sel;
0 i1 u# p; ^1 o2 p9 E o, _ try {* N+ o/ a0 U7 o& o
sel = new Selector(Class.forName(name), method, false);
! {$ T/ U9 f7 \; g! ^$ a/ a } catch (Exception e) {9 [& I; g5 q. a, x3 y$ H
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");: ~; u5 m C7 n0 i! O
System.err.println(name + "." + method + " returns " + e.getMessage());
5 k7 h& ]9 x# x% L/ ` m System.err.println("The process will be terminated.");
9 S5 R) i& Y, S5 M" U+ g0 W System.exit(1);; A3 m8 v! y7 v( Z8 `
return null;% [' ?) G1 _( |' o9 R3 z
}
& G) F( @ L3 h$ L5 S- Z8 } return sel;
( X8 k2 w, W4 S* e9 k }; Z2 w: r6 B$ \/ L/ ^$ B8 E# _
& }; t; k) E; l( v3 @5 b3 a
public static Selector getSelector(Object obj, String method) {. g; b6 J: f. O) F. F% H$ L9 M
Selector sel;+ |3 F( T/ W6 m+ t3 @
try {
$ R& `! t8 |( \: ~. O/ a9 f9 @ sel = new Selector(obj.getClass(), method, false);# C. p2 Y. z6 s
} catch (Exception e) {
+ s" a7 w# M8 w: S System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ") ]! T: o0 Y# F% G. Y
+ (obj.getClass()).getName() + ".");
+ l2 N- i- k$ r! m: }/ t; `! E System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
# z( A3 {* j+ I$ }2 b System.err.println("The process will be terminated.");, ?0 p! h H" h
System.exit(1);
, k I( N% d* s7 Q/ \( U1 | return null;+ p6 ^" X1 l r% G
}
# r4 |1 M; I2 B) M) h' {5 I return sel;+ G1 E: v0 ~. X
}9 B1 a l: N4 [+ z7 }/ o
} |