import swarm.Selector;
9 ]5 M/ y+ ?6 E( M1 @' Y: N2 u3 j2 ?+ M
public class SwarmUtils {
7 { \# @9 a r. }$ V; B% T public static Selector getSelector(String name, String method) {
4 K* K) o) s* N9 i/ o, a Selector sel;! d: e5 b! K0 @8 p' s
try {7 g, D* S$ t$ i9 t
sel = new Selector(Class.forName(name), method, false);
, T+ e5 s' g; s" [) g% s. h, w, S% L } catch (Exception e) {
4 S! B9 i7 x5 [' {: Y6 r, e9 ^ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
, r1 K& r7 b/ M+ I System.err.println(name + "." + method + " returns " + e.getMessage());: I! Q+ I4 D6 _+ G
System.err.println("The process will be terminated.");
6 U2 R0 u) c7 g' o0 M! U System.exit(1);
* E2 n; h. L* [0 y0 k) ~ return null;( M; x1 l+ x) m4 g) c
}
* U4 ]3 r2 u; \( s. K1 Q return sel;! D$ k- _7 H& q0 y' k, Z
}. O7 r, ?7 d' r" P3 Y# N% ^0 I
- D" _9 A4 Z: w2 [
public static Selector getSelector(Object obj, String method) {
# M& E. _. R! t6 e+ L% a' U% u Selector sel;& B# M' l+ ~ v7 u' \* E* o$ `
try {
! Y5 B. E: ]8 S/ \0 E7 T0 u sel = new Selector(obj.getClass(), method, false);
: D' r8 k7 R1 a$ L6 U% f* H } catch (Exception e) {" |! P! M4 l! M& J4 R) Z" W
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "8 j) J: o5 F3 \
+ (obj.getClass()).getName() + ".");
( ~) [/ D' i" n System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
1 `* b! ^1 w' L$ V+ D2 S( Y6 x System.err.println("The process will be terminated.");2 R i; i1 }6 B7 q+ A8 f
System.exit(1);
0 F1 L, R1 v: P# k( l return null;
$ z! O) u& v2 O; a. A; p }2 O9 j2 P5 W# l8 r- B& w
return sel;
* T8 I! F7 O% I7 Z! |( \3 L }
2 j2 G \( o. d6 A0 X1 }( h$ F} |