import swarm.Selector;
7 ^) p: L3 F F+ f
2 U# N. q) Q2 a; q8 tpublic class SwarmUtils {1 _* K( W( A# ^) b7 c% Q
public static Selector getSelector(String name, String method) {
2 f% H: g, v8 f7 O# a9 e Selector sel;
) [# P2 J) e- y. q1 h1 X" P try {7 K. ~. }3 I* @: c
sel = new Selector(Class.forName(name), method, false);
3 T$ u- `; |0 j& w, B9 q } catch (Exception e) {
8 M8 N9 j' M# y. t2 Z$ M; }8 p% @ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
! r$ E: I2 _$ z System.err.println(name + "." + method + " returns " + e.getMessage());
" a" |: [; _6 [8 e System.err.println("The process will be terminated.");
' l' t5 c/ \( J8 Y% n" v! x: X System.exit(1);
5 I( A" N; c7 [- b. U return null;3 C# x5 d. w7 G# v3 T* H2 k3 S
}
% z0 X3 e5 T6 X$ i return sel;. r8 O, c0 N+ d2 Q: f( s# e* ~% c
}
}9 Q" m9 x7 _! a" {2 Q7 d8 J# j1 y/ R/ l4 K, M
public static Selector getSelector(Object obj, String method) {
! M; ^: J1 M- C" M Selector sel;8 Y2 ]* s" r5 S$ A- t, d2 P
try {
( S: |2 Y( S, F% u+ W9 @" Y+ n sel = new Selector(obj.getClass(), method, false);" M, Y9 U1 ~( W6 i' f5 G
} catch (Exception e) {6 X% R( v7 `# W: |
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
7 U/ [6 @' I( u4 N; |1 @( E + (obj.getClass()).getName() + ".");
( ~8 D' B8 G& }% @0 G System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());9 n, i3 N9 Q% g6 E* z$ r* J
System.err.println("The process will be terminated.");! K9 ~( o! u1 V) X
System.exit(1);$ G4 j7 t/ L' |# w
return null;8 a& a/ Y' B- \5 @
}
4 Z; n, h" q3 Z+ S, Z return sel;
2 v9 x1 s1 ]' J3 S/ X }
W2 b0 x1 X! [3 y) e7 |4 P( h} |