import swarm.Selector; d3 E9 N: F' B% t2 S/ s
8 v, ^4 O# w* X3 qpublic class SwarmUtils {
$ u& U; C r, C5 k# ]* \/ s1 o public static Selector getSelector(String name, String method) {7 y2 t/ A" ?4 b' Y! m5 ?" R
Selector sel;4 T% ~, q9 f" \7 k% ?0 v* \: {" z
try {- ^% ?+ D/ f- `1 C6 _. M
sel = new Selector(Class.forName(name), method, false);/ b7 b$ U" I" V" F) U) l7 e f
} catch (Exception e) {' G9 H" I- _% c
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");( u6 U4 s5 k+ m
System.err.println(name + "." + method + " returns " + e.getMessage());
& L0 a4 q2 Q0 t) R, y% V System.err.println("The process will be terminated.");, J) O6 P% o8 f3 g
System.exit(1);; i$ w, k! h+ X, T+ d# I
return null; C0 L- I+ s/ V: n) Y
}
; F; j' W; N/ A, d4 c n% J* P U& `1 V return sel;
* A' S) _. E A7 y$ T7 h6 P" L }
' E& ?- ?- A8 F' h" x0 H* N5 t
# W+ }5 H; m7 Z2 y6 K, W' b public static Selector getSelector(Object obj, String method) {
1 s& t; @6 c1 b( a) T3 a1 O Selector sel;( g2 a9 V6 ?* d/ j- q8 t7 H
try {
9 O5 r5 I& W" I, G4 y) T sel = new Selector(obj.getClass(), method, false);
7 K& \; k" N) i h' \* p } catch (Exception e) {
2 G9 M; G8 U- f# r$ ? System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "; k3 _4 _& L6 N) X( [' I
+ (obj.getClass()).getName() + ".");
: Y" ^' {# G6 s System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());# H! c& ~' I% @: D
System.err.println("The process will be terminated.");
& S B! o9 T& [ System.exit(1);
% m9 E: J% s; o4 h return null;0 R6 S) |- L$ K- ~) o* {
}
( \+ w4 y& U7 ^5 I( L return sel;7 u. ]: m5 i) u% `9 n) Y r- ?
}
8 D; h9 F1 @7 w, F6 _} |