import swarm.Selector;* a5 D# G, a S! b0 P9 s
5 f9 a, s- c4 p9 U9 \8 v9 i* {
public class SwarmUtils {1 p/ h3 @/ l0 S+ i9 j
public static Selector getSelector(String name, String method) {
% `2 Z$ P2 [; @, }/ k# ` Selector sel;: {) ]" @; ]/ m+ Y
try {
$ `* m9 B9 e3 t/ b" P9 C sel = new Selector(Class.forName(name), method, false);
* I. n$ b6 p& Q9 d: t } catch (Exception e) {
. K) f' Y9 P+ K6 s System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
: \$ U; E9 o: [ System.err.println(name + "." + method + " returns " + e.getMessage());3 T$ q+ q) N8 r& c9 f" l
System.err.println("The process will be terminated.");
& Y7 m7 ]) r3 U System.exit(1);
5 A- f. p: j7 y: J6 }0 l* W return null;
. R- u/ \% c: e* |( ~" ^+ h9 A0 N }
* u! ]; @) H* P& t return sel;- n6 |, o+ w8 v+ c* h
}
! ?8 W3 V& v: w; d7 e/ q3 _) @5 ~5 i- F! Z
public static Selector getSelector(Object obj, String method) {7 i' B+ ]" z6 v; y# `; d7 z
Selector sel;
& J3 m0 l9 h" E Q try {( p5 t k) V) a; q! g0 m5 e
sel = new Selector(obj.getClass(), method, false);
9 c2 L& g1 [" S" c$ B { } catch (Exception e) {
# c; \* P, q% J' [/ S* P# | System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ", ]0 L# K7 [' U) \" R6 f2 J+ ?
+ (obj.getClass()).getName() + ".");; i* b. M% u' d
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage()); S" c+ a* z6 P2 E* ]6 w
System.err.println("The process will be terminated.");
( @+ {; W2 S- r' {* s System.exit(1);
1 c, Y- y& m; D* T7 b4 V0 c return null;
~ l7 |6 [7 q' O" M }3 \4 C% Q/ }. a7 ^4 \8 j. F
return sel;% {2 |) d6 N3 u# o3 Y7 X' w. l
}) R) C) l. z. b" w2 v) a
} |