import swarm.Selector;, E6 U- g+ Y2 E$ ^' h1 V
( a. M2 u1 B! R6 U; U
public class SwarmUtils {
6 O* m& j- \" i3 R8 u& r$ O public static Selector getSelector(String name, String method) {% U' B4 |1 Y3 x, y. w6 @. s& s
Selector sel;
, n% B/ z0 v, x+ l( f try {
, J& \ M8 [. N. o% U' @ sel = new Selector(Class.forName(name), method, false);
* `& t. E( C7 q8 `3 H7 ]& W, j6 r } catch (Exception e) {6 i' k! w7 t) ?7 A1 l1 s$ E
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");9 |/ }! T/ M. v4 T7 S+ Z- t5 i
System.err.println(name + "." + method + " returns " + e.getMessage());3 Y7 F5 ]1 ^" A2 Z& F
System.err.println("The process will be terminated.");/ E! o1 O8 _+ Z
System.exit(1);, ?$ t$ A0 u0 ]
return null;# i. B. u/ ?: \% ^! g
}
+ g3 W% A, D- T: O return sel;
: h8 v7 @6 i4 v( Q& V2 n }/ j+ H+ ?/ @6 } G
0 [- i7 b0 P! t
public static Selector getSelector(Object obj, String method) { }; M5 }' @) [2 ~, }
Selector sel;" W. }* w5 ]4 y4 ^5 p: p; Y
try {
+ _, l+ g6 r' b4 N9 k" W9 A sel = new Selector(obj.getClass(), method, false);
* T2 N$ }4 U% f' J* F } catch (Exception e) {
7 r9 K6 t0 y) J) L# D9 r4 m% Z System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "0 U- ~6 c1 ^) V, A
+ (obj.getClass()).getName() + ".");2 R W# w0 `2 x* T q$ ^5 n
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
2 b. b' g) e3 u, p/ [ System.err.println("The process will be terminated.");1 P0 D) [- @0 V# A3 {
System.exit(1);0 s4 e- ? j+ ^- j
return null;
+ g7 s& J% f- S7 G8 `: L6 y- e; s% G: g }
' L, t w1 s; T* a return sel;
& `9 I" k6 E; d2 X; X }" `9 R. H4 K2 V9 n3 B
} |