import swarm.Selector;! {" D7 U1 I5 }5 g: U$ s8 M- f
H0 a% k7 M" b5 J @. K
public class SwarmUtils {/ L: y$ B# i1 W7 W: {# R Q
public static Selector getSelector(String name, String method) {
7 k6 U4 O2 l6 p% R% T+ p+ j Selector sel;
1 d: O2 X7 G, N8 a u3 T: p3 S8 Z try {
) |( w+ }6 o. s4 O/ H5 t# o sel = new Selector(Class.forName(name), method, false);
, N# }9 ]9 Y: S- o3 x) K3 g- ^' ^ } catch (Exception e) {
3 K! ^+ U+ T' i( \8 O* h9 ]/ Y7 n System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
( i7 x! ?! r, S3 e System.err.println(name + "." + method + " returns " + e.getMessage());
/ C5 Z) E/ E, v4 l( {0 I& L( Y System.err.println("The process will be terminated.");
( a s+ e6 R$ m2 d9 g" b System.exit(1);
* a3 {4 _, W: Y( M/ h return null;
/ b& T$ b- `, k/ ]- p3 } d- l% F }7 Y% L$ W& a3 X$ g3 S. _9 s
return sel;6 A/ E( B; Z; L: x& T8 f, m
} C- _" R3 I! N( n# {! P
1 a7 |* B$ J1 c* _ s* U& Z public static Selector getSelector(Object obj, String method) {
3 h9 B* s9 h; B. s! | Selector sel;
) G# i. _% X/ x/ I. m try {
* L% j% Q a( C# Z sel = new Selector(obj.getClass(), method, false);7 h. x/ u" F7 u# O8 O
} catch (Exception e) {8 X/ i# \9 n+ }0 j
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "% J" ]* F9 Z+ }5 I* `
+ (obj.getClass()).getName() + ".");4 T, U4 s! Q; V" L( A) P8 W
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
, @. P ?5 [+ K( `0 |" b. i3 F System.err.println("The process will be terminated.");
8 B$ b* o" u# t2 r' w* \# f System.exit(1);6 J ^+ w: b# [. J( J) |
return null;
7 c5 F% T% S( p# ~ }8 |( I( q- g+ T+ J6 ^0 ]
return sel;0 Z! D6 j! U6 x/ i: _. ~! S
} l. A1 F) o0 Y' [. e8 D
} |