import swarm.Selector;
/ M& U% w! ~& l) j6 c
# ]- k' V8 u8 x# y% o5 W/ w$ Q: Xpublic class SwarmUtils {
/ r# s5 d9 {' m; {6 y public static Selector getSelector(String name, String method) {& n+ e7 _& B. h! M$ n
Selector sel;
/ v$ m2 W) ~" C w- s try {
2 o* x" h$ S4 ~. i6 I sel = new Selector(Class.forName(name), method, false);
: i" X& j# j J8 a } catch (Exception e) {. Z! v2 N# V( o) u
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
* y+ H) J$ ^# } System.err.println(name + "." + method + " returns " + e.getMessage());
+ W' ]- |! t5 r% k4 U System.err.println("The process will be terminated.");( n g) r/ A5 s ?6 g8 `* ]3 I" r
System.exit(1);! { O) o& a! i' N
return null;, S* j8 D; v9 m C4 d
} w( A8 C& `$ N. M, p
return sel;! z$ B. ~5 @7 c7 k o" C8 r
}# Q# B1 { g" M, ^7 B* i( o/ b' C
R6 O, Q: E: V8 E3 I public static Selector getSelector(Object obj, String method) {/ X; j* \ A4 e; U& ^, o
Selector sel;6 @ T a: D1 s7 M; _
try {% R6 v3 t- ^7 H0 U# I
sel = new Selector(obj.getClass(), method, false);
, t' [: O/ P" U0 ~ } catch (Exception e) {+ E+ G- H- N6 T
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "+ J; {! z5 Z) v, k
+ (obj.getClass()).getName() + ".");
1 ?; `9 t _! c) _5 b System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());: b d+ ]9 v) m6 M6 P( M5 q
System.err.println("The process will be terminated.");- d8 L% a# s% p
System.exit(1);! _& v5 B, g/ B. v+ Z4 S* t3 `( H. B
return null;
+ {; _ Y4 j, `" k( V3 s }8 p6 D. D) q9 D- Q
return sel;- Y2 k* t2 @' n7 H* k9 {
}
/ b0 m' t2 r" h( K} |