import swarm.Selector;3 U I/ Q+ t" K6 \$ ]2 r
! c1 w# O) ~- i+ i$ apublic class SwarmUtils {( A/ ~/ {" G* S4 t7 [% q: j; `
public static Selector getSelector(String name, String method) {
8 O: v+ b2 m4 s$ l! T5 O, Q, ~+ V Selector sel;
4 b1 u, B6 r! J, l" q try {: Y5 e& z" `% a q s* {
sel = new Selector(Class.forName(name), method, false);# ~' u/ ^- J: \
} catch (Exception e) {. B: N" G9 z, M. }6 Q
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");6 ?$ d$ A9 w6 z* \
System.err.println(name + "." + method + " returns " + e.getMessage());# D9 P0 S7 A. I
System.err.println("The process will be terminated.");0 [9 @) Z2 |6 c Q @; ^
System.exit(1);
4 X) B- [2 G- e) O y# s$ m' G3 @ return null;
! F' k1 R4 M! r" V }* X% k, j% j' X' J1 Z; p
return sel;* y) o3 S. j& }- \* V! G
}
` s: v( z. V
$ ~6 y0 _, [6 v2 f2 t+ H/ S: h public static Selector getSelector(Object obj, String method) {8 c7 G, c+ u4 F5 M! l
Selector sel;
) z; G4 P! q$ e D2 M8 M try {
; Q& y# o3 A( @1 q% c sel = new Selector(obj.getClass(), method, false);
& m9 x) j$ J \7 N; f } catch (Exception e) {
3 }5 r6 G( z% I p1 @/ q; \* }: g System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
' B$ G* }- N( j% Q( d# v + (obj.getClass()).getName() + ".");4 V) K# Z6 J* L8 [; J* G6 l
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
# n0 Y) _7 i, B) O System.err.println("The process will be terminated.");
# G) G5 _% {/ S, O1 e* l2 r System.exit(1);& y! \$ ?3 J! r- w6 L( n; u7 S
return null;
1 v/ c# ]; q8 j6 ~; d }2 d& r7 k- q6 a( z" [% s
return sel;" k8 t1 f3 {& Z; |( w& \+ o0 V7 d
}
6 m# Y i) A1 T" m# j} |