import swarm.Selector;
* `2 |* e P3 E/ j; P
7 O- r$ E. Z: q; Spublic class SwarmUtils {! t9 U2 \6 d! Z5 |
public static Selector getSelector(String name, String method) {
6 ]/ M* [2 _1 v$ B i Selector sel;
( x' j' W5 e( \( l/ S9 n try {9 W1 U+ k# b- ~* j( _7 b
sel = new Selector(Class.forName(name), method, false);9 J! k: i ^' `/ P1 J5 {
} catch (Exception e) {
6 \$ M# X: f6 D2 {. s System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
3 z. A# v/ f6 x System.err.println(name + "." + method + " returns " + e.getMessage());/ y* x Y* e# v! A- F# ?
System.err.println("The process will be terminated.");
4 W# S5 \6 _' s8 S3 ^ System.exit(1);
, Q: _+ v& Q4 K/ ]' B. }3 j: y return null;* d1 z0 W% Y: _9 u
}- u% f- F* U+ q1 b8 g# N
return sel;
. s$ ^+ L+ `" E0 q4 N }
* i1 V @' V, u w3 y6 N7 u9 C* ]$ c5 G& D2 u
public static Selector getSelector(Object obj, String method) {. t- G# m! }8 ?3 h- G0 F2 N2 R
Selector sel;1 o9 i" c8 {; F7 [& Y6 R" K% x
try {; p( d6 x3 t- u. ^( x% B9 T& p, T
sel = new Selector(obj.getClass(), method, false);- N! K$ b P" P7 X
} catch (Exception e) {
# q; `; ^$ _: B5 g, w7 ] System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "4 Y h8 U `+ e# F7 l6 g; N0 @
+ (obj.getClass()).getName() + ".");
/ \2 f; e: Q( ]: Q) z, h4 J3 Y/ V System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());! u3 Z- x. T2 |$ k+ l' o. F
System.err.println("The process will be terminated.");
* T; }4 n8 i8 T- s* E, C System.exit(1);
1 \( O' q/ H7 s! ?: i return null;
- v4 `3 H5 R r# c9 s c }
- m% l/ O4 y. J+ P7 O1 C6 W return sel;
; A3 o5 e( f0 Z6 Y0 i4 U }$ e( ?1 B$ i5 ?. K
} |