import swarm.Selector;
- F5 ]1 M* K/ [4 N: Q8 a/ v$ x: E& n; h; y
public class SwarmUtils {7 `, d& W! \! i% D! N
public static Selector getSelector(String name, String method) {
: G4 ]3 V6 s: _# m/ G Selector sel;
5 D6 u2 H7 z+ l7 Y ]( i% I7 D try {8 j4 P! {2 K! P
sel = new Selector(Class.forName(name), method, false);
, s7 P% c- [: m: `2 m# w } catch (Exception e) {
8 N& u! {5 c# b6 k System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");" N; A* g: l' h5 C- ]
System.err.println(name + "." + method + " returns " + e.getMessage());
6 U) ]* q. x- n! K7 j System.err.println("The process will be terminated.");: {+ c" `+ R+ S/ v3 ]6 n& A7 V
System.exit(1);
( Q2 S1 b8 E) Q3 j: [ u- x6 f return null;
) K/ H( E2 O% ]# i0 \. S }3 F" o3 U/ k' Y8 ?
return sel;1 ?- P9 y% ]4 s( Y' O0 q
}
p- Y) O9 b6 ]3 d8 K* ^: k% h% V2 P" }+ _2 u3 p3 U6 d" u
public static Selector getSelector(Object obj, String method) {3 S5 p' v0 J+ x
Selector sel;
# m2 e0 W5 L, W try {, d) d$ ^( T3 s/ B7 L
sel = new Selector(obj.getClass(), method, false);* t' i& E) u3 r. ^* w8 A9 A/ I- R
} catch (Exception e) {
: Q8 [- }6 _; u6 i7 c4 L9 V System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ") c% _ m4 V7 E: D7 i V
+ (obj.getClass()).getName() + ".");
# p! f, _+ i- Z' q System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());/ E" P y) T% i- o; u
System.err.println("The process will be terminated.");. x6 w. e% {) N" U: p
System.exit(1);
( }5 t* \# e: i return null;
a9 v7 G, j7 W. k& z1 Y, r! A" v }
2 x% J& x0 q* N: U' G! y- ~0 j return sel;8 F6 m/ s4 _4 }. l- \2 F( Q
}
8 @. S& T- ?5 j7 o$ E- W2 W} |