import swarm.Selector;6 T3 v r" d% f1 g
6 B8 @) K2 ] Y5 N: U7 ]public class SwarmUtils {. Q6 m5 W8 j n- U$ p
public static Selector getSelector(String name, String method) {6 z# P: ^0 Y* }, }
Selector sel;
m T) [4 h/ C/ k; d9 G try {
' m4 x3 Z9 h0 X: v( |0 c/ X sel = new Selector(Class.forName(name), method, false);( u! J" a& C5 Q' Z
} catch (Exception e) {! l: h# l o, L
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
# G9 d6 l( H2 S& K System.err.println(name + "." + method + " returns " + e.getMessage());
- p, }1 D- Z6 r: T9 m, w/ J System.err.println("The process will be terminated.");- l3 p; s+ ?0 ]* S# ]. G* y
System.exit(1);
0 k) G- M+ [8 P return null;
( G8 ^4 B { C) l+ | } {3 r1 J8 L+ _& Z" {$ l
return sel;
1 v$ q. R3 R( l2 t B% C }
- j& ^% L5 j- S* |) |6 _* {8 u3 T% O3 n7 p* P6 }% q6 e N
public static Selector getSelector(Object obj, String method) {
) y# K1 E* `' q! ^, C8 W$ J) ~3 Q Selector sel;
z. J; S' t; I/ V5 M- T" }4 M try {
4 y7 E# K5 x# p) w$ t sel = new Selector(obj.getClass(), method, false);
- O1 a& `. l! J1 X5 ?5 P( \ } catch (Exception e) {3 _2 g% b w4 X
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
4 ?: I- v ~& ~, X + (obj.getClass()).getName() + ".");, d2 A2 ?8 m, k4 @' j# t1 R d7 t
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
- E/ S- H# ?* D/ K) W System.err.println("The process will be terminated.");( w2 d5 {# w. g. i3 s2 j
System.exit(1);
, F6 m, F2 C3 {5 K2 C return null;0 t" F* t9 H: M
}: v' P7 ?; f" Y! x7 W2 p9 s
return sel;
/ w; ?% M9 b" `. k- }0 I }2 a: B: Z% y4 ~$ }* E8 t3 R
} |