import swarm.Selector;
& G* R+ X+ z V9 O Y% X9 B V j8 o; o& x2 Y$ X' y1 p
public class SwarmUtils {
3 T! c5 |2 c+ W3 } o- r, y; ?9 V public static Selector getSelector(String name, String method) {
8 p/ V) X5 Y) \: q/ H, h# ? l Selector sel;' ?6 u5 T( ]: z( e! C9 p# n/ \
try {
7 L( E/ N! g% T k* _ sel = new Selector(Class.forName(name), method, false);4 w( _$ S6 K+ Q; o. h. m5 H
} catch (Exception e) {/ f, J5 ?7 x) _3 V* b" y( w# v* Z
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");" f& V% K$ T" h/ o
System.err.println(name + "." + method + " returns " + e.getMessage());. z2 }0 e* J: D7 T
System.err.println("The process will be terminated.");
) p' B; r( A' G; \ A) X System.exit(1);
9 R! i+ E# a. Z! c; n return null;' q# ^; A. q1 I8 S5 J8 r
}
, p* h. Z* a4 N) G' L$ k& H1 I return sel;
) U+ U) o( U ~" r }( m4 b1 e6 I8 H% E3 d9 D
0 n7 c: V7 x! O2 k6 F
public static Selector getSelector(Object obj, String method) {
- P4 w8 ^& E) i7 V2 R Selector sel;7 O F$ ~! ]! a) T
try {
' ]. v3 K( v) u6 }% u0 K% ~5 @; i sel = new Selector(obj.getClass(), method, false);/ h# {- ~+ m1 ?7 b' d, o0 r& Q% r/ S
} catch (Exception e) {
/ a+ d1 h9 Z' B9 N r9 J( t System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
+ P9 Z% W5 s+ ^* u* [ + (obj.getClass()).getName() + ".");( d* t7 g1 r" y- Q8 w/ P, a
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());* V2 @1 V& c) V' }5 q1 i! D
System.err.println("The process will be terminated.");% ^2 q- {- F1 z; ?& M4 l
System.exit(1);' ?$ N' U, k/ z% u2 Z& a
return null;
7 o* }4 T# ]) p; G/ [! k }
) n. x. \: Q( b3 r* Q3 N return sel;& S' q+ I: ^) q6 N7 t0 g
}0 r- m) X0 l* _ i& H2 T' _
} |