import swarm.Selector;
5 f( }8 o6 p0 R) U( }
8 L* D( m6 R9 w/ p* apublic class SwarmUtils {- w! N* g9 I z/ A( j9 I# ^8 L
public static Selector getSelector(String name, String method) {0 W( b4 r0 W+ a8 ?7 {" q
Selector sel;+ n; W R) y9 a( D6 S
try {
+ y. d0 ~4 z% d& U' y sel = new Selector(Class.forName(name), method, false);9 U( Z: h$ _, m. D' y t
} catch (Exception e) {
) J( ^& J W9 X, @8 | System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");- J- d( K) ~5 t5 W) o
System.err.println(name + "." + method + " returns " + e.getMessage());" N1 S5 u4 U( w! u! ?' T0 ]
System.err.println("The process will be terminated.");( B& d7 | G% L' J( Y/ @
System.exit(1);$ {* J. G U& x
return null;% q$ _7 B9 G% L3 D4 x8 i3 `5 Z
}
3 A# u: }/ ~; h" Q/ @6 j3 r) o7 Y return sel;5 X1 _1 y/ |( ~* q; M7 f
}# o: B& W& |. x+ x8 O6 E
2 p; S- @3 Q. f8 T9 c3 ?7 @- G
public static Selector getSelector(Object obj, String method) {& f. E% W; s3 b% H$ K, S }8 R r
Selector sel;
2 G& P# g7 K9 A/ r try {
7 H) d6 H% X7 r A( O sel = new Selector(obj.getClass(), method, false);
( I$ }5 G& L# }4 Q) n } catch (Exception e) {
2 N! j2 r: N# M d; }9 x& p System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
]- B9 H% g8 v8 N( k7 N' n + (obj.getClass()).getName() + ".");5 I" k) l5 W; ]. r; h; p0 c6 f) W0 c
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());0 m9 o9 [7 ?5 u& M( U( `
System.err.println("The process will be terminated.");) c0 u6 d2 R' S/ {; O, D
System.exit(1);$ D$ k; j! Y/ Z3 j& Z3 ~* D
return null;5 K. y$ H+ Q& `7 h7 L# J& h; e
}
1 K4 V2 `% O1 J% @ return sel;& I! X6 A8 s1 g1 y+ N+ I# Z4 B
}. o3 r4 l( J9 X% C
} |