import swarm.Selector;
- g, w6 K. r: Z% U- M# @ v- |! y& e
" ~/ D. u# v) F0 upublic class SwarmUtils {
. ~8 |5 o6 u1 h- N public static Selector getSelector(String name, String method) {
; T3 h) D5 Q) i8 U& P+ S Selector sel;
' C# s/ \: n5 N8 X c: W6 Q try {) |4 p" |/ Q( Y* z+ n
sel = new Selector(Class.forName(name), method, false);
' r$ M* [ u3 u: [ } catch (Exception e) {8 I8 z1 Y! S9 ?3 {, F9 M$ s
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");) x# ~! k, E. h! q
System.err.println(name + "." + method + " returns " + e.getMessage());0 q' J8 k6 _/ k, r p& a: }6 c1 `
System.err.println("The process will be terminated.");8 \( J4 \. l; Q8 W6 u9 ]
System.exit(1);* Y0 r$ W2 {- \, X
return null;
& Z* O C6 U5 h' Y% ] }' _5 k6 y! d% l P" k) @ I% Y4 K
return sel;' N8 g/ k& S- C! X) Z
}9 U1 R9 {" [1 G P7 ?4 s) E/ Z
# Y ]7 g9 g9 e% E1 `2 V1 n- G1 G
public static Selector getSelector(Object obj, String method) {
" _* r1 k, B" \% ?2 n4 @5 p Selector sel;
& e6 e; {% \ S1 x: J: H try {
# [6 R1 e E; x' x9 |5 \ sel = new Selector(obj.getClass(), method, false);, `! h, d& b) m6 T1 g$ @' C
} catch (Exception e) {5 E3 x! w5 U1 F' q, ?& J# }. I
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
( Q( u/ W) _* a3 w/ Q: y- O + (obj.getClass()).getName() + ".");# [: d& @( g2 k
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());- e, `& ?* [0 q
System.err.println("The process will be terminated.");5 T& {2 w3 j% h: v# a
System.exit(1);1 ^9 y5 T, i9 ` J
return null;# \) B: W( ~1 }5 G. x1 }
}8 D' u9 m( W/ a8 E
return sel;
S6 c5 J' j- e5 O4 o }: f f* r. |! |0 M
} |