import swarm.Selector;
& ^" _6 {9 b" w$ N* B$ d, m g6 B) r
public class SwarmUtils {- [/ s& n" M% x U' r, [9 T6 d
public static Selector getSelector(String name, String method) {
5 F; m5 U/ b! G% B9 n$ O Selector sel;( [7 j- R5 B; R; A0 I3 c- s' W# b' P
try {
! N1 {4 n# e4 u; I% _; F! E sel = new Selector(Class.forName(name), method, false);, S- b6 O' T/ @- X) I; E, r8 t
} catch (Exception e) {
d# b h! f F9 S7 c( ^% Q( ] System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
! B4 N9 G5 x& m, L( {5 ]# ` i System.err.println(name + "." + method + " returns " + e.getMessage());3 x. \( [% {( D. G2 Y" G
System.err.println("The process will be terminated.");* @$ `' b6 V& q# l* a0 q
System.exit(1);
- ^3 S( { b' g; ^7 q7 f return null;8 ?2 g2 f5 E% k0 j: T, A
}
2 @; d: m3 @* I8 Z" @2 D return sel;
+ j( X" E! I. n3 |/ G' H }. @' C' e/ [+ G
' O$ I" d+ @ r! t3 h7 m
public static Selector getSelector(Object obj, String method) {
; W) h; I/ X& ?" z Selector sel;
5 H& F5 O, \6 P8 _ try {- a0 y5 ^; x/ c& s1 Z( n6 h$ S
sel = new Selector(obj.getClass(), method, false);! f' [* D E! P4 Q8 u( C# Z7 T
} catch (Exception e) {
% |9 j: c; P5 a1 z# t System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " i+ K$ k$ @( T/ s( ?& `
+ (obj.getClass()).getName() + ".");
! R, X& }% f' t* W$ C% c0 M8 R System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
% [; a, v1 N0 N9 w/ o8 a System.err.println("The process will be terminated.");; s8 I+ g3 X' L [' @
System.exit(1);
( b/ P y/ O) B+ ~! D return null;
7 ]) ~, Z- U5 {7 i- T }3 J1 [9 S. [- O" C* |- F0 _
return sel;
5 @; t e) O2 s }+ ]) ?- ^* e! h) v) |# ~* }3 \! ?
} |