import swarm.Selector;6 i; z' L& m" Q: v
0 [( T# r: A% m, S
public class SwarmUtils {
! r8 k5 x$ f) q$ T7 h public static Selector getSelector(String name, String method) {
) A a3 n2 E0 ~2 \3 S- m* e/ n Selector sel;
* `+ Q3 v) u: l! e/ ^: V try {. Y. [. }& t$ Y: J- ]
sel = new Selector(Class.forName(name), method, false);/ q5 U, m% j0 b( B% e
} catch (Exception e) {
* b9 v- B% Q: t. @7 ~ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
0 p$ ~, U: U5 e; B f# R) b System.err.println(name + "." + method + " returns " + e.getMessage());& m2 S7 N- [; L
System.err.println("The process will be terminated.");1 Q( M* ~; S5 m) l
System.exit(1);
8 {7 _2 k: a6 P return null;' h( [# ?2 Z. i+ ~! P5 h" T) S
} Y9 G# D+ o! n! R. ] e% x2 G
return sel;
6 h$ B% e& L5 y- Z }# g% g& l4 T; t% c5 Y' ^% q
6 M) l$ J2 o6 f1 h8 s T public static Selector getSelector(Object obj, String method) {
# ^; S, Y4 `/ O- Q2 A Selector sel;
/ g: D* v/ z: c( v$ r; o try {
& f# ]( _, Q" ] c: k! r sel = new Selector(obj.getClass(), method, false);
# K# n$ q1 M8 b$ d; b, K } catch (Exception e) {0 ?4 w% c+ L k1 Z
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "; n) y5 O9 Q/ b2 Q2 x, \
+ (obj.getClass()).getName() + ".");# Z8 W( z r% P/ l
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());5 k7 l$ k: a- h; Y3 C2 R
System.err.println("The process will be terminated.");
' F9 I* S0 e! x5 j$ p$ h System.exit(1);
8 o/ ~; q5 u7 B5 v return null;
0 t4 w! G8 x% Z# L+ R" c- b0 N z1 q }; ~2 A& o0 E; h! [8 D% y
return sel;% n5 k, p; F, l+ l4 |
}
2 J3 a8 F: p3 r9 M& M% a6 \6 F5 ^7 v} |