import swarm.Selector;
! q' U4 ]0 u" c a! {4 s* \& A1 b/ f+ [
public class SwarmUtils {
1 f) B1 u: g0 a" Y J+ G public static Selector getSelector(String name, String method) {4 p2 b/ a6 @* ^
Selector sel;
' u3 n K3 C" ~$ j+ | try {- E3 {! |( V0 s/ d8 ?. k
sel = new Selector(Class.forName(name), method, false);
7 X5 n8 @9 v3 z! R7 R, z1 t } catch (Exception e) {# `3 Y' |6 p* q/ K$ r
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");" W5 M' q: {6 `& A$ B) ^/ F) V) _
System.err.println(name + "." + method + " returns " + e.getMessage());+ H: x0 @" E7 i, J2 Y& X$ f
System.err.println("The process will be terminated.");
" {- `5 `$ Q" X/ | System.exit(1);
7 `/ ^6 U- ]/ L return null;
Y* s+ p3 V$ c4 w7 {+ V$ B( v }( Z: }" I3 T, a; Z, ^
return sel;
( o+ z( {' }7 k9 Q7 s; `/ O }+ q2 X% I1 f0 W3 p6 O A0 L
. e: W+ O2 M. k/ i2 k public static Selector getSelector(Object obj, String method) {2 _! Y6 X h8 z7 N
Selector sel;3 }% i& }# D; Z: N3 M: T3 e* E# Y
try {
; m2 i F6 c. |; K. C/ @# o sel = new Selector(obj.getClass(), method, false);
$ x3 Z! d" A! t% b } catch (Exception e) {, d, X! x3 ^3 Q; g6 J$ n$ w! M
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
4 _2 {5 G$ Y) i3 Z, \: |1 m# ? + (obj.getClass()).getName() + ".");
; q4 r. e. |% X. q+ R+ G System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage()); H& r% W* z( T. \* Z/ y; }
System.err.println("The process will be terminated.");" j6 J1 y) g5 X9 N$ z) N" `) J
System.exit(1);
$ k* {* n* [$ c; |2 V: _ return null;3 l: u0 Q" j* H+ S
}' Y2 Y5 Z5 t8 v5 F; l6 q
return sel;1 z) c/ E& f1 c/ ?$ t$ ~' a+ {
}0 {' K8 Z# O) c) G
} |