import swarm.Selector;: U! y/ ^' q# n- y* B
) i% k+ o! ]1 W7 L2 J( W, w
public class SwarmUtils {: v9 t" ?- ]0 j0 [# Y
public static Selector getSelector(String name, String method) {$ i& q! L" F! h* f
Selector sel;, M+ E1 Y) i" N o" X" U9 |4 k D
try {
2 j3 D% i7 _0 ^" c8 V- Q: X+ X2 E sel = new Selector(Class.forName(name), method, false);
" G9 F0 U& h0 y } catch (Exception e) {9 e2 o" m" T) r, z' \% v
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
# q f; Y+ G2 ]' | System.err.println(name + "." + method + " returns " + e.getMessage());4 I1 }) n' I$ E2 e$ A/ I
System.err.println("The process will be terminated.");
& F$ A" }: r& w8 r0 U) n, j System.exit(1);
8 S' A. L' i( ] return null;
5 o. o: {, t+ b3 H# y; a }7 X+ U) H/ N" N) k. |+ Z: \; [+ I+ p0 _
return sel;
- ^5 I* m+ q k, b }
7 q) H2 h% y# ~7 n4 T6 n h4 Y3 l" l
public static Selector getSelector(Object obj, String method) {
3 D. U2 V+ x6 b, S Selector sel;1 ~ m5 y# T. Q. N1 K4 T" v0 X
try {& I2 E& `' `, [9 j& W
sel = new Selector(obj.getClass(), method, false);
: Z" D2 G* t3 r. x# D } catch (Exception e) {, @9 a: T E5 V/ M0 \
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "' c5 U4 |9 M' m' S9 {
+ (obj.getClass()).getName() + "."); b' o! A, q9 I4 { m
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());6 h: K# y6 F; v+ T. g. [
System.err.println("The process will be terminated.");
1 N4 G/ F5 T# w) J3 s# h- C6 O" R System.exit(1);7 {2 f% [, R6 N* \7 N. O( n- L
return null;3 M5 D x/ O5 w/ H. v3 z- A1 O
}
, X+ }. o" t% q% ^. j2 j return sel;
% i1 V2 `7 s/ k9 |) a& _$ e5 s }# {5 T- S) j! p( [4 D
} |