import swarm.Selector;
3 j9 t$ x4 u7 J" h2 Q. I
6 C" o$ _! }0 l3 |" {1 cpublic class SwarmUtils {$ g- U+ s( n( ?' c# H
public static Selector getSelector(String name, String method) {
+ `: V- @5 d+ C8 A! o, M% n' J Selector sel;, ^' ?/ C0 o: T5 M: `! a
try {
: A* u5 Q5 a3 s* K. _ sel = new Selector(Class.forName(name), method, false);0 [; H6 O$ @1 @" Z0 J( b
} catch (Exception e) {
4 u- }: W; ]9 B" J; [ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");: g' Q8 O9 k- x5 ?$ T0 S
System.err.println(name + "." + method + " returns " + e.getMessage());
0 ?! m3 j! V+ L/ J System.err.println("The process will be terminated.");+ d' n6 V; A$ Y3 ?: ]7 b- \
System.exit(1);
# X0 r! m [% e- k& `8 Z' E1 @) H return null;
8 q. A8 h z) Y) F; W) W3 ] }
: e/ ~: o2 ~- w" Y return sel;
6 H3 c& y2 u7 _, I7 r }1 g2 j- p1 ?5 o) c
+ ]1 |' Y: g5 z) {; d) g
public static Selector getSelector(Object obj, String method) {' O# P7 J# m* B1 V! E r5 i! b( O
Selector sel;1 x: z3 d' @! ?: i6 t
try {
+ g) ^' Z& C! R sel = new Selector(obj.getClass(), method, false);( d1 T6 Z# T# R
} catch (Exception e) {
$ Z/ J! w8 S: y System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "# g" r2 m6 h4 X8 b4 w/ u
+ (obj.getClass()).getName() + ".");
$ m# K2 C/ Y. ?6 w9 ] System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
3 j: c+ ^& \1 y System.err.println("The process will be terminated.");
- B0 [3 l& g/ J7 e System.exit(1);
- P* ^8 ?5 i. h9 \ return null;
% ~( Q2 E6 o3 c9 [8 u% Q } T3 M8 v6 m8 U$ v: R! K3 G* N" \' {
return sel;8 ~) r7 q0 r, I* r( g3 }
}
' x4 r: T! P- g2 N# H9 N* u' f} |