import swarm.Selector;
8 Q5 W0 x7 K, E5 w; l. S, Q! O9 Z V! ]0 P9 g
public class SwarmUtils {
1 O' s& r% e# e @: i5 T, E public static Selector getSelector(String name, String method) {
' e( F9 r* ?$ k Selector sel;
9 {& S2 E9 Q# o! v1 V. h try {7 z: u z [' ?0 T2 Z5 y
sel = new Selector(Class.forName(name), method, false);
+ @9 O2 T+ r% o2 H* y" V } catch (Exception e) {
( h' G. X: O: r" Q" k System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
# Q/ [+ U9 s5 t6 [9 a, W: |) C System.err.println(name + "." + method + " returns " + e.getMessage());, g; o8 j1 t' Y7 K# T x/ w
System.err.println("The process will be terminated.");
, Q0 r8 n) b/ `- b* ^, x! { System.exit(1);
' U& ?; E" h$ P4 q return null;
& j9 i# g' ^9 z5 n8 o }; R4 p1 _4 Q1 J% n5 x X0 I
return sel;: u* k- C& B7 r
}
5 K+ z9 G& x$ ~. T; g# P+ h& j' i3 _ r8 T
public static Selector getSelector(Object obj, String method) {+ v0 ~" O C! Q. ^8 C
Selector sel;
) p; m$ ~; ~3 X7 \8 E$ { try {+ \ V- e3 \2 n- v$ A) N
sel = new Selector(obj.getClass(), method, false);- k) n( ]- _3 o' B' Y3 }/ y
} catch (Exception e) {( G( b4 o. i* q/ P. i j
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
' c m X4 z* N! Q; U/ ^& y + (obj.getClass()).getName() + ".");
X' U& ^2 [. F* Q. R+ z System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());. a% M1 m$ ^, g. u& Q3 @% A
System.err.println("The process will be terminated.");: K7 ^& A! w9 s) W6 [1 B* h
System.exit(1);
$ V/ f1 E& M; A: n" F8 K3 j+ p return null;+ b! z, r; f9 S/ a& D$ G$ F" N
}# N9 e( R$ x0 i" e1 G' d
return sel;
1 Y: l. _9 o$ T" [8 c$ l }
6 K0 \0 A s b( }} |