import swarm.Selector;7 m8 S9 q" f5 {% x6 H! q& O5 r$ b" y
: p& Y7 a5 J2 ]6 P1 m. F/ ipublic class SwarmUtils {
4 o/ T6 q8 m$ g% O public static Selector getSelector(String name, String method) {
+ W: O- {2 R# j! ^3 }$ w Selector sel;
! A$ |$ K4 z% M4 E: c, b+ z, H try {
2 f- m/ G! q) [" t6 C+ g# \5 I sel = new Selector(Class.forName(name), method, false);
6 R3 P8 d8 w- g$ \ } catch (Exception e) {& P( Q* o, s' A: ^ e$ C" M) s* H9 Q
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
3 N# C" X2 p2 J, Z System.err.println(name + "." + method + " returns " + e.getMessage());; b9 ]' ~: H' c0 V& H
System.err.println("The process will be terminated.");
1 w: c+ I) I( E0 f! { System.exit(1);' h9 C' }. i( i' o
return null;
: j4 v0 F3 Q4 s }
3 s; \- a5 O7 n$ B* O1 f3 P' ` return sel;2 E0 @2 A* _5 x) \% P0 q
}3 b$ H$ o4 ^9 R2 X) J% T
$ O, u3 U" |+ { f3 Y6 s* l+ `
public static Selector getSelector(Object obj, String method) {4 ?# S$ g7 j6 L6 h
Selector sel;
3 @7 I* j( k: B4 z; v try {
$ k( R, a2 _ I+ W4 f$ B1 X sel = new Selector(obj.getClass(), method, false);6 u/ G6 Q7 O0 w! ^2 X/ f$ P
} catch (Exception e) {% u- B1 S, d: N4 o4 w
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
8 ?' S' X- x: u0 f! C Y! X9 } + (obj.getClass()).getName() + ".");
. S# [+ ]9 r+ b Y6 e System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
S- T" `" Y: B& N System.err.println("The process will be terminated.");
4 n6 |9 v! Q" K3 X7 W System.exit(1);
' }% q, Q2 t, E return null;
+ O6 W' B' w9 j2 [ }/ A2 c& a7 O2 E5 _: E; s5 A4 e
return sel;$ u k) }7 S; C" P0 v+ W( w$ R% R
}
" r' C4 `. Q$ P" O} |