import swarm.Selector;" S0 t, T3 s) |- B
5 E! x2 A- i }4 {0 f
public class SwarmUtils {8 k2 W0 M" v& R3 S( U
public static Selector getSelector(String name, String method) {
. U" X- g# A) \% R0 t6 _& r4 m Selector sel;
2 q2 o! Y' g$ T. ?' L try {
8 E! w l2 Z- h/ ~: M sel = new Selector(Class.forName(name), method, false);
4 ?# T( `* S. g1 ^7 u- j0 \, J } catch (Exception e) {
- N3 V( q1 m+ d' X* ?" @* Z System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");0 C# i+ u( N1 |
System.err.println(name + "." + method + " returns " + e.getMessage());" B( m9 ^: `2 w
System.err.println("The process will be terminated.");6 b5 m8 |+ `2 v2 f
System.exit(1);
) E! x. X7 Z3 ~. X3 ^" M/ o return null;' w6 Z4 k% W9 [( U# Z5 l+ s8 |% U$ L
}) f# `! J" s. c$ C: s
return sel;" P# j! z) m6 [; [+ z
}3 \2 s* I W+ i$ ~1 T7 F% \
3 I0 ^& m/ J6 ^( E9 A2 W
public static Selector getSelector(Object obj, String method) {
1 r3 [( i* [# e0 r5 J Selector sel;/ I; M5 [ d- _
try {
& c6 w2 k9 \6 X sel = new Selector(obj.getClass(), method, false);3 h& v% }% s$ U$ y+ j8 V
} catch (Exception e) {+ {% W- Y5 u1 @5 ?% P, A7 t
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
4 u4 z' w2 r# W, t + (obj.getClass()).getName() + ".");4 Y; z: q& w4 W8 G
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());% D- d* [5 ^8 X) x0 Y
System.err.println("The process will be terminated.");
4 y4 ~/ J! L3 u e System.exit(1);
1 K5 ]! _3 J4 d" p/ U' }8 n return null;1 S6 T- E) \( F" E6 I) L+ b
}3 y6 v' e! E+ l% b
return sel;& S: Z/ f. C1 |/ u
}
8 t$ s! O, ^' }9 G1 X' l} |