import swarm.Selector;3 t+ A9 u( V+ K$ `* A
6 V. V9 @; ^( d. l) \public class SwarmUtils {* V9 }! g8 k/ T( U
public static Selector getSelector(String name, String method) {
" F9 o2 K+ p) a; T' e- I Selector sel;
' ]; x" G$ I2 \1 G1 g' S try {- W1 B2 R* R4 I4 H. U
sel = new Selector(Class.forName(name), method, false);
* H& }# z/ Y1 y4 N4 S4 c } catch (Exception e) {3 } D* R E% v- G7 K
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");+ q1 [- B! F% m* V# [# ~
System.err.println(name + "." + method + " returns " + e.getMessage()); r% }; J+ w5 p3 d$ j% ?
System.err.println("The process will be terminated.");
, Y2 }4 [7 {. R7 ^ b! |1 J# x% y+ c System.exit(1);, H e" s% j& t
return null;
( f0 K( O! b* I0 J1 a9 ?; _2 A2 O }; d* v7 p+ g6 |) `# [
return sel;2 ?7 p$ l I: Z- j9 n& m$ @) e
}
/ R; t D& s; l1 r! X
2 F& k7 `* x; H7 h1 d& u g public static Selector getSelector(Object obj, String method) {
9 f: ^5 ]3 ?, s: x9 j. D) e- M Selector sel;. [ N4 E7 O" d0 i
try {
' ^( h# H/ F: f! C: c5 U sel = new Selector(obj.getClass(), method, false);
4 S. E, z% l# v) [2 ^$ y# |' b } catch (Exception e) {
) a' d1 @ K& E. e& _$ u' } System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "$ ?7 G, j+ K t7 j6 f' d) W( ?/ U& l
+ (obj.getClass()).getName() + ".");: F1 Z+ R2 i2 \, T& G) z0 M
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
* d& {! A7 J5 v$ M H System.err.println("The process will be terminated.");
+ n2 l$ F5 Y: q$ B! b' R System.exit(1);
# }0 N, Z. Q0 ~$ | return null;
& c) Z! S8 ^/ S2 e! e }
' H/ d. k5 _* A0 y return sel;9 n! ]$ I! F% r- V0 n3 s
}9 r# j$ \4 G/ w' [( M9 g
} |