import swarm.Selector;
7 U' N4 o; H- Q) O$ k0 M( Z: A
2 D3 j# _2 I' I ypublic class SwarmUtils { y& W, m$ Q; J) B3 }) \
public static Selector getSelector(String name, String method) {
& }; H& Z2 J/ C, a7 c Selector sel;
! e' T9 D! l2 d& h+ R* A try {
7 N5 x5 \* T+ m- `) Y sel = new Selector(Class.forName(name), method, false);- t# [% |- b8 k2 r9 y% I3 W
} catch (Exception e) {
% s& K! R6 W8 ~. C System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
# g: m% O3 b* p# K7 Y) o* f System.err.println(name + "." + method + " returns " + e.getMessage());
- I( y8 C1 ~4 G* S- P& a6 A/ D% A System.err.println("The process will be terminated.");
8 c9 o$ D- H# a1 U D System.exit(1);
: N6 @% d6 V0 a4 g: ^ return null;
% B- @! }! H- V4 v5 o' U- x# x# @* @ }
' k1 {( ?6 ^0 P. a+ \ return sel;" P; U8 F" a9 G6 F( P! l
}
! ^ T, Z9 N Y/ r4 T+ H2 l' z5 e& w
public static Selector getSelector(Object obj, String method) {6 I( \6 T) W- k( J/ ]
Selector sel;
$ x F9 }* {' Y+ Y try {) ~# d7 n' b2 O1 ?/ _; L$ d& I
sel = new Selector(obj.getClass(), method, false);
: D& g9 g# O6 \, ]6 @! L0 N } catch (Exception e) {
+ d0 x5 ^0 ^! _- k2 w System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
) z% w. c+ v0 u7 k8 H + (obj.getClass()).getName() + ".");2 z( X8 W7 s+ j$ Q+ g3 w
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());2 Q, u5 X0 b# ]. i+ W Q$ X
System.err.println("The process will be terminated.");
0 M1 [/ D d4 B. q: c! W System.exit(1);2 ~" w+ Y9 }6 Z z$ G
return null;
, ]) I) h- C+ |+ T" d' F& N }
/ Y( E6 B# n' l return sel;5 w( w& q9 n( I9 k
}3 K0 {6 r8 y' d. u ?( Z
} |