import swarm.Selector;
6 n3 H3 I( w+ s6 a6 _8 n7 m" V! y* }9 C: f
public class SwarmUtils {
/ r1 B, Y) @7 m; s: ^# O9 Q public static Selector getSelector(String name, String method) {/ n6 e, W7 v9 {
Selector sel;
* B+ T2 y ]7 E, j; U: C2 I try {* t& S! t. I! Q& I/ {# f
sel = new Selector(Class.forName(name), method, false);; W" P0 m. v7 w5 I
} catch (Exception e) {- `7 z( h! w7 Y7 j: L9 _
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
8 V$ L" W5 P; ?; u# M& k2 D _ System.err.println(name + "." + method + " returns " + e.getMessage());
5 e0 c; Z, W0 |0 Q System.err.println("The process will be terminated.");
& A, R& |. X M" |# W+ \1 c System.exit(1);# }4 Z- T' J" Y' f' |0 h
return null;
7 i, ?9 h$ D9 b }* M r5 b" n6 V) q
return sel;
8 e. N0 k5 n" B$ M }
! |9 o4 E! f# }# j
- W6 V9 Y& A8 S. y# Y public static Selector getSelector(Object obj, String method) {
; _# H! t+ f+ n Selector sel;
( W& B2 y2 t! ]) ^' F2 R& c* l try {2 S ^7 I% l9 {! \0 t
sel = new Selector(obj.getClass(), method, false);
: z5 T% j/ l1 N# r; _ S8 D1 J } catch (Exception e) {3 ~% Y& G7 B k9 E8 f
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "% a8 r5 w: H8 V$ Y# i
+ (obj.getClass()).getName() + ".");
& M5 e& k" Z3 U# r. | System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());! v E+ c& m% o1 P- E
System.err.println("The process will be terminated.");
; A0 `; R0 \ R, r/ G6 t System.exit(1);! j, \4 z4 d/ O2 u( w
return null;
7 Q; h8 b! i) L3 e8 | }$ ` ~) {; F: F
return sel;9 ~1 ?+ J3 _* s8 |% @
}
1 @& B0 L0 _5 p1 ^4 t} |