import swarm.Selector;
9 a1 {8 B8 ^$ H9 l- C6 h- x& ]3 h& G4 R- t
public class SwarmUtils {
2 }% b3 b) U! L public static Selector getSelector(String name, String method) {
( X2 [1 N+ q4 A; b/ w6 D% K' S Selector sel;
7 [" J+ q ]& e/ `9 S! o( j0 a try {$ _7 h" ]/ R/ W/ z! P6 ^ @9 Y
sel = new Selector(Class.forName(name), method, false);
. z1 u" c2 J+ A& ]8 p } catch (Exception e) {
. g/ q9 ^9 j5 Y6 n& U System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
, {1 _: V% d! W8 m8 q System.err.println(name + "." + method + " returns " + e.getMessage());) o; X, A0 C+ l0 [' u; l
System.err.println("The process will be terminated.");
$ O1 r6 O E- H" H System.exit(1);
2 _$ i3 i2 }# V1 V" t return null;
( B+ S# N$ t: S; u8 m$ F& L* u }
7 P, R6 E2 ]+ O0 [7 M return sel;. i% H/ x4 g, l$ O
}
j2 E2 Q# e. f) F [5 l0 d: e& g/ I+ E# H# f$ T) e# D9 Q
public static Selector getSelector(Object obj, String method) {- }' ~& S) q$ E0 o& r$ }- S4 K2 b
Selector sel;
% X% x! |! E9 W. w try {
9 i {! P- w' Z, M8 q' B: \ sel = new Selector(obj.getClass(), method, false);. r) y1 e1 c5 _' M# D5 \
} catch (Exception e) {
. v1 d# b+ Z( [- M System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "+ ^% i* ]+ O( p
+ (obj.getClass()).getName() + ".");
( W9 r, f, S* H' m4 k- U System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
/ [3 K7 O! P) e# C- | X System.err.println("The process will be terminated.");2 U! j# P+ t! t( @
System.exit(1);, o& R( m$ E d* O Q
return null;. l5 ^7 B5 t0 [
}
# @. ]: l" A" } A4 U+ y- x& G return sel;/ G- N+ N6 a1 r y
}4 i# r; v [+ l# \0 H# }
} |