import swarm.Selector;
. `1 E, c8 N8 \/ N
+ q% t3 c# K k4 K3 J% J; H: C4 ^public class SwarmUtils {" R+ I+ v; a- _& p
public static Selector getSelector(String name, String method) {
- s6 c6 K2 y$ p, [ Selector sel;
' A0 u, V0 l* l3 `- O& b try {& ~: K8 v9 c0 I0 G! C
sel = new Selector(Class.forName(name), method, false);2 j: ]; o" M" L$ z" a
} catch (Exception e) {
2 D% v8 _! k$ ?/ h2 Z System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");& x P- y; K3 a% G0 _
System.err.println(name + "." + method + " returns " + e.getMessage());
5 K6 R' F1 ]7 H, V- y) c# c System.err.println("The process will be terminated.");
' q4 ]: Y& D. W H, z" I System.exit(1);
% @) j8 Z, M \2 j# y% A9 t0 p return null;. _( [- ~9 n2 R- h" @& F/ o+ i
}
8 ]* \8 h; O; [ return sel;( j. o" p5 o9 Q, i( T0 i- ?8 o
}
# w7 w( f, o8 Y5 G4 F# U2 N; q" h& l* M1 S
public static Selector getSelector(Object obj, String method) {
7 ~$ E/ u3 K7 [9 o& I' X+ ?4 j Selector sel;
- s L5 V1 d, i try {
8 w, A0 z7 K+ `7 `8 S. |* y sel = new Selector(obj.getClass(), method, false);2 F: M6 l$ u H! b) ~
} catch (Exception e) {
0 T" d$ a7 ?% Q3 I D System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
5 Q4 f( R! ^% n# z + (obj.getClass()).getName() + ".");
5 ^* X( u* _2 ]* r# v: b System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());/ O0 H; ?" i; X! O) A. i S5 O3 s, r
System.err.println("The process will be terminated.");
( h9 [' I& H$ R+ }- L System.exit(1);) ?3 ^ [* s# \4 D4 L. `
return null;0 @. U+ X1 x5 X( L* u6 r; m
}; w( F6 [# K' n% J& s% Y( j5 H
return sel;
* ?' ]; F: j$ V9 y) I) y& J }
2 r/ O7 ~" P0 W/ Y} |