import swarm.Selector;# [' d# y$ `! r$ U) v. q
1 g" e# |3 I, n+ x
public class SwarmUtils {
1 o$ D% [2 c- S public static Selector getSelector(String name, String method) {6 h9 T/ V, D9 W ~. U% \8 A+ S3 V
Selector sel;
2 L5 @& c* h) H9 Y$ ^ try {
. ]8 L7 J2 S4 y# f0 P& [ sel = new Selector(Class.forName(name), method, false);! b3 r4 j1 D2 `- H' W0 i: Q
} catch (Exception e) {
$ V @' ?. ]% i; {, y6 z System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");- D; i6 g2 k" x2 s9 W5 a/ V0 b7 w
System.err.println(name + "." + method + " returns " + e.getMessage());
- d: |" b5 w' ?; I& R9 K5 G Y' B3 f System.err.println("The process will be terminated.");- [. M# X2 f! c& N* Z" V
System.exit(1);
2 _+ k. _+ F4 h9 n return null;7 ^! q E( h) `$ [/ h
}, _# z& Q8 }1 p: A6 H8 }
return sel;# P: |- g- J: q9 M7 c
}2 B, X- A" \& N8 l' j9 @ l
5 ~& E3 K; P8 H+ f9 P0 ` b
public static Selector getSelector(Object obj, String method) {. O: M1 W6 f9 q* {
Selector sel;
^4 o. U% x. Q% x; d5 v- y& } try {
- B4 B5 R$ F/ q8 D- t, U2 J7 ~6 X sel = new Selector(obj.getClass(), method, false);
+ E2 J3 a! Z# C9 Y } catch (Exception e) {5 u' [) F9 \- x; i# n3 g( g; z/ f
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
8 Y! S" J( \! @5 _4 Y + (obj.getClass()).getName() + ".");
2 L( I4 Q$ a5 t5 O7 Z7 a9 i9 d1 f System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());% N' r _3 h+ R; r" G
System.err.println("The process will be terminated.");
2 N8 Z( S7 x& P System.exit(1);
4 @! K6 R. y: W* i' n u! U return null;
, m9 Q1 F% m: F. M }+ D, n/ `/ ?/ _6 J: @* J0 x( N
return sel;, w, P5 S. o: t5 K* P8 e! ^
}* P8 R9 _& Y- s6 s8 ?5 p8 Q
} |