import swarm.Selector;& X! I: B; J p# |8 H! I: I
$ `" B. P' W( G: }. y1 m. Z
public class SwarmUtils {1 ]( @$ V0 W$ \( a! K1 K) _
public static Selector getSelector(String name, String method) {! E, Q+ P f3 F1 T* ?
Selector sel;/ u& |( X8 [2 d, \) l5 @( Z8 Z
try {
1 a9 o; X+ K' {/ o sel = new Selector(Class.forName(name), method, false);
3 G! j {# U6 s4 b. F5 d } catch (Exception e) {
9 O3 S+ X( J4 ~% e! a, \- \ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
2 `% r+ ]2 }! q7 f( ?7 w0 P9 Y6 v: b System.err.println(name + "." + method + " returns " + e.getMessage());$ }! v( b& a% P" E2 |# B8 G; n. b
System.err.println("The process will be terminated.");- V+ _! u$ ~. G( U! g1 {9 F
System.exit(1);9 Z6 N/ b6 D. D# j7 w( k- ~; g, Y6 B
return null;
& x) J S5 w! ?( @3 K }* T+ H6 ~4 B+ k/ V) v, `; d
return sel;
: B R. ^0 j7 D2 ~; m" ? }4 r9 U, f* p" g5 [
. J; f8 e4 O' m4 J
public static Selector getSelector(Object obj, String method) {# u1 l$ W; [9 O6 ^
Selector sel;$ M3 d7 T$ p1 ^2 N; A1 e# _) w* Q
try {* ]/ B5 P" A9 K# T
sel = new Selector(obj.getClass(), method, false);
3 V J {% r, S } catch (Exception e) {
$ t5 r. Y) M+ ^ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
1 n7 C* O8 F! ^/ ?4 G" y8 [6 r + (obj.getClass()).getName() + ".");9 k7 {! c* i; i( _! Y
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());; F" U# Y! O$ S0 F' s8 u, `3 X5 z
System.err.println("The process will be terminated.");
4 U2 X& I) J: W, g2 O System.exit(1);3 r* m1 ^9 _7 t: l
return null;
6 F: a8 `& Z5 `4 n }
/ g- f6 Z; I# C( i+ ^ return sel;
/ J! `! d: S* E) }$ |+ z }
, n) a/ S# u0 S9 O9 s" I4 {} |