import swarm.Selector;% K* C. x, d% i6 V- E0 r( o* Y8 t% F
* G+ {( p5 d4 |0 \! ~7 C
public class SwarmUtils {: S0 m3 F1 e8 W1 {9 d
public static Selector getSelector(String name, String method) {
$ Q) ?7 v$ [! P5 Z! J" F7 a Selector sel;
7 q5 c$ P5 P8 U& {, n9 ] try {
# l* E5 n+ @0 c* Y sel = new Selector(Class.forName(name), method, false);2 \: R# x/ D# A* I" |
} catch (Exception e) {! C6 A4 T4 u9 d) i$ A- Q# l
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");3 T8 r, Y. \; e
System.err.println(name + "." + method + " returns " + e.getMessage());
# A" Z2 W% G8 V System.err.println("The process will be terminated.");
0 M% B. B+ F: ~1 g System.exit(1);
^% d1 Z$ r+ ` return null;
- @: D' J* C+ t9 Y8 H }$ |) p% J; X1 k# }" D6 G
return sel;
# Q; S: k8 Y ?9 S" t }
. R6 i& l3 p3 B% N) z; h" M5 W- o* }6 l. h! z( h# k4 V
public static Selector getSelector(Object obj, String method) {; N( d! D, R2 v+ o3 f- X: k- Z
Selector sel;
9 P) f! A# w5 d* n; L3 X try {
2 ~0 C2 w" S& P sel = new Selector(obj.getClass(), method, false);
9 x1 d& Y. M3 Q+ O) R5 o2 ~. u, O } catch (Exception e) {
) Q4 E' H/ e: l/ `, N System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
: ] {4 e" S9 ?0 Z + (obj.getClass()).getName() + ".");' r V) B* f- A4 L* v) o+ r
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
$ U! }" ?9 B. Z9 J5 t/ z/ o7 J: y System.err.println("The process will be terminated.");# ^2 W( V9 y O
System.exit(1);
8 ]0 q7 C: s* w5 T: N9 n% |' v return null;+ d* a M/ R6 H8 c, a2 t
}- {4 [# `- t5 ~7 u* E
return sel;. F5 A% ?7 N# E T
}
! `% ?' x9 h6 {* r8 N1 ]/ K} |