import swarm.Selector;
2 q# o$ R# g1 r
* g( ~- A" b/ v9 o rpublic class SwarmUtils {
7 N" P% U% K) @; |1 ~ public static Selector getSelector(String name, String method) {
! N, P# M Y; \4 d# L% O# [ Selector sel;
' M @( b! x/ c% j* h try {
} W% D0 J* U4 G5 O+ u3 V sel = new Selector(Class.forName(name), method, false);
' h$ ^9 w& ?4 j, m) W$ T } catch (Exception e) {
7 m& G6 Z7 D- _# A, N6 \$ d System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");0 x/ }* q; d) J( S
System.err.println(name + "." + method + " returns " + e.getMessage());3 O# d5 }8 P+ W5 C! z
System.err.println("The process will be terminated.");1 I F" e+ V) {3 F2 K
System.exit(1);
, M- z/ U0 Z$ U# w3 @ return null;
8 Z8 \' W$ n+ i1 q1 ] }; \; p" p! ^$ U5 B6 H, G
return sel;
' B% Y3 G- m7 j& q& l4 w }
. J. _4 B5 H4 W- \& ^
1 c1 q( X: J) o8 Y, h4 @ public static Selector getSelector(Object obj, String method) {0 d% A3 }# O; J$ P( O
Selector sel;
+ f9 f% N4 k3 `$ C2 J' b% i9 g try {
- ?# n' T/ X# s9 Y sel = new Selector(obj.getClass(), method, false);1 L8 ]" V- X! k0 n
} catch (Exception e) {5 L8 ]4 J+ [3 t: A- P# U
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
9 A# o9 H, |( t( \% | + (obj.getClass()).getName() + ".");
0 F. `+ Q) M- p8 V3 k System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
7 f9 u: h$ d5 O/ M9 `! @ System.err.println("The process will be terminated.");% Y. }" ]. H1 Z; w5 L: z
System.exit(1);
% H6 \7 E5 q! H$ z9 h3 }* z" P return null;
0 D! \1 c1 z; q5 v- u8 y }
- N! E# e% a* X$ j$ ^1 A return sel;8 O5 k, F F' m! n
}
1 Q. r5 x( Z. X' b} |