import swarm.Selector;
4 V3 i& c+ X/ H: P8 N& F# `9 v7 | V0 g4 ]
public class SwarmUtils {
$ ~7 w( y" |+ x5 w) [. _5 K) @8 J public static Selector getSelector(String name, String method) {( y+ m5 f7 X* I. U3 ?
Selector sel;( L! u$ |9 d3 V$ l* c8 T0 H2 }) X; d
try {; n' { }# Z, G' u t& \
sel = new Selector(Class.forName(name), method, false);( t+ n w4 r/ _6 ~( v; _
} catch (Exception e) {6 A1 ]6 R1 T9 \- W0 G0 |/ G0 N
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + "."); [& c. \! F8 [9 M& y$ [
System.err.println(name + "." + method + " returns " + e.getMessage());
! V6 X6 o9 b6 r d1 _/ r$ K- o6 G1 P System.err.println("The process will be terminated.");
* A0 |' n* U! f8 Y j System.exit(1);
. G; b6 r8 k6 E0 c' y/ D return null;; }# x1 G9 ?! m) M0 _/ M0 z5 _" J
}
1 ^; i7 C5 f3 h* u/ O return sel;
# K' b0 t6 Y! U" r }' [% C3 z: q/ W) W0 Y0 m
6 }- N9 o* ^, _$ S2 t' V# @6 { public static Selector getSelector(Object obj, String method) {% x2 Z4 x5 O4 q' U+ `* E
Selector sel;
C5 C8 D+ E+ ]+ D$ m7 M try {
+ M2 {% \/ N! F4 G& Z- \2 v' y- F sel = new Selector(obj.getClass(), method, false);
/ I8 H+ O. ?9 b7 g9 y3 i9 T( T( W } catch (Exception e) {+ A6 D5 a3 ]& T, e9 |
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
7 r' k8 s0 s0 c+ F& {; b% v% s2 Z + (obj.getClass()).getName() + ".");! Y* l" T' y N0 i
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());& \0 h$ k, O9 D) m O8 s4 _1 w8 {
System.err.println("The process will be terminated.");2 f/ V2 o- s8 ~2 {7 y. N
System.exit(1);
. v8 N7 K/ Y$ q% D0 j, H return null;
! L* E4 c c4 V/ F }) a- w; i, E& E( l" Z
return sel;
- W; B3 O5 h7 A* x+ E. F6 G* S }
& k8 l7 _: j$ t/ D, T% H7 k4 Q+ A} |