import swarm.Selector;; o- S9 G! }) h9 \& P" r
& B* j: w& h. {: m6 N9 x/ I7 V/ ]" Lpublic class SwarmUtils {# `& M, m |$ g# j
public static Selector getSelector(String name, String method) {
# Y8 C4 P$ J$ e8 P Selector sel;' d, w: R e/ z; V2 b
try {
" ]: F1 m6 o! B sel = new Selector(Class.forName(name), method, false);/ a! n4 L# a: ?6 ?
} catch (Exception e) {
* O1 }- D9 g8 P0 Q- V/ e& k2 u" ` System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");7 U5 g! m- U: J' c) B; f, e
System.err.println(name + "." + method + " returns " + e.getMessage());
7 g# q* U* ^1 n6 @! r# u System.err.println("The process will be terminated.");$ m1 u$ {8 B4 n1 E
System.exit(1);
; p% N1 g7 L3 R9 R2 Z% | return null;
+ a4 I: m+ v* w, X1 t }* P6 j5 ?* e+ G2 e( C' p
return sel;
" o+ @$ d5 Z9 @ T* T+ P }7 N- J9 E4 j$ ^" Y/ J/ ^
" c: u9 c& E/ k' }, F1 e5 `( P public static Selector getSelector(Object obj, String method) {# W) X2 s4 Q. a5 C( v* h
Selector sel;
9 P* R; {1 |' P try {
7 x# I4 m4 C5 ], e; \; B" R sel = new Selector(obj.getClass(), method, false);
9 C! ?& B/ ~. V0 ^& i } catch (Exception e) {( U( d4 P+ r4 |& X
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ", g5 m% C. O* x$ Z5 l7 [( V
+ (obj.getClass()).getName() + ".");% R2 s; y3 x8 J% y
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());+ ?/ C% t K0 v1 k# h0 M* p9 U
System.err.println("The process will be terminated.");
; D2 J8 {% }% T5 `* Q/ V System.exit(1);) r: p$ c" G. D8 [$ z
return null;
" T$ n: I) [$ h% ?4 t/ j }) V- X. b' F: C6 z* m, q
return sel;( Z+ g" ?/ @1 u" X- O6 K
}8 [+ N! A* r5 Z# h
} |