import swarm.Selector;" T# X& T$ o V K9 j# J$ ]
1 W5 y" c8 O! \, t
public class SwarmUtils {
" R4 n* Q' L2 |- D9 \ public static Selector getSelector(String name, String method) {
- g- q) ~% [+ }; X- c! W Selector sel;
( j1 P+ y) e4 `: s1 x$ J# K* J7 l: G try {
% f Z; n. \2 t2 w& X sel = new Selector(Class.forName(name), method, false);7 L M; M" G9 Y9 |5 }- Z
} catch (Exception e) {
: F4 O$ D2 }2 z! l4 M System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");" ~+ M) H2 T% B
System.err.println(name + "." + method + " returns " + e.getMessage());) _8 G4 x; p. e8 |! A8 S
System.err.println("The process will be terminated.");
3 d) L: R4 k( {' ?: b System.exit(1);" y5 {* L5 e, l i
return null;* o3 O) E4 j, K% j4 }
}
) u7 h3 y5 t. b, r& e return sel;6 g5 ?; n) U+ l1 {& G9 i
}* F( P, b+ J' l8 ]
. Q+ |: F8 }* Q7 d/ Z
public static Selector getSelector(Object obj, String method) {# i7 I f4 L% ~! t
Selector sel;
# J% z- K+ Q5 e& M4 d4 [ try {3 q1 z: j: |' {2 z$ L# C# T, [: N# O
sel = new Selector(obj.getClass(), method, false);
7 x4 l4 O+ U, t$ _4 p& D& @ } catch (Exception e) {
" G3 ^2 p4 f3 x8 ?/ j System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " F4 \* w( B/ g# c. }
+ (obj.getClass()).getName() + ".");
5 p: r6 A, k5 ?1 `3 e System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
* ]8 c1 Y; w, M3 m) K System.err.println("The process will be terminated.");/ u3 [( m* F9 L: Z' b
System.exit(1);4 e0 W8 V- d ~' z: V* ?
return null;, [% u3 b% v0 A4 m/ L8 i
}
n- |( C" H( Y2 V: f return sel;% A" f6 o+ c7 X7 E5 I# n0 C
}; ~) r. N U! p1 Q
} |