import swarm.Selector;
) h+ p' y( H0 D( ]7 ]9 D
* m6 V$ V! ~7 P- a- o& q* l7 opublic class SwarmUtils {
8 j! ?6 Z" E' e& R$ Q& m1 Y0 }1 _ public static Selector getSelector(String name, String method) {
3 F! B0 h! T) ` Selector sel; a% `: H# [! T, @ z9 e/ z8 y$ a6 w I5 \
try {
1 Q- l( s X- L sel = new Selector(Class.forName(name), method, false);5 D1 A8 a" p7 T: b8 N/ P- l5 d
} catch (Exception e) {
& f, K& D0 k7 |) x System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
' T- _. }* N1 L: R- s) n System.err.println(name + "." + method + " returns " + e.getMessage());
) C0 Y: E6 x, n$ ^" ^, I! Q8 _$ E System.err.println("The process will be terminated.");) x& {/ [, G8 d$ n2 {
System.exit(1);# u; j% |' {* n: @$ ~
return null;) m! R. D+ y' W n& ~$ H: y
}! x" T4 {+ f8 E$ w' g
return sel;
$ N1 @. L( I3 N& _4 Z. r7 V }9 w9 L7 h0 A/ P5 S4 ?' q
, O1 Z8 w+ l# }' b$ i
public static Selector getSelector(Object obj, String method) {
3 Z3 s. E+ `) m% S" }7 }/ c, c Selector sel;
: O0 U* A, |/ `% b) | try {* A* @* o$ [. `3 x
sel = new Selector(obj.getClass(), method, false);
4 y. R8 R' n7 r: C) Y' O } catch (Exception e) {( T% ?% B/ I( E% w' Y* o
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "' b' Y, s | d' g
+ (obj.getClass()).getName() + ".");0 P3 H- ~. {2 y" e: _
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());; _4 @% a2 ~. C- G. M# v; [
System.err.println("The process will be terminated.");) M6 `: J; A: D. K5 }1 b
System.exit(1);$ }2 _0 {0 O. d9 M
return null;
8 I; r; j7 i2 C4 { }& d% x4 Q5 s3 G3 p6 g- [+ t3 a% n3 Z* X
return sel;
3 @. t" \! c9 ?* z7 S9 ?% f( v! a8 i2 I }6 l5 q% j- b4 K: @" R& ^( U
} |