import swarm.Selector;
, T1 M0 G( D( I& D" j2 t C% e4 g% g, `+ E) ~( r7 t! f
public class SwarmUtils {
8 S& I! ^8 Y# P+ D; d5 b; L2 c( X public static Selector getSelector(String name, String method) {
( H( C$ G4 a* \) s) R Selector sel;
1 ^8 r! l2 W% d' R0 ^- K% e try {: p( _; ^0 U. `3 m- \$ c: ^
sel = new Selector(Class.forName(name), method, false);
* }' ]& x& V5 q: N; S } catch (Exception e) {
( Q d% L3 O2 y% T; [ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
o' _8 u8 g/ u% B) r2 b# w5 ~" Q System.err.println(name + "." + method + " returns " + e.getMessage());" Q$ Y7 f% d' b- d9 @) A$ q
System.err.println("The process will be terminated.");0 k G9 T% k+ P- Q
System.exit(1);' b: g$ w% f P3 s. c
return null;
. R& Q: G! E: x6 w J" } }9 H) P& w" v: a$ w: x) j
return sel;' G1 N1 J1 @5 \$ s
}+ }6 W* O6 e1 V8 W5 c% v$ [- {# P$ K) J
Q' k( a6 p8 Q8 t3 W7 C$ l! |
public static Selector getSelector(Object obj, String method) {
& f9 K& J! [- b, v, ] Selector sel;+ k2 W9 z- X$ a; `6 p% S
try {
% m, F. ^% A/ O3 q( Y2 g$ p/ }) I sel = new Selector(obj.getClass(), method, false);4 s' ~# y. h& M! p* E
} catch (Exception e) {
' s. k, P; R9 X, P6 h, x: E System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
' P- [; q# e- C' J3 ]$ M + (obj.getClass()).getName() + ".");
l+ W9 G! r! M/ E; @ System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());8 c9 }* ~: N- }7 V& K( a& R4 B. h
System.err.println("The process will be terminated.");
+ m# F; d( K& O2 ~0 y+ N System.exit(1);
( y4 M1 |: V6 [ return null;* j& d z( O; W( b4 k2 B
}) U: \1 r1 d( a* u7 S2 W2 |7 e$ V
return sel;
$ ?3 U% S' b* t2 ]2 i }
( W8 x9 F! N$ m& F$ A/ k% w- g# r} |