import swarm.Selector;, ]2 K# D: S8 f
) I& t# l* ]: L% k
public class SwarmUtils {
6 p6 q/ Y1 n3 {- ?, z: |0 U( F public static Selector getSelector(String name, String method) {; V; Q Y9 F9 N" ~
Selector sel;
) ^& n8 h* ~. s0 ~2 q try {
0 V7 Q, z7 _, T4 {6 u! B sel = new Selector(Class.forName(name), method, false);
! F; J/ O. F' w* |/ \ } catch (Exception e) {
; r" E7 p2 c1 O% M System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");; S8 R# Z- y: `- s0 x: e
System.err.println(name + "." + method + " returns " + e.getMessage());, w7 i$ h& f$ i* l! \8 I
System.err.println("The process will be terminated.");6 e) w) h' I' ~, J
System.exit(1);$ p% }- o f' N2 I/ K
return null;) c2 t" {7 t5 O% m/ l
}
, t' u: {! ~' g# B6 c return sel;
, q2 b& v0 X$ v+ [7 z }
: R5 O% N) V, ?- E2 O
4 L9 X& W4 o- Q% _ public static Selector getSelector(Object obj, String method) {8 L8 H2 p% w# N3 s- L" {1 V
Selector sel;
8 S" X$ E) O5 g4 j( V try {
$ s9 a" Z, w( d7 `; J/ n$ \, c sel = new Selector(obj.getClass(), method, false);* s ]- e9 U& J6 p) \- p6 R
} catch (Exception e) {3 v2 N& ^$ W: E$ x! Y0 b
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "% h& M/ S2 h) u9 v2 Y+ Z
+ (obj.getClass()).getName() + ".");
( K( q8 i2 `+ D( j8 F System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
; L( I5 H4 ?$ C3 q System.err.println("The process will be terminated.");( z9 M! }9 t& e! J7 m6 ~
System.exit(1);
6 t* w! P0 _& j1 e& T return null; j% z) V6 F# c R' `. ]# G7 X" r
}
8 ^# U& |/ |. c! b- o( J return sel;
8 ~9 D, K: K' l' {) D( H* C }2 c) L ?- I5 O4 {
} |