import swarm.Selector;
4 y; x9 o! F4 O. G. _" x4 j3 x( g% B9 t* U
public class SwarmUtils {
4 q/ L, e2 B2 j, r# j R5 M2 C public static Selector getSelector(String name, String method) {
# S; R4 h2 D9 d/ x Selector sel;; g+ \4 _, g% u# K9 L* l7 r
try {
, Z4 D! S- m8 ? sel = new Selector(Class.forName(name), method, false);4 f# D# A `, l6 G
} catch (Exception e) {! h$ ?. w! r" P0 y4 h4 _! ?/ ^
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");: K( e" ]8 W5 t- O1 Z2 B
System.err.println(name + "." + method + " returns " + e.getMessage());+ }7 V# j" m$ s8 P8 p
System.err.println("The process will be terminated.");3 p& _: [6 i5 }. S! D+ g$ l( \
System.exit(1);
8 I* @+ q2 T+ D/ X) D+ F6 I6 e return null;
2 m6 X4 A! ~$ z8 F. i E }; K$ I+ e7 E0 Q
return sel;" R4 e# J+ o I% {- V
}7 W5 g# r9 M/ R1 e
9 l6 @+ S2 ~ m h) p; g* n# i
public static Selector getSelector(Object obj, String method) {, g& v1 C3 ^% B4 }9 P4 ^
Selector sel;
& L: r% i1 S8 e" T' v- N try {3 n/ ~" z8 d" ^ R& [
sel = new Selector(obj.getClass(), method, false);
6 P7 @% p! F) W& Y* W } catch (Exception e) {! W t. a0 r* Z- c, }' ^- O
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "9 S3 O! O, E$ H5 U+ l
+ (obj.getClass()).getName() + ".");1 J6 T4 I2 Z# a$ h9 F
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
% d1 `4 C( l! I9 F9 L; p System.err.println("The process will be terminated.");9 `4 L2 p2 k) t4 y% q a
System.exit(1);
& z8 ^8 Q" v. l% M$ I return null;2 o$ n3 f3 Y$ B3 I
}
6 U# ~+ q0 |/ ]0 E7 m6 Y return sel;' S9 g3 G/ W. I# J
}9 ?$ ~3 @* t% q" y" m. M/ K6 y) v
} |