import swarm.Selector;2 t% j1 }4 s) l
+ p7 w- N8 W$ B$ D5 @' Gpublic class SwarmUtils {4 A8 S( G$ D2 |& J2 O) F
public static Selector getSelector(String name, String method) {
" ?, z' g7 H! I9 A# l* W Selector sel;
/ J, `3 \. r& Y2 q( ?4 b try {6 o" n$ \, ~3 ?, s3 E* B
sel = new Selector(Class.forName(name), method, false);
5 m+ _" y5 c, O! U! U7 h% W9 K } catch (Exception e) {
8 Z5 ~2 m1 Q3 z) S" {3 F System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
4 z! X8 R1 N x System.err.println(name + "." + method + " returns " + e.getMessage());
/ N' Z" S$ u0 k; _6 b System.err.println("The process will be terminated.");
$ M+ G# Y O8 y2 B, k System.exit(1);
. A% `" g- i& _* E& |7 e8 x return null;
3 s) S, K- s$ g$ e" r( P }+ i% | m4 T% r: V. ]! ?# R# j+ L
return sel;
5 r0 _; s: k. F: v }' L) X/ R4 c, U( W1 S0 y
' Y# g3 [4 I- C) `
public static Selector getSelector(Object obj, String method) {8 A/ r- m: e6 e! i
Selector sel;
1 ^/ u( k4 h1 v) l% ~ try {
' d4 y1 y0 ~& w0 g sel = new Selector(obj.getClass(), method, false);
7 q$ F3 [/ e: [! g, f } catch (Exception e) {% d: `8 w5 M* f/ K
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
: R# T4 h1 n& h; D7 H + (obj.getClass()).getName() + ".");
" o4 n) o0 \$ Z* d8 H+ m- `+ S System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());) a& K" V0 O! \
System.err.println("The process will be terminated.");
6 f. h9 k9 c! c3 M# ~ System.exit(1);3 m" A1 B' ?9 ^# E
return null;3 k: }9 o+ s V, Y. o+ n$ w; J5 c
}
) `/ c4 q$ q% c' `( {" G2 H return sel;% ~4 L6 s. ^2 o' h
}9 a* [" ^9 U& r' ?, n- \' Q/ f: F+ p
} |