import swarm.Selector; t9 Q1 w# g. Y4 Z9 ]
, b; E6 M" @ y3 G" U3 apublic class SwarmUtils {
% f( }6 _7 K- _% R: z public static Selector getSelector(String name, String method) {; T4 ~9 a- `4 g- Q
Selector sel;
( _% ~2 ~9 j) j* e& }7 P try {
. j8 `- O2 e' q8 c7 }# l# |/ F sel = new Selector(Class.forName(name), method, false);
/ v8 O* R) S2 n+ n- H' f' ? } catch (Exception e) {2 ~# A, k6 t+ `6 B V
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");* z, j! }4 q9 U6 A
System.err.println(name + "." + method + " returns " + e.getMessage());
/ r) M) G% P& k System.err.println("The process will be terminated.");
9 s/ r$ R; n4 a6 o* [* \ System.exit(1);
' e% W% y- Q- t! _7 E return null;7 `- c' {, ~' q3 n/ r' T7 A
}
* S0 M; J# H6 Z6 G5 E% V+ M0 e return sel;9 @1 b6 |5 y4 S' k7 M
}2 m$ Q: q/ T8 {$ T0 B$ c+ Y
) ~* M4 p: `( B public static Selector getSelector(Object obj, String method) {5 z+ K8 g; G$ j% R
Selector sel;+ I0 l' n5 j, {) v% ?5 i
try {
9 l# R5 V2 v7 Z3 K sel = new Selector(obj.getClass(), method, false);$ w4 x( N2 t i7 }7 x$ H6 i4 [
} catch (Exception e) {
6 \) p$ |. \0 O, T+ r) Z System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "" |8 o, N: W. ]5 V i/ Y- S' a
+ (obj.getClass()).getName() + "."); [! T3 a1 ?8 ~
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
! l" z1 h( Q! K/ ?8 J System.err.println("The process will be terminated.");+ F" T9 h; E$ Y( r2 v/ W
System.exit(1);
3 r! t! ^0 Y* v9 M1 ]% P return null;* w8 J: R$ ~" h1 T
}* Y* Q7 Q# q( u/ [. q
return sel;7 K( M3 \- _3 g2 v5 C7 V# W
}
# {8 k8 B6 g- ^8 O" r} |