import swarm.Selector;
- t2 ?% Z; x, o2 \5 I$ h! t; ]5 o1 v; `* {/ \ \9 e' u
public class SwarmUtils {* y+ t N! Z& @) i2 P
public static Selector getSelector(String name, String method) {9 R% R- s) t9 {( }! `7 |
Selector sel;9 V& N; L, z& X q, ^% O: A4 S
try {
* b* E; c9 v: U, I- D9 B! K sel = new Selector(Class.forName(name), method, false);
7 a, d8 z$ K( `9 ~8 a } catch (Exception e) {
% Z& _; H7 S$ h8 ^ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");: r3 D0 @$ ^6 l5 T# B' ], E$ w2 G
System.err.println(name + "." + method + " returns " + e.getMessage());, C6 O |2 _/ d7 f. K) m( M
System.err.println("The process will be terminated.");
* ?" j( T! L; u System.exit(1);9 z" d# [- ~2 ]
return null;
4 C, }- }& }, U4 m }
8 J4 a. ^8 H) l s return sel;
, k( ^- K5 e+ S2 i }
; P6 u2 O+ y! L# R7 S
' A, e0 a4 G5 n6 A0 C, J. d public static Selector getSelector(Object obj, String method) {/ `; H2 I/ g: `
Selector sel;
. X( {: `% N; ~ q ]# B+ p try {, {! _3 E; ^# ]
sel = new Selector(obj.getClass(), method, false);
( C0 f9 Z8 J2 U, j" t } catch (Exception e) {
3 |, L. Z$ {+ k8 K2 X8 S( i1 h! F System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
& y( L( j C0 y& y + (obj.getClass()).getName() + ".");# [# n1 `; m6 i* `. L
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
/ U) ?: o, R; W4 ~2 S$ b System.err.println("The process will be terminated.");9 p% }9 Y. e# k5 Z
System.exit(1);
: ~ v4 W z; B$ t2 j# i" t return null;
* U, m+ s/ H- w! M* q) P }
/ D4 B7 _3 B( w$ H4 t- ^ return sel;
4 z* c: F' P, H3 @* M }
8 E; z, Q8 |' q2 o} |