import swarm.Selector;7 A$ ~) ?) |% b$ _6 D2 |* h. C
) k7 D( [, d8 `6 Ypublic class SwarmUtils {
* o% c6 {/ @, o3 P r0 R5 x5 D6 A- b* V public static Selector getSelector(String name, String method) {1 I. C6 }+ u' N! T. ^3 Z6 D
Selector sel;
+ L7 ~1 n! ^/ m# B+ B7 v try {4 R+ E6 o# u: G; G
sel = new Selector(Class.forName(name), method, false);2 L7 h3 c3 }: p
} catch (Exception e) {+ x7 V4 b1 Y7 E' `; I4 \2 m9 c) |
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");: l5 ]: G: W/ r% o
System.err.println(name + "." + method + " returns " + e.getMessage());
* S) c! B; _9 R& A, J; Q# I System.err.println("The process will be terminated.");# U* i' G+ ^( W# n4 l/ e( x0 k& C' Z, }
System.exit(1);7 G x5 R) ~0 }
return null;
: n" K; g% d1 B: _7 n6 T }
9 z- v+ Q% g- f, g return sel;7 ~, [2 L5 s4 r9 [) z
}5 O" a. m+ u9 u2 V5 q
& P$ _2 ~- A1 v( s; e0 v, H j public static Selector getSelector(Object obj, String method) {
$ B0 M$ v, v3 z; Z% P- G* H" h0 { Selector sel;; G% G+ f7 l( Q$ V% h, y
try {
* x2 [$ w7 {" q) T- k8 j) b sel = new Selector(obj.getClass(), method, false);
5 j- Y8 h7 O' S0 Q6 |# c } catch (Exception e) {
* Q, |; L" p, g0 _ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
2 u5 B0 i" L1 R) ~, G2 ] + (obj.getClass()).getName() + ".");: D, s! S6 {% l$ h* s/ T
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());; N( D+ g6 Q% H2 ^4 Z+ T& g" h
System.err.println("The process will be terminated.");
5 E# o0 q) }/ v- i; ]1 T System.exit(1);
8 f2 D& ^4 M9 n" Q. M/ Z" f return null;
4 _6 j) f# t$ R9 J }
/ C' J6 f0 e$ i5 P( x return sel;
; w- Y; J9 h0 q: }# ]$ K }# f) [+ x. o, i2 L9 U
} |