import swarm.Selector;) H2 z8 k) Z5 j/ ^
, v; ?1 Q: x+ c" b; e" ^0 ?9 Q
public class SwarmUtils {+ l+ L2 e0 s+ t7 z
public static Selector getSelector(String name, String method) {3 m% g; ~' Q! c' K6 K$ X$ s# v
Selector sel;
& `' |! P! q$ u$ s0 q/ c3 Z try {
7 c D) H& H6 H( C sel = new Selector(Class.forName(name), method, false);
* X+ e* k1 C% ?, u" X1 o2 V1 w } catch (Exception e) {
# {2 N" p6 e6 g7 |7 v2 a! c2 e System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
% N$ h, w' C( ?# ~ System.err.println(name + "." + method + " returns " + e.getMessage());: J, C+ a) x5 e% |# Y) e
System.err.println("The process will be terminated.");% i2 h. B% G! O1 _3 N
System.exit(1);+ a$ ~/ w0 n+ L% T! u
return null;
7 ~/ |# o1 @3 R$ T& U, M, @5 c }
" o0 I/ v3 ]; }- W3 w) _ return sel;# J) x& B" s: Y+ N
}
! _) U0 H, N* o
' `1 y! m5 t, q9 Z7 N public static Selector getSelector(Object obj, String method) {5 x1 n8 U4 ?. _7 e
Selector sel;, Y3 ~# ^# s" a6 G
try {8 }2 R/ J8 K1 {( y* ^* e
sel = new Selector(obj.getClass(), method, false);0 I+ R: C; K& U, b6 I7 p5 I, }
} catch (Exception e) {' j0 |* Z5 C3 o. s( m9 I2 q' X7 f
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " ^/ V0 N r" x, m7 S8 n# L
+ (obj.getClass()).getName() + ".");
# R: [: G. s$ j System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());% P. n) h1 m" ]
System.err.println("The process will be terminated.");
3 @; U# j0 }- _7 a System.exit(1);
; H9 p3 Y2 \8 d4 Y return null;
5 p1 |) ?# W! Y5 j5 r# V0 N }
: d) G3 }( O% ^8 h, O7 X return sel;; ?( ?7 L# J7 y- n/ h( h
} q$ f: C( a1 q5 s$ b
} |