import swarm.Selector;
. [ P! L! i t6 \- y/ W
l) R. x* M3 M+ v+ e" C2 q, x6 Vpublic class SwarmUtils {3 |5 V9 }7 d- w" k& d3 J0 k1 J8 w
public static Selector getSelector(String name, String method) {5 A6 p& [; `/ O- X4 `
Selector sel;
0 e0 a9 |; P2 b$ e6 p q: ` try {- y7 ^1 u) d# f) }% c) j( o
sel = new Selector(Class.forName(name), method, false);
7 x% r6 u, `) ?: @ } catch (Exception e) {: n7 I5 I _* b" ^0 q/ x
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");9 U! J, m/ L `- v5 z
System.err.println(name + "." + method + " returns " + e.getMessage());
7 [+ W! G, s* B2 V3 j System.err.println("The process will be terminated.");' n1 e7 v) E: `
System.exit(1);
& l j, [% j l0 w) T; r; k" [ return null;' k- P/ `2 n j' c y
}
( |6 T; f; A; D# |' e return sel;
, h3 k7 X) S$ i& d2 o* w8 p# Y }
- x, a# Y I/ z; D7 F/ F8 K- S9 q2 C1 @/ r
public static Selector getSelector(Object obj, String method) {/ L* k& R+ z- |8 C- q) U+ _
Selector sel;
4 Q5 I6 C E6 W' A try {
/ _" P+ M% \- _; D( E6 X' W sel = new Selector(obj.getClass(), method, false);5 ]# t0 E* J$ e# ]
} catch (Exception e) {
1 y: u, w& F/ D# d9 W5 e System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "/ b/ s! Q0 p& U6 }5 c1 `
+ (obj.getClass()).getName() + "."); m8 E# z; x. B8 u! L
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());8 F0 s! y/ R K! W9 }4 |2 k8 Q
System.err.println("The process will be terminated.");
0 K0 p' J3 V. @ System.exit(1);8 p+ S, N% w4 r* t
return null;! k" e3 ]6 A& t+ E9 X
}
+ v% e" Y n4 h& t- n3 W) c return sel;) v- C) J) O# Z5 P$ r+ i
}
& L9 Z$ @( e" m& [. M} |