import swarm.Selector;
, B1 T$ D, L! f4 _! B$ y
( w) S4 l: p& Kpublic class SwarmUtils {
5 K5 F: M$ Z5 s public static Selector getSelector(String name, String method) {
2 d; D( w2 E% T. ? Selector sel;
1 f' n o; L c try {- U% s ~* T% p; W3 v
sel = new Selector(Class.forName(name), method, false);
) W# B8 Q7 [. D* [6 f9 L/ Q* D* s } catch (Exception e) {
# ~' `4 w/ |/ L System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
`: O! g/ [5 D: L* o# T# } System.err.println(name + "." + method + " returns " + e.getMessage());
+ Z' b% n- {3 T, h O System.err.println("The process will be terminated.");
+ a# H6 S) t( H4 C# a# I, @ System.exit(1);* ~5 v/ z4 r/ H3 U% v
return null;
P- b3 o5 z0 N8 D( K }% ~# d% |2 R9 `) |! I4 x9 G$ v* Y
return sel;# P9 Y6 s4 [3 x: e; h
}
) W- |* q: q1 r- A3 }& C/ I5 E- q6 m6 Q0 P5 v7 }
public static Selector getSelector(Object obj, String method) {6 c: W% I3 l0 X6 x$ a& v
Selector sel;' z) F' |; b5 f
try {
4 s5 r+ p1 A7 l2 G2 k I2 f sel = new Selector(obj.getClass(), method, false);
) ^7 s: e6 m6 g9 j2 a, w } catch (Exception e) {
& G; I# ]1 \; _2 B: a4 z8 j System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
3 W$ D: D1 G! E3 ? + (obj.getClass()).getName() + ".");
& I/ t8 `$ K: Y' [( O: N1 Z9 Z System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());$ A* g% j' V# s& x
System.err.println("The process will be terminated.");
- W/ k$ [4 h% [! i* p0 x System.exit(1);( D+ T# P7 C6 Q
return null;* D. f# B$ W3 h5 V
}7 d; z) W# V4 S
return sel;
0 t) v7 A: G8 y+ r" a. ?0 g }
* x8 ]* L- L5 H6 V- d} |