import swarm.Selector;
: G: c, R; n! a
7 w; _" ?3 m8 Dpublic class SwarmUtils { |1 R1 H" ^7 L
public static Selector getSelector(String name, String method) {3 m# J6 x* n2 n7 j1 |
Selector sel;
$ c% `! @1 N, B# Q+ f" H3 _ try {
; i8 b% g) ^) T sel = new Selector(Class.forName(name), method, false);, g1 c9 Y7 y1 I; q" k
} catch (Exception e) {
" H) V3 @6 J: ]# R1 H# F System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
) q* G6 q& M) v0 V0 U$ J System.err.println(name + "." + method + " returns " + e.getMessage());5 o" n" z. q$ z ]+ x
System.err.println("The process will be terminated.");
% c- {; k2 ?% E' q- O System.exit(1);
( w" f! Z) w4 c | return null;
1 K7 Z0 F# R2 ^/ X }$ P3 y. `% ^& L# F5 h
return sel;
/ Z W6 I8 R/ @) F }
p; y/ p9 T1 t& a
5 L. x9 d8 b0 D- m* U" w# i' |2 r public static Selector getSelector(Object obj, String method) {8 e3 |) _& L5 J( `9 v- W
Selector sel;& u2 h. U- R7 p X: e# e5 T1 B" P
try {4 d" f- V* }% f2 L$ \0 ]! k$ Q
sel = new Selector(obj.getClass(), method, false);- y. [; M/ Z/ L/ w f. {) D# O4 b
} catch (Exception e) {
. v* G$ R* v+ l. v ~ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
8 e* ]& s: h2 Z6 l. M" m6 `5 O + (obj.getClass()).getName() + ".");
' D/ g. F1 Y( B* j: d System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());! I' j/ }: g% i5 D+ L( [
System.err.println("The process will be terminated.");
+ C+ O9 D3 @" N: y! K$ q System.exit(1);
& l' y) p. K- r, C# y return null;1 y! ^& N1 k W' g
}
/ O% s/ G+ z. {# w. h2 H X return sel;
+ W& q! M4 `$ X1 t6 r }
- h& K4 Q& k8 I3 U} |