import swarm.Selector;% I& ?6 v6 S4 s& F0 H. r; P/ u( |
9 z$ u5 d+ t3 ?3 \& _# \; v
public class SwarmUtils {( b+ y* w6 Y0 Y$ {9 d
public static Selector getSelector(String name, String method) {7 }) b9 v" m; y# M0 h1 z8 |( i3 O G; y
Selector sel;6 c! Y0 n F8 G+ W0 O2 g6 X& M! ^
try {3 ]/ h. e+ b( b
sel = new Selector(Class.forName(name), method, false);9 Z) G+ s% k: Z7 ]) b/ X' {
} catch (Exception e) {* R" R* j& g- P
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");2 ^" _! _* V8 K4 q' w
System.err.println(name + "." + method + " returns " + e.getMessage());( ?6 B. h( H3 @3 I
System.err.println("The process will be terminated.");$ t& {, ~& y, i8 Q
System.exit(1);7 _- n: z& b0 p
return null;
: N0 S; M3 M) t( L# D Z }
8 X! q; u a0 B& z. q return sel;! n4 \! V: B. @" d+ [$ ?
}0 E5 w. c& f4 v4 v
3 @4 ^: S# x, O6 F* o
public static Selector getSelector(Object obj, String method) {" C6 M+ R( k) r; h
Selector sel;& D2 n; e% V; X
try {
0 R! B& ]6 I, W sel = new Selector(obj.getClass(), method, false);
2 _8 t9 f, d/ H# ~ } catch (Exception e) {
* j b: ?) H8 t4 P8 P System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "+ u0 _: i: Y! C" Y& u
+ (obj.getClass()).getName() + ".");# s9 C8 S# @+ [5 z
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());8 s; D1 T% ]5 H q# z7 S
System.err.println("The process will be terminated.");3 P1 X* k1 U0 Y' p" k3 E
System.exit(1);& N. a& v* O( j/ j& |; e
return null;
1 ]7 P' d! ^) J# H }
8 A/ h0 U5 O4 I+ X5 U return sel;
9 |. A' l( I2 \5 X- I' J5 ` }/ L6 K: n& [4 K, o1 u4 a# C
} |