import swarm.Selector;8 s4 f+ D9 R% J+ f) h! ]4 B
/ q' ~4 G$ s5 Q" R, |9 g
public class SwarmUtils {
- ]- Q7 \. `- ]; D public static Selector getSelector(String name, String method) {4 B0 k1 e; }0 `- B) `
Selector sel;! w% F6 d! @8 d0 P3 H" x+ u2 q" Z
try {9 o2 ~" U# ]5 a3 }. c2 j0 q
sel = new Selector(Class.forName(name), method, false);+ s$ E9 b% O6 j. k
} catch (Exception e) {& f; C: z* L% U; d+ Q
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
4 U4 Q: `/ C! H; @/ N System.err.println(name + "." + method + " returns " + e.getMessage());
+ {1 M+ T7 \5 G7 ^1 P6 B- ] System.err.println("The process will be terminated.");
+ ^( K8 V& o$ v& e) [2 {) c+ { System.exit(1);
. V" A8 q" [" \ return null;
4 f" W2 [' w! V7 Z V& Y1 V4 V" w }
1 D, g& O8 H u" L$ b; S return sel;+ T6 W f: X* f) L3 q+ P. f, K; f
}
9 B% s6 T- _; f" k1 l: ]4 G r- v9 v( z8 t: ], N
public static Selector getSelector(Object obj, String method) {
4 T& P) |& w) | Selector sel;" B# @6 x5 V6 C, m, s+ v0 E
try {9 z8 O2 i8 n2 V! [) o6 a
sel = new Selector(obj.getClass(), method, false);( y8 K+ S3 K5 Y; d5 W* |$ g
} catch (Exception e) {7 N8 `7 B0 y& c9 N) }
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
& \: p% `" O$ k3 G& s + (obj.getClass()).getName() + ".");
# D+ J* S% V$ H! c5 @6 L' i8 G( c6 | System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());) a0 {& Z6 z* m$ y8 F% X* s
System.err.println("The process will be terminated.");4 w6 }% J3 L5 Z- p
System.exit(1);5 j% Y" }) S, R( r: ^, X
return null;
; z% ?& J1 ~9 @$ [7 a }
) Y/ j/ w( x( J' r+ K& k9 z return sel;9 ]2 P' C% j3 i+ }- }4 x0 ^
}
* V: @+ ], a, Q} |