import swarm.Selector;
5 w0 M4 z: R( ?
; ^) e5 b' ~9 l9 o, Ypublic class SwarmUtils {
8 c8 X* X3 ^6 z7 ~ public static Selector getSelector(String name, String method) {
2 k" l7 N) B, F" U0 J2 [ _ Selector sel;% O M$ v" r5 P. D7 L3 G* ]
try {6 E N2 a9 o9 s
sel = new Selector(Class.forName(name), method, false);
% N v4 n6 w4 v2 Y0 p3 w3 A! } } catch (Exception e) {0 M" u9 Z g- r4 Q2 M
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
l9 T3 l6 {$ C( t0 w System.err.println(name + "." + method + " returns " + e.getMessage());4 W J+ X8 N" y/ v) _: G
System.err.println("The process will be terminated.");
- i& M8 ~0 ~" I- Z/ U System.exit(1);
- w3 V# e7 w+ u return null;
& S1 N# p, {& }) X! G. f }2 u8 ?! i% {& s! r. f: q( \
return sel;
% G8 w4 c) W1 \. f9 P }
m& `1 E! m7 r' G; x( v* ^
0 D2 }$ k& g4 H public static Selector getSelector(Object obj, String method) {: q7 ]" k, c0 h! D* [0 ^
Selector sel;
8 `. _' ^" Z0 { try {8 p1 K$ q" w- x) Y
sel = new Selector(obj.getClass(), method, false);' N" h q, I; L9 V
} catch (Exception e) {
- P- Y7 @( B# y System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ". {: l2 o! n- S: o. ?' g; W
+ (obj.getClass()).getName() + "."); u" J9 [) m2 F$ ~: I
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());* x1 I$ l# e1 J h$ X( L
System.err.println("The process will be terminated.");
0 V, g! N3 l6 A$ s6 m System.exit(1); x+ o. D$ u' s3 j* L G( A
return null;. G4 {' J0 j4 |1 Z: L4 k; {& `
}; w3 F3 a: ~4 ~5 ?
return sel;$ m$ v% b2 y5 Y) B# A5 i. W
} r: f) \8 j2 k. J0 q9 ?% \9 }
} |