import swarm.Selector;
- y6 o1 Z% F" `- C( t! B% O
2 Y+ @5 j& K: X6 O- ~6 Kpublic class SwarmUtils {
& y0 [* v+ U! _# I! M6 k public static Selector getSelector(String name, String method) {, v/ Y) b# }' |. s9 z% L8 g8 s
Selector sel;
, y- V+ d b$ J" [ try {
- y* v4 L( L# E4 S+ ~ sel = new Selector(Class.forName(name), method, false);
# Q8 @& @% ~ \+ @- h1 ~ `) n } catch (Exception e) {
- B# o0 Q/ y) {( I! I System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");; G" _/ y8 ]* ?' i# c$ q
System.err.println(name + "." + method + " returns " + e.getMessage());
9 R8 U. |5 p+ q System.err.println("The process will be terminated.");; b$ M# O4 V- w- y& _
System.exit(1);" L" W J+ r* d0 G6 k% F# o, T z
return null;1 J6 L7 M& C' O* b
}
, W; e! c9 ^. r. Y2 Z3 S9 M- \6 A return sel;
( @% T& S, E# T& t ?/ Q( t }
. D3 `, r2 X# ?' {3 ~: I+ e7 w$ F' B8 B; p; K" Z
public static Selector getSelector(Object obj, String method) {5 @. [: A$ n0 n1 O, `1 k
Selector sel;$ _, p# P5 \" r j/ o
try {4 U' o& c0 S) W6 ?9 g5 s5 J2 X
sel = new Selector(obj.getClass(), method, false);
3 \8 v7 e* x' x. w+ C } catch (Exception e) {
. L+ v/ i0 i$ Z System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "/ D Y/ F+ x$ o& ^3 {
+ (obj.getClass()).getName() + ".");
9 e& F( ~7 h2 x G* K: `( I System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
5 \. b+ \4 P: R" r System.err.println("The process will be terminated.");
$ A% Q4 [. h, X- R4 Y2 p System.exit(1);
* j' j( t* O9 ]+ F return null;! d6 }9 s. X) C) T- B2 a
}
4 m) ?0 ^9 L& [ return sel;
) J6 I E- B( d7 k7 s& e }2 w- p4 ~2 _" P' p" i6 o, b
} |