import swarm.Selector;
8 ~2 _4 o) E. t/ W# `8 d/ x: O1 w. k
public class SwarmUtils {/ H; u" i4 S- _% P, J4 r. s! p
public static Selector getSelector(String name, String method) {
( z" b3 i; X' t/ J Selector sel;
' ?# h2 C6 r# A* P& }6 ~3 q& ^" S5 s try {+ h- {4 W! u) s+ R O! ]1 m
sel = new Selector(Class.forName(name), method, false);3 i, O* \0 F8 {1 a5 f4 K7 c' F
} catch (Exception e) {, @7 G) x7 T+ `2 n5 v6 v* N* u
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
& Z# U9 a/ w$ P& O System.err.println(name + "." + method + " returns " + e.getMessage());
& K! D8 [' s. ^7 ^9 C% S7 E4 o9 U System.err.println("The process will be terminated.");
/ R5 t* K* A1 [% S, e% [8 g System.exit(1);
) |4 j2 g) Z- ~/ g4 w- U: u: Z return null;
/ }. [1 o* I3 v( {; Z3 D }3 p2 `. L3 D) R
return sel;
3 G; r: b8 s% W; T. C9 ` }4 {3 M! L0 J+ {) Q
' k* R- `) C& e4 P& E, A
public static Selector getSelector(Object obj, String method) {
4 V1 a. S) W9 H* ?- G Selector sel;
- N6 J4 M* o1 G5 O try {/ y. Q: u4 ?6 M- P
sel = new Selector(obj.getClass(), method, false);. k- M5 Z9 `1 x4 \6 l9 k: L
} catch (Exception e) {; @* _7 x5 ]4 r0 T* K+ v
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ": U* c+ \2 ]/ j/ w
+ (obj.getClass()).getName() + ".");% i" ^1 k- P0 F" d" x
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
: ~! ]% l- P/ i6 K) H System.err.println("The process will be terminated.");# t) V2 e9 H" N4 W7 t1 p
System.exit(1);
7 ]1 h S. W) c) W. P7 `# R! ~ return null;
. v% w$ c* a) i, `3 K5 ` } b I) ^/ Z9 L" ^
return sel;% X, [9 N" r) ~
}7 l1 s; ^. q" s6 k, J4 Z
} |