import swarm.Selector;7 g7 C: k) G- M" a! c
Y( @; m/ n5 k/ ?% {2 {
public class SwarmUtils {, n) L1 ^9 o3 |5 R' Y
public static Selector getSelector(String name, String method) {' z; ] l0 Z* `8 V% ~4 X
Selector sel; n" e% h2 ~' ]6 H
try {& I" d/ J' N5 p% J8 F% B
sel = new Selector(Class.forName(name), method, false);
. T$ c0 F: ^8 ^6 L) \0 [ } catch (Exception e) {% G w. r' T8 _/ E' W+ a6 t
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");2 N: e: K6 l# N( m
System.err.println(name + "." + method + " returns " + e.getMessage());) D4 {5 b# l2 {! \% N V8 l& ~
System.err.println("The process will be terminated.");
# F4 l" E3 J A" p9 q. a+ S System.exit(1);
& c6 t D& Q9 F2 x return null;
- F3 i5 z% C, L: J6 }# x: [9 ^5 b }+ r! s" W( T& P7 `) M' M3 P
return sel;( O6 d% ~/ R' k* t7 J
}
8 |8 j) v' r: X0 W& p" F! T- ~$ i1 k' j- o9 S" E1 J7 _ t; A. q
public static Selector getSelector(Object obj, String method) {
+ D l7 a8 Q/ f' ]( x6 l! ? Selector sel;
* I. I! Z1 R& \. Y/ z# d/ z+ A try {% f% h8 \, ~' X1 [7 k2 Y+ t& c
sel = new Selector(obj.getClass(), method, false);- t7 A3 [- k* V/ }. a
} catch (Exception e) {
0 P* _6 }! w* n) m System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " N5 G9 `5 b- T5 ^+ C1 k' y
+ (obj.getClass()).getName() + ".");
: t% P. E, u# Z. ^' R System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
. a$ m2 b$ ]/ n: Z0 d& n! Z System.err.println("The process will be terminated.");
" k* [. c* d' x2 [6 u; e System.exit(1);
* O, f* ]% v5 a8 Y+ d return null;
, u( y U& f& T; e. b6 I' h }/ i/ u' c& T3 A5 G6 {4 |( i" {1 T
return sel;
6 L, o$ P) y5 ^+ W, n7 E* _ }: z/ ]: V, X" X. W
} |