import swarm.Selector;
4 W( `' x, f2 A+ D% f# ^* X$ z9 l- e* `$ w7 B
public class SwarmUtils {, g9 S- X6 }' W$ Y4 w, e
public static Selector getSelector(String name, String method) {. b7 r1 Q' N2 l/ F
Selector sel;5 c v, u( K0 |/ B
try {
0 Y% o7 v* D. }* X sel = new Selector(Class.forName(name), method, false);
0 y- `% ~: @) v9 H: Y% V/ ~8 p' L } catch (Exception e) {
/ d; A5 M/ a& w1 s, h" d* N2 x System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
* F" F% w0 j" `1 C6 S System.err.println(name + "." + method + " returns " + e.getMessage());
% {5 C: e" a8 |* G& {' U System.err.println("The process will be terminated.");
4 f$ l4 ^! p. i2 i* M$ {4 d. r0 w System.exit(1);1 g4 a1 I& d& q5 S9 C. H( p% M
return null;2 x- U1 _ H( Z% S; Y
}: b2 o/ L& Y9 c
return sel;
7 f% |" {' n( J P, C3 T }
% z/ h- _) ]. ^4 g1 p6 x- {; H4 v8 T* X
public static Selector getSelector(Object obj, String method) {
0 x% g4 X0 i) g3 T5 p9 K( ^ Selector sel;
2 K. k. j" N, M9 N2 \4 C: _% A try {
0 W9 g( ~0 i$ J sel = new Selector(obj.getClass(), method, false);
/ A3 p+ c: d0 {" k/ J J } catch (Exception e) {" a5 n; \2 a1 M
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "$ A V$ o: U Z0 e! b
+ (obj.getClass()).getName() + ".");
! R8 L, {8 q$ X. E7 u3 E System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());1 r, P$ |! v- \) r8 l
System.err.println("The process will be terminated.");. |) d+ r R7 N* d! b
System.exit(1);
" x& s) b) I; m: X0 {. l return null;( A( a/ E$ }) M* D) _
}
\4 k' h+ }( h( {+ F; r return sel;* u1 h1 M; l" e# T5 p% ?+ E! w
}9 z; S8 l7 }' S7 z4 E
} |