import swarm.Selector;# E3 S* o+ R( S
( \# _9 i( c0 {: r
public class SwarmUtils {5 F9 ^# {3 |$ X( U {: a
public static Selector getSelector(String name, String method) {
. b% p. o2 \$ t Selector sel;
' m9 r& k6 [4 m, N) c$ U( k; ^" I try {% F! h, ^1 B* @- ^: J
sel = new Selector(Class.forName(name), method, false);
( }! `: n; P( d* L! v7 C# {) @ } catch (Exception e) {8 K5 S& K; ~2 W7 F+ \
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");- R: U# {' M; T [# Z `2 k$ u2 u
System.err.println(name + "." + method + " returns " + e.getMessage());+ l) F# b# P+ j, t X, U( r( s
System.err.println("The process will be terminated.");
& \; Y% S& B5 a9 |: A$ r5 h System.exit(1);
" q6 |, i$ E% f( ? F3 \ return null;$ e9 N. B' s8 u
}2 m4 w" k S* W: S4 c, ~. G
return sel;; ~) S! J' S% P+ ~3 f$ C' D4 _
}5 o! v% K0 R2 d! X+ ] w9 Q$ T- [
! {8 E8 `. K Z# m1 h
public static Selector getSelector(Object obj, String method) {
2 Y0 k' x# N. @' r9 c3 A7 a# B2 \ Selector sel;+ J9 C1 `0 [$ C# q+ c1 k
try {$ m1 V$ a2 m2 B
sel = new Selector(obj.getClass(), method, false);. M# L& V- Y, A% `
} catch (Exception e) {* n* Z+ u |" t; M
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
( Z, q. K" c$ ^0 ?" j& p+ n/ v1 M + (obj.getClass()).getName() + ".");6 x% x J0 f9 G
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
1 P/ E! _* A7 P s( }, n System.err.println("The process will be terminated.");/ S5 _7 o& C; {( \ p
System.exit(1);
. s" [, \' `) K @! S' X" B" v1 A9 r9 D return null;+ v# i+ T) Y* r9 w8 c
}
* N- Z, L* W8 A" K& q, x" Y return sel;5 Y2 M, [0 u- P5 k: R
}
5 Q% ?! u: Y1 [/ Y, \} |