import swarm.Selector;
% n" j8 ^0 }& N2 Y$ M# Y6 }
. i( h( p+ t9 m- i, u) Y8 @1 |! d2 f5 xpublic class SwarmUtils {- M0 k1 _/ H" }. _# L0 i
public static Selector getSelector(String name, String method) {0 k- Y0 f" {' J/ M- ?3 P) @
Selector sel;# ]) E) t* ?4 u/ Z: B; q
try {
. C' E( F4 y! [7 M4 o9 M- H sel = new Selector(Class.forName(name), method, false);
; U% u% q# S2 W9 a. Z. S& V: F } catch (Exception e) {! A6 \( n9 S5 _/ G
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
. x- D/ a O }* u1 p System.err.println(name + "." + method + " returns " + e.getMessage());2 N( l: L8 d- W7 v' D& X' d
System.err.println("The process will be terminated.");4 V6 ]( g( g/ j5 l5 y3 p+ d* e3 E" E
System.exit(1);: g% q4 G1 Q( x$ H
return null;2 x: P4 S2 f( j! C2 {# E
}" o" d9 X! S3 e! Q
return sel;8 @+ q# t. G6 L/ o5 e
}, B7 l/ a7 X1 v6 _3 R$ \7 K
" b- ]- a7 Y; ^7 Q( [ public static Selector getSelector(Object obj, String method) {6 t' b. M- B* R2 g) ]
Selector sel;. h- e* ?: L( m2 W3 E3 X) v
try {7 `0 H" S) n+ ^1 o
sel = new Selector(obj.getClass(), method, false);; h8 T) p# l8 C' a% X5 e
} catch (Exception e) {; I$ _8 B5 @! d, m( g; ~
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "8 r" l! U" f* j! }7 ]6 ^. s
+ (obj.getClass()).getName() + ".");
' R& T; ^2 F( v( K/ d6 O% F9 k" n# k System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());7 `# Z, H3 @/ k/ E; s
System.err.println("The process will be terminated.");
' v9 j. o- X4 k' A8 f0 p% j System.exit(1);
( ]9 m3 m7 J' A2 ~, h- I return null;1 {2 `& C: o4 R( I2 m
}
3 J9 e0 y0 T2 ~& Q" z4 e return sel;% B" \4 @8 r( J" ^, ^, A3 }# K
}. U7 p% G L$ _# \
} |