import swarm.Selector;
- k( h0 J9 S! B* f# t& x* R3 {# K% r9 v) `2 S. L
public class SwarmUtils {5 S9 {; w& ?8 ?: m. y$ F
public static Selector getSelector(String name, String method) {* b) {, \# z1 F: r6 b& n
Selector sel;
3 G: A, a1 x: P Q try { h3 P' {; m6 @3 N
sel = new Selector(Class.forName(name), method, false);$ @' t) @$ E* A: c/ t6 F( K7 h2 h
} catch (Exception e) {
) M( t3 J# Z" S2 d( U; | System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");. W1 J' g8 R) v6 Q) Z1 `1 O
System.err.println(name + "." + method + " returns " + e.getMessage());. z& h, ~% q& G$ ?1 @8 u
System.err.println("The process will be terminated.");
5 K0 i1 v9 C3 n System.exit(1);
# B# s3 R' i- k& x( I5 N% B! q8 p return null;+ Q3 R4 Q3 m( Y+ L/ ^+ C
}' S2 {: C* C) F- A
return sel;
- U/ L( D( v n _# l( W3 q- I7 C+ n }
5 H0 C. j y5 I) U/ L% y5 {2 { Y0 U) D& z# K/ H
public static Selector getSelector(Object obj, String method) {
" h/ T. V1 [3 x* w/ `& U Selector sel;& d: q! D7 |& @. S9 Y' {
try {9 u& V9 L6 U5 T
sel = new Selector(obj.getClass(), method, false);
l r) }# l; Q: c8 A: ~/ X( W } catch (Exception e) {
- N+ ~' ]7 `3 _( G; z) ?' r System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "6 [6 q# _, G" L: i* h: z+ s
+ (obj.getClass()).getName() + ".");; L& @1 [3 \& E) T, Z3 }: l8 y
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());7 r, \* }6 A% M- y. U5 Z( ^ k
System.err.println("The process will be terminated.");
! c$ p, v4 m7 B, O0 \7 E% u. t System.exit(1);
- U2 \; a+ q$ Y! }. X2 U return null;
( A7 B) O( v9 h* a/ D; @+ R7 ^ }, ]0 z/ t4 u9 _$ b3 x% |+ O, ]1 X
return sel;- L% |4 u7 Z) P, p
}, m7 C! o. a0 Y, J! s1 m9 f
} |