import swarm.Selector;
- M5 w! M0 [- Y* E7 Q3 W! u: I$ H0 O+ ^- F% W8 e
public class SwarmUtils {4 V+ x8 h% j3 n0 I! i# D
public static Selector getSelector(String name, String method) {
0 }3 d& G0 b5 D2 o3 U+ @" ^ Selector sel;
7 T0 H3 n, X+ y+ v; m2 u try {
" s* s. L- F8 Y7 O% K0 e sel = new Selector(Class.forName(name), method, false);
' L0 V! m! [/ W6 \# f } catch (Exception e) {( w" f+ h' q' u4 o2 u
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");% s3 @! A; c+ u, N4 r
System.err.println(name + "." + method + " returns " + e.getMessage());2 M2 Q- ^' s( O; E! I+ Q% p5 W ?
System.err.println("The process will be terminated.");3 j. b+ c: e" ]* b# A
System.exit(1);0 M" D# J$ s" a
return null;, w: O6 d5 t. J" j0 s, ]" y1 p) @
}% |# }# F8 {( f K1 ], w- j% ^
return sel;0 X% S6 H$ x+ W
}
7 B8 J N! c c8 Q9 @; ~: U6 u
6 F: R& p& N" T& F9 t$ }% I% y public static Selector getSelector(Object obj, String method) {
% P" h, f) O: ~& x3 R Selector sel;
: u3 q' M0 r8 e' A! m try {
& V" M: s4 V" w! h sel = new Selector(obj.getClass(), method, false);/ c1 ]# s$ j$ [3 @# A/ t& m
} catch (Exception e) {$ a0 p% o- o! R2 `4 J
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
" s+ m9 D" t) a, G7 m, E + (obj.getClass()).getName() + ".");* k/ m$ J! `1 C2 j1 ~+ `1 a
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
0 M" y" }) E7 ^/ F8 n System.err.println("The process will be terminated.");3 c% g9 i1 U+ x, `7 m
System.exit(1);
. T) i# k9 @% H return null;
. U& M! w( x# J3 H+ _2 U v" b }6 [, C1 J2 ~; j; f m$ C g5 ^
return sel;
7 M! Z7 p2 r$ S- O }: {% e$ E5 j! s' M2 R q
} |