import swarm.Selector;. R8 v. U* b4 m9 Y2 [
) d: @; l: X/ i2 [
public class SwarmUtils {7 A- O7 H: r$ ]5 {* `0 J' M: R A
public static Selector getSelector(String name, String method) {
* c( c2 ?1 t0 j- U! r Selector sel;
0 x! y0 w6 {$ l r l& e5 @5 A try {4 o/ T6 z/ }, x# {" Z
sel = new Selector(Class.forName(name), method, false);
% n: K/ L/ `9 ]2 m } catch (Exception e) {* O' p- X( J/ }, v) Z$ j0 X4 y
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
# K E5 \4 _+ } System.err.println(name + "." + method + " returns " + e.getMessage());7 [% o! E) O( ]$ X, J* A
System.err.println("The process will be terminated.");) t' n% G. z6 b
System.exit(1);
8 @% p& n I, i& E return null;
& c p/ `* ?1 ]+ X }
5 i1 j5 [( a; L: v. O0 D& Y return sel;5 O j+ A* t% V* x2 m, O
}
" T; c+ Q( Y" J: B& X5 X8 s% o3 I2 ^. R0 Q9 Y9 I
public static Selector getSelector(Object obj, String method) {4 D6 w3 m6 p0 X
Selector sel;
; u3 M* w9 j9 |" z try {
8 {7 v) C6 ?; `3 S0 n sel = new Selector(obj.getClass(), method, false);3 @8 k, D, c: d$ T) L. I3 h
} catch (Exception e) {: j2 ~# k0 o1 p' B: }2 p8 a _) U
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "5 c. B# ^9 e7 X; a" m0 v
+ (obj.getClass()).getName() + ".");
3 P' z7 i- W1 v6 N* J System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());3 L" V, p3 j# I$ U: A! k- z8 d
System.err.println("The process will be terminated.");
) w9 Z) P; H. F9 ?: k/ g+ L% Q+ K System.exit(1);9 V2 q$ j5 y$ |8 y0 i0 q/ N9 ~
return null;
2 E* E$ v, x; `9 U) g! q }
& Y: O, k% O# T O8 s8 U) v return sel;
, Y6 n. p1 R, X' m" X4 T }# |4 J( C* @/ h9 v% {- v
} |