import swarm.Selector;, Q& A) f, r/ q7 U% n
- s/ C/ _, ~) P7 Upublic class SwarmUtils {7 k, w+ B4 y" T
public static Selector getSelector(String name, String method) {
7 N+ W- R6 z) U Selector sel;7 ~; a# \4 y ]# c& T; q0 Q
try {
0 n5 t- c) l# c! A* Z/ a6 ^+ T sel = new Selector(Class.forName(name), method, false);
( X" O- g4 n. N: B* |6 A } catch (Exception e) {
4 V% @; Y$ T" u/ k; g4 g! c System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
4 M: c/ r9 k; h- ?/ X, [+ O System.err.println(name + "." + method + " returns " + e.getMessage());
3 i7 H- Z" l* Z$ P( v" R# I( e) v+ d System.err.println("The process will be terminated.");
) x% }& L5 z3 w) D. q) Q System.exit(1);
* J/ k, l) ]1 c5 ` return null;5 k- L" ~ t6 a8 \3 B: N
}+ G- V0 U- A9 H/ N, z
return sel;/ d! u; p. @4 R2 X: ~; F
}
" {& |1 X! Y9 Z/ K+ o' m& ^$ K- ~9 [. g
public static Selector getSelector(Object obj, String method) {7 W/ |* [0 ?7 A
Selector sel;
/ t( G5 I) x/ [/ }% R try {5 G3 v2 B3 s3 x
sel = new Selector(obj.getClass(), method, false);
2 w5 {" x3 y1 D3 Q$ D } catch (Exception e) {+ P* C( E5 C2 u
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
0 Z, n2 `5 u& K* T s + (obj.getClass()).getName() + ".");
4 R4 |( g/ y( V) U& _ System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());5 w$ F5 A* Q# u# t" s* }4 J
System.err.println("The process will be terminated.");- }% `% M3 {6 J# S
System.exit(1);6 J, M5 C+ o1 ^/ o; m, P7 E" }
return null;
9 \7 ^- `6 R6 W/ o. f7 s' ]6 {- `& N }7 h* [* [9 r, j+ F6 g' X) u# g
return sel;
/ ], j2 G- g8 c6 x6 h* m }
' f; w8 f0 t5 I* P/ v A; g8 s; ?. ~} |