import swarm.Selector;
' |% A' [; a! {' z7 d B( {$ R) h/ V" n1 f$ b. q1 `/ _
public class SwarmUtils {
6 t! y5 T7 @5 F& I$ |/ w1 `0 M public static Selector getSelector(String name, String method) {
4 G9 [- k% k: |1 Q Selector sel;! B- \0 X3 b' p
try {
4 W. [/ Z4 w( Y+ E* m; T4 |" u sel = new Selector(Class.forName(name), method, false); d7 R* V- s9 ^1 E
} catch (Exception e) {2 I5 V# ]8 O u8 n( x( m
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");# n* D8 I) h+ Y. O0 d
System.err.println(name + "." + method + " returns " + e.getMessage());* U4 T6 ^, u. q; q& A- m8 J' M! A3 X% [2 W
System.err.println("The process will be terminated.");5 E% U! o7 b4 h) e
System.exit(1);# n, r/ c1 p( l1 w% X/ M
return null;
1 S$ X4 R+ T2 W$ D }. K" K& @% ^9 |/ a3 z4 x7 z0 G4 w
return sel;
: b- d( T& [7 D1 C0 v, V4 d }
/ V" D0 L8 S+ W d# d, f* A5 H% Y2 H- R& c+ k0 T" F( c8 X
public static Selector getSelector(Object obj, String method) {
$ Q5 ^0 l( y0 R9 B0 \4 r P Selector sel;" n1 p! e4 ^- E
try {, H/ a! S; g+ B
sel = new Selector(obj.getClass(), method, false);% H: J) ^" O0 h
} catch (Exception e) {
7 s& t1 @3 E( g7 F# u) p& [ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "5 n, V0 _' ]! V3 x% G9 Y
+ (obj.getClass()).getName() + ".");
* M5 M5 T" w4 L6 R' ~; m) H System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());# W$ m# U: J- _' S- x5 n
System.err.println("The process will be terminated.");
- u# u- n% { E: E System.exit(1);$ @3 b9 r$ Y# A1 B: s. h: ?: }
return null;
/ ?% ^. E* H5 m }, L/ X( e$ u" ]" b, c! m1 p
return sel;
# f- h1 R1 N1 Z& w }
. M* r+ }6 ^" K' Z# n. b9 [ f# ^} |