import swarm.Selector;
9 F V( t% D& s5 t/ B
( K- ], a; R4 H( I" q- kpublic class SwarmUtils {
; n0 R; _5 b* ~ O5 I3 k5 j public static Selector getSelector(String name, String method) {) N. x( E2 e' x
Selector sel;
. l/ P( O8 |& B* b try {4 q: M2 A% a4 M5 f. o0 b
sel = new Selector(Class.forName(name), method, false);, I7 p" m2 m3 N3 H. O
} catch (Exception e) {
5 B1 E9 g1 C) b( }- B System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
* c, \8 L ]( g- l System.err.println(name + "." + method + " returns " + e.getMessage());
( D2 r3 S) E) f* |6 v& h$ H# ` System.err.println("The process will be terminated.");
* Q3 v7 A) ^7 V, x; B System.exit(1);
9 r& r( @ f2 u9 G9 L return null;7 S9 m/ e- J! `
}
5 c+ t. Y J: ^ return sel;
N# {& H% X/ Q& f2 D) b }
- G8 r+ s8 b2 V t! b7 b1 a
- ]7 h5 k5 E# I9 D5 A( I/ q* J6 j public static Selector getSelector(Object obj, String method) {
2 k! v' }2 k2 {- Y. X Selector sel;
$ V$ @" n+ E! R1 G try {
+ V3 U) v2 }6 S! r: ` sel = new Selector(obj.getClass(), method, false);
8 l0 ~! p1 W7 n G+ j! ^9 B } catch (Exception e) {
9 B- S" [7 D; x+ F- @ G System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "$ ^6 l$ f' t- n0 q0 J
+ (obj.getClass()).getName() + ".");
4 E" _3 Q8 z9 L3 C System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());" N) w4 U& G e% ~/ x m, k5 O
System.err.println("The process will be terminated.");7 _" j4 y0 N' T' O' O
System.exit(1);7 B' X4 L- _5 B4 U$ d z1 d; s
return null;
% d, R8 \( V0 ]& D }' ^8 K0 r% w$ U# L
return sel;9 |. G# @% o0 {7 n& U
}) G; z4 g7 W9 y$ S
} |