import swarm.Selector;; g! j# f8 \# }% d( v
1 V* |* }4 j/ n1 |+ s' R# V
public class SwarmUtils {
6 a* [. d: R0 U8 V& e- m public static Selector getSelector(String name, String method) {
; j1 E' `% L; M# }1 o Selector sel;
$ o, b4 t& ?& v1 C* j try {$ }1 f1 x* W* }' p
sel = new Selector(Class.forName(name), method, false);: ?4 B7 Z" `3 d, W
} catch (Exception e) {
& S6 I1 W% F8 \5 e" y System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
! i( V- t) Z% B5 [& U4 O System.err.println(name + "." + method + " returns " + e.getMessage());$ u3 L1 N( h0 D
System.err.println("The process will be terminated.");- v, R7 l( i+ H3 K- h9 t
System.exit(1);. h x8 O9 z. \- ^6 S* n
return null;
. B9 G0 l: E( ^! a5 P0 ?/ A6 _8 ? }& r% ~; k8 Z# T& W) ~/ n
return sel;' e; y- [8 k# l3 e! `
}5 @* N3 T2 s) w |8 x: L6 |* A
3 |9 v( _ b/ I- z& M1 V$ A
public static Selector getSelector(Object obj, String method) {9 @4 ^: ]# \% D% i% B2 _& |8 {
Selector sel;9 A% d2 |/ C2 M+ s, f7 p
try {2 M! c- ]4 `( {- D* G: r
sel = new Selector(obj.getClass(), method, false);! D& a! i8 ~; D0 Y; Y
} catch (Exception e) {
/ u S$ W6 n, j1 H1 z System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "; t* I# m0 A5 D3 n- B$ R
+ (obj.getClass()).getName() + ".");4 g% M- M, v: y7 I, o, m
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());5 M4 u5 Y5 u/ U, v4 a
System.err.println("The process will be terminated.");: F: Y/ S) W( \0 G/ X
System.exit(1);& S) }- {9 w: Y6 n9 b
return null;
- z- D7 U; ] v) y: D }
' P: z! L- w/ ^" U1 U1 b return sel;3 C b* h- y, O- o8 C) F7 L3 o. V
}& T% s/ C6 Z' G L
} |