import swarm.Selector;
+ o) K. B a W* s2 j; N2 [9 o2 @7 `. y/ o6 I6 n
public class SwarmUtils {% T/ g+ @; W: i' r
public static Selector getSelector(String name, String method) {
" v2 E1 D) U' I" n0 r' p$ n% w Selector sel;, P q0 U! F; U5 `' Y4 Z
try {2 s- J w6 O( w5 c! I
sel = new Selector(Class.forName(name), method, false);9 G) Z5 }7 ^5 _6 j& n
} catch (Exception e) {
' x# _. ?6 F. M/ |; {) r0 Z E* z System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
% c* W8 y( I4 v3 Q% ~0 \9 @( h7 g System.err.println(name + "." + method + " returns " + e.getMessage());8 h8 }3 Z2 |2 g
System.err.println("The process will be terminated.");
: T" T3 y8 N! G: V System.exit(1);
9 f' n; j! T9 A return null;
3 N2 X, M% O3 a5 @ }
/ e0 ?6 U# D- x& m return sel;
8 b, O$ I% J0 A$ e& v% L) { E }. e, [# G' f' k5 q% U x% K
, G* [/ W% C# @; `! p- \+ X- ~
public static Selector getSelector(Object obj, String method) {4 A2 J- M' m% C, q# ]5 V5 j
Selector sel;
' a: Q- Q$ S; `1 V try {
! m0 k. p* M; Y; }8 o sel = new Selector(obj.getClass(), method, false);
; m: B7 u# Y! k, P } catch (Exception e) {/ o' T1 F" a# U( V t* W; i
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
1 H& f. a v/ c D: E1 [ @ + (obj.getClass()).getName() + ".");- K9 m8 p @# x5 c6 [
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
( Z& o/ Z8 s/ Z* D/ [3 Y System.err.println("The process will be terminated.");
! R) a7 F( m3 e# I, u [ System.exit(1);: g) E" I9 v0 u/ H% ?- w# {+ _) R
return null;
, l" @8 H' [. _) R' G }$ _/ }1 O, u/ Q+ W1 j
return sel;; D+ j+ X! f: ~; G8 o. o- E
}
2 M( P4 F1 Y) r X- G4 F6 F+ u# A} |