import swarm.Selector;
- B' Q( x2 Q( P+ z& l& U( D, r: j& _
public class SwarmUtils {% z. Q5 Z; S4 P9 w) j y
public static Selector getSelector(String name, String method) {
5 y4 o# Z5 D t& H# n5 t9 B* Z Selector sel;$ E H3 c5 y$ @) |0 W
try {
6 V4 V G6 ]- ~# s sel = new Selector(Class.forName(name), method, false);( R; z4 S3 I1 y/ P2 ? | r
} catch (Exception e) {$ Z# z) ^* i" t" h( |
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
" O6 c. |2 C3 F6 h! |3 U+ u2 @+ ~ System.err.println(name + "." + method + " returns " + e.getMessage());
( ?: E) t# ]: S# a/ u. ? p System.err.println("The process will be terminated.");
! o+ P+ @& }1 D* {% S+ j$ ^ System.exit(1);
3 ]7 O1 x; }' K3 a ^3 o return null;( N3 B" q- B' L# Y, c( i: R
}
1 t; a2 y" I/ q2 i( q7 ^ return sel;0 x }8 N( j' v2 o7 F0 R
}
5 O8 G4 }( o# ]* p1 n4 M! w
) F# d% e7 O T/ L public static Selector getSelector(Object obj, String method) {
6 B% Q0 U# o# u7 D: D) E1 b( a8 M$ ] Selector sel;
' K( M! ?4 l- p8 v3 S7 Y2 E" i) z6 a try {
) v& E }9 S+ F# W: y sel = new Selector(obj.getClass(), method, false);
* X: W/ ~1 f. ? [. W% s } catch (Exception e) {+ M2 n1 j( Z1 f8 i$ y p6 c, j6 h9 c
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "! t1 m- Z3 e3 e
+ (obj.getClass()).getName() + ".");
# @- \# Z1 O) W* i# j+ E: w& \, U System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());* {7 I8 X" `$ H7 F$ e
System.err.println("The process will be terminated.");
9 j' v! Y i! v8 [' x$ ^# I. R' N System.exit(1);. A5 f5 D4 T5 F8 d$ h% I
return null;8 E/ J& t" U6 h3 e
}$ h* ]/ T0 ~; Z( H
return sel;" R6 s' P0 d7 |9 Y
}4 m* j8 E; W; R, U+ w5 `9 b
} |