import swarm.Selector;
1 L% r- W. K& z
- K* i8 B) l$ _8 L* s% E6 ^4 k$ Rpublic class SwarmUtils {/ F0 y, `: E' m, ]4 s3 x; f
public static Selector getSelector(String name, String method) {
6 d( K; M: q1 ^& G% H8 j Selector sel;
, Y4 _" U, h0 q, b( C/ _5 F" N! _ try {2 P' g3 B, M- Y$ l
sel = new Selector(Class.forName(name), method, false);! R q* y! \- X4 S
} catch (Exception e) {$ H v8 d( `1 n0 C0 U+ ]
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
! C4 [) I, x9 ]! f# g System.err.println(name + "." + method + " returns " + e.getMessage());
: G9 d! `. N. t) K; N) }) K System.err.println("The process will be terminated.");2 w" x( d/ m( \0 v2 K% o0 s
System.exit(1);
4 w0 F, D" {. A6 c return null;
; ?- y0 H6 K- t2 F( q1 m }6 r& O; X1 G) U( t# ]3 Y
return sel;1 Z; }+ x |& q4 O
}
- ^' V) ?7 e" v6 e
$ S9 R- g8 Z1 W; R public static Selector getSelector(Object obj, String method) {
, u' H& N7 b% t% N2 ]+ q Selector sel;% S1 D, {3 B" b3 s, V
try {
x4 n W8 [( j, v6 A" j sel = new Selector(obj.getClass(), method, false);
7 c5 Y1 ^( x- ^& O% E( M8 I9 F' ~4 N } catch (Exception e) {
$ s* i5 d* m) E2 p$ r* `2 ~ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ") p3 V7 r6 B' v6 C2 j4 ^5 W
+ (obj.getClass()).getName() + ".");2 I' r$ @, Z7 X5 \- _8 f
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
! U7 R% Y, a0 T System.err.println("The process will be terminated.");
* X+ B) i3 @2 x6 A* N9 u$ _, n4 ] System.exit(1);
9 O) I: r; E% W* w( n return null;1 H2 R, M) I# t/ \2 G8 E) v
}
3 X. t# p6 p8 [3 X: |* {0 h return sel;
( q$ V# i, i/ @, _8 s }8 ^5 W& \, s$ ]6 a
} |