import swarm.Selector;
& L, g+ Y3 i+ u$ z& l7 ]$ L6 B7 a D- @. \1 b# N6 U* z$ S ]
public class SwarmUtils {
: s5 k6 L2 E1 `$ F( X% h5 i public static Selector getSelector(String name, String method) {
9 _( R. X( `& x) q b Selector sel;
# i& a. e/ c$ I! P try {7 R6 Y8 M* T7 c& c& T" o Y
sel = new Selector(Class.forName(name), method, false); u. A4 I+ O; s! f( d
} catch (Exception e) {
* N2 u+ q* P' m7 N System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
8 x8 D; u4 d( j+ ]! t/ H- _ System.err.println(name + "." + method + " returns " + e.getMessage());6 Q- Z5 U/ I+ X' G$ T; R& n9 }/ e
System.err.println("The process will be terminated.");( |4 r" |/ x6 {8 h: |
System.exit(1);$ N6 i, p9 r& n3 q9 P' f0 G
return null;7 a7 N, @' Y' f, H1 u
}
' R5 u: ?, B- _ _2 p# L4 } return sel;" g5 U$ \! Y: m& ]
}
1 i+ p( h' n/ H) C5 k& K' b
3 r3 d6 }! x6 k) ~% Q9 L7 q4 F public static Selector getSelector(Object obj, String method) {; `; f) `% P* o5 b& w" V
Selector sel;
# c8 b. h0 A4 F( Z C$ j; G( q try {3 o, v% p1 v# S) s8 W
sel = new Selector(obj.getClass(), method, false);
. j* d4 I4 A$ X: q' P3 E5 y" c } catch (Exception e) { m' B \- y- M5 F/ `; W
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "2 u$ C) {, E* j- t- S+ X- Y8 |
+ (obj.getClass()).getName() + ".");" A. C. Z. T; ?( q* i8 O
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
$ _$ d3 {$ u7 D" t1 ]" y System.err.println("The process will be terminated.");
# j' g9 V2 k; l( u( I( d System.exit(1);
, T8 A$ x: T8 s3 e5 `4 C! ?% V$ f return null;& Q4 v$ e% ~0 Y3 m& ^ X
}# W& {: ?/ [( O. D H- h
return sel;
2 p1 I# s8 |3 K5 O& k }
' Y) a3 ]5 o" }& X1 v+ }2 K4 O' k} |