import swarm.Selector;2 _9 |! ?, r6 l
; x" R' {3 p4 e4 Upublic class SwarmUtils {. S- H. b5 z1 p; R) E# Y
public static Selector getSelector(String name, String method) {
9 |( _! K7 K6 A9 P Selector sel;
3 [- O$ u) j9 K3 y try {
, i! C3 M; j& E$ h1 x# z. u sel = new Selector(Class.forName(name), method, false);
4 |' J# D7 J' ~/ B } catch (Exception e) {
$ z' i# K$ u/ A) i: x, _" o0 k+ T System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
! A7 L- d. ^1 O% `9 g System.err.println(name + "." + method + " returns " + e.getMessage());
8 J' W* ]1 |" K# p5 q% T System.err.println("The process will be terminated.");- ?# _- L, [2 U( Z' v5 Z
System.exit(1);' p- R0 b" G4 y' J
return null;9 @+ s. g! f* K9 I. G, w' p
}
) E5 X8 Y2 I) L' q6 [1 f return sel;
7 {5 U+ p/ k7 v$ q1 } }
4 v' }8 K4 D+ r( Y( J
7 ]2 r* B- M9 U8 C7 J: M0 U5 Y4 ~ public static Selector getSelector(Object obj, String method) {
* R4 O7 m' ~" I) o6 u" A2 `' l6 m Selector sel;
3 [% y, G3 d q0 b; h try {
2 O( z) `0 s* u0 e1 Y8 i sel = new Selector(obj.getClass(), method, false);
' x: f2 Y/ G4 _( R& b } catch (Exception e) {- _& M, ?. N5 r/ n. f& M9 e
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ") G6 d; a. a2 c* g0 W
+ (obj.getClass()).getName() + ".");, Z1 V+ Z6 i$ b8 b
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
9 I9 t+ l: O& V) J System.err.println("The process will be terminated.");
9 |% f Z4 u% q, ^+ E System.exit(1);2 A2 j1 _/ b" X% G( c
return null;1 f: u" M! H4 `- H- {+ B; j
}
0 D- y% @* ]" x) | return sel;2 u/ h$ g# R2 C5 Z7 N
}
* z/ n+ y4 a5 Z" q0 k8 k$ Y, q} |