import swarm.Selector;' W' h) w- i% }% O L! j" ^+ `: p
: }: H; `5 b. W9 Q8 f
public class SwarmUtils {
0 z( K# v; F2 I0 ]* x public static Selector getSelector(String name, String method) {+ \$ H* Q8 p1 T& j! S3 i' p$ j
Selector sel;
- ]8 w9 W9 G6 k try {4 C1 H' D, M* m9 O X. I
sel = new Selector(Class.forName(name), method, false);! \* a, S$ {# z/ Y4 h9 ?
} catch (Exception e) {) j& P0 z, [( E- a4 g: E5 I, f- f
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
6 _$ L6 B9 V8 w$ M System.err.println(name + "." + method + " returns " + e.getMessage());* s# x" u- V# }7 V2 o+ r% _
System.err.println("The process will be terminated.");
* }* ~6 a; @# Y+ G x% @7 X2 f System.exit(1);; ]; z* v1 T3 }2 k3 i/ @
return null;% v* b( z) u# X- @; `
}
8 q( H) c- N& w) l% i3 }/ c9 F return sel;
* {8 `. k- y' a5 {( k }
3 L* |! [; p0 C2 d* o( {" N0 d0 t4 M7 Y+ q' ?; b2 i+ k
public static Selector getSelector(Object obj, String method) {
# U! O p' u. s8 {" N/ O+ W; Z Selector sel;% s( \! L8 @; D4 ^( q8 w2 j
try {
* D4 m% S, j9 D A4 Q+ W3 U1 l sel = new Selector(obj.getClass(), method, false);6 k! f# A) G# L' L
} catch (Exception e) {! C3 w6 f6 x: T/ J
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "9 Y; X0 H- r( L* G
+ (obj.getClass()).getName() + ".");1 I6 M% M0 U7 Q) {6 e/ @) _. d
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
0 ?. h5 P3 _4 ~) O; d C9 r4 b System.err.println("The process will be terminated.");: {3 S% r, i3 e* B! v, @: I+ C1 A" R
System.exit(1);
1 L6 u1 Y, F( p$ y& V return null;
: Q; [1 a* e4 N" q0 J" ? }
1 G* c8 L' T b" n return sel;% Q, C' a! r3 t6 A+ G- c: o
}- I- z' g( d9 E t6 ~
} |