import swarm.Selector;( Q9 c1 J% U1 F6 _: P' o; b P
1 y9 f- q7 R* F) t' u5 xpublic class SwarmUtils {
0 w% `" X) z0 I/ b' N! l+ G public static Selector getSelector(String name, String method) {
. i9 n0 w6 m) i* j Selector sel;4 E4 q' ~7 S' Z) ?, @
try {
4 q* O9 P7 q, S3 `2 @ sel = new Selector(Class.forName(name), method, false);' B. J0 E2 X( E: U
} catch (Exception e) {9 n4 c* b" v* q* z
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
5 W: W/ f x, F System.err.println(name + "." + method + " returns " + e.getMessage());3 q2 X' k% E1 m" B- ]* [& S
System.err.println("The process will be terminated.");! h/ b5 Y! G# a' f7 Q( E7 g, q/ M
System.exit(1);* S& {6 \- {6 N9 o9 o
return null;! @1 m' D' X; a0 ?6 k) ]% T/ n
}
$ d. u+ t N4 U! K1 C; Z return sel;! v+ F k6 z& B4 R( Z
}
: c4 A+ j9 G+ t. n5 f
- t+ E6 Y- Z% K: {# k" ~ public static Selector getSelector(Object obj, String method) {
: Q( \# L3 J7 f0 w- K# [ Selector sel;- C# S& D# X# _
try {
1 `5 X' L4 d" Q sel = new Selector(obj.getClass(), method, false);
0 f0 z# W |- D/ g4 H9 j } catch (Exception e) {" W; J& E3 G; D8 r; F4 y+ c. u; O
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "3 Y+ q4 M" n) j0 C0 ]0 @- _2 t
+ (obj.getClass()).getName() + ".");
/ H+ a' |. C2 j& a V& p4 \6 | System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());4 `5 F1 {, F$ ^- Q
System.err.println("The process will be terminated.");8 q3 R, {' X6 \8 g5 j
System.exit(1);
% B( c6 L5 ]+ x& r* i' [/ w return null;; E, b* o7 h- O7 Z8 U
}
- [% d( J1 l& i2 ]( v6 P3 ^ return sel;
4 Y/ ^5 I- ?# Q$ ?: a1 m2 Y _ }! _ j! _. C$ F" e: z, c# G
} |