import swarm.Selector;
5 j$ l* C8 G+ s; j5 O9 J* B2 |
3 A* a" W' x+ f/ L3 hpublic class SwarmUtils {
1 T# P7 w0 j! W public static Selector getSelector(String name, String method) {9 I. g2 Y1 Y" s: J7 l
Selector sel;
3 U! u1 s) v: A* F/ u try {; `" H" q- `/ ~9 ~3 R
sel = new Selector(Class.forName(name), method, false);# J1 \9 J" `; P
} catch (Exception e) {
/ ~' F" X: ]/ t) s& H System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
8 S. c, v& b2 Z) s System.err.println(name + "." + method + " returns " + e.getMessage());" h$ S" x6 G5 N3 V( \
System.err.println("The process will be terminated.");" _' b: }9 Q t
System.exit(1);
8 n& |3 s6 L* ]* z B" Y) h/ p0 j return null;8 H U" u+ a. i8 n4 o
}0 D* G) {2 K( h. r% y
return sel;8 h+ u6 u' F4 J; G S( v& f. N
}
$ F$ t- B0 k6 D# i& }0 f* d; {- I/ l" S& I2 f
public static Selector getSelector(Object obj, String method) {
+ f4 i* h- J2 T+ X; ~6 k- v Selector sel;
8 N0 q3 m7 r9 t8 Z6 x& f' P% T( L try {
$ [% y; @/ S+ [4 E7 k: D3 \ f. ]3 Z) Q sel = new Selector(obj.getClass(), method, false);: {& Q) m+ v: D( X, q( d/ F
} catch (Exception e) {
: P# C) ?4 o2 x3 p/ n( K+ [ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "& |3 s- H; a5 u2 r
+ (obj.getClass()).getName() + ".");8 g/ _! x" ]# U! [9 ~
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
* T2 |8 f% E" H% p% z4 m, Z! O& U System.err.println("The process will be terminated.");+ M( k$ D4 E- h- s: f
System.exit(1); g, k# K) R/ x, I$ a
return null;( ^2 g6 O# C: E# y
}
3 `- o D) ^ B return sel;
" s. h3 C# W* T0 @& B }
4 h1 R( T2 n W6 B- R0 {: {" ~% V8 m} |