import swarm.Selector;
: i! h6 J: B6 J/ n
q; \" n! N V$ Opublic class SwarmUtils {; i o+ t7 j$ c$ l/ D$ [
public static Selector getSelector(String name, String method) {
5 e% v! T% w, V8 \( a Selector sel;" k0 G6 n: x: }1 x: e# x! `
try {
* U' X2 l2 [- X/ F# X& w sel = new Selector(Class.forName(name), method, false);
( \8 o, A4 f( e: g, i7 w% q, F0 k } catch (Exception e) {
7 A% e) L8 X( Y. Q3 W, Y System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");, c1 X1 z6 x# L/ D; i
System.err.println(name + "." + method + " returns " + e.getMessage());
& E: Y" |# E2 Y* s9 _- ], t System.err.println("The process will be terminated.");* T; g) c( M) z8 b. ]/ B) l
System.exit(1);* h/ f& t9 M$ b6 B. P
return null;
) l9 i3 n7 P- k2 ?2 E }+ B7 J2 G( D! A
return sel;$ t- J6 s- L4 {( K* B. X, o
}4 J, W5 V6 |* z" K
% C& p; P P9 S6 S5 p; [ public static Selector getSelector(Object obj, String method) {$ _9 q: \; P t- t
Selector sel;
) m( ]& p! ^! l# R3 Y/ b. l try {* R+ t* W, z- I1 i1 L _ {5 x+ S# z
sel = new Selector(obj.getClass(), method, false);" E+ l- K2 @: Z$ w' |
} catch (Exception e) {3 C& F% f. s0 ] S3 l
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
3 d0 T' j3 w5 X( g; P2 f v + (obj.getClass()).getName() + ".");2 ^" H9 ?1 n5 j. f$ ~
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());* Q" C2 U' h& V; S& L. ~& ?1 \
System.err.println("The process will be terminated.");
d& t; a% m/ ? n; a2 S System.exit(1);
2 p! c+ R- f6 s5 m) ~* y+ q return null;
' ~1 v: h! O4 w+ V \1 K: T, u S }" ?, u2 s# G1 N4 j
return sel;
1 ~2 Y& ?* _6 i1 y$ b' Z' n }0 l3 G; \ G3 K: X8 _
} |