import swarm.Selector;
# q/ V! W! j) q# o0 P
3 w9 h. g" i9 I* X1 Jpublic class SwarmUtils {# `7 q4 M1 }$ u# t! u0 t
public static Selector getSelector(String name, String method) {5 r1 L5 x' e2 t! I
Selector sel;1 r/ [5 Q: e) U- I
try {
* \; n, ?' m( \9 K" L6 q sel = new Selector(Class.forName(name), method, false);" c! N( h- j2 ^! O) H
} catch (Exception e) {
6 B7 O% @/ o" Q; |3 D# O! L System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
$ ?3 s: V% x( z! ^ System.err.println(name + "." + method + " returns " + e.getMessage());
- m6 w2 X5 N, C7 G5 Z# K System.err.println("The process will be terminated.");
1 K/ z6 K7 I& j) U/ n2 O5 ~/ m System.exit(1);9 @/ D* O+ d+ Z, ]% y
return null;6 T. ?1 J ~7 _7 J* w- j6 m! v
}
' y: _) Z* n+ l: U- D! D return sel;! w3 ? X2 o2 C& S1 G% R; O' M
}+ d3 t& O0 [8 q3 x
5 j2 v2 J" T* {' b E: c1 J" C public static Selector getSelector(Object obj, String method) {
8 H; B2 }. A1 _: E# u* }" K' G Selector sel;
' c2 q" Q) {1 D! |* |, I try {
$ N& Z3 \6 @4 \7 y) K: z- d sel = new Selector(obj.getClass(), method, false);( |% a- X/ r3 [' Y4 w! @
} catch (Exception e) {2 _! K8 t4 o6 M3 B; H6 w
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "$ _/ J! k k' g9 Y5 X
+ (obj.getClass()).getName() + ".");" b6 ~% ?% \( _; H
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
: L$ c! r1 S7 Z+ s: [ System.err.println("The process will be terminated.");5 r: T/ o& v3 C4 {& B+ T# u
System.exit(1);. x! a' U! W1 A9 T
return null;" \( g) _1 v1 {0 X3 f' W
}% ]- z0 z. Y1 v* Y
return sel;& Y8 m$ r. d# [/ H- x3 [" R
}7 L3 E! N) v8 o
} |