import swarm.Selector;9 |, J" O. E$ P2 _
; h7 Y4 ?3 D4 n* h. W* R
public class SwarmUtils {' V1 T. U# u k1 G# q2 \& }
public static Selector getSelector(String name, String method) {
3 `( J. Q' K$ {3 N1 ?! c. Z, Z Selector sel;6 Q6 p; x; h1 A7 g" A- [7 T
try {- M' O% F+ {4 k4 _! W. t- J0 x" i
sel = new Selector(Class.forName(name), method, false);7 D: i7 V5 {- L2 J6 }# O! a
} catch (Exception e) {* ]7 Z. j' I* V# H
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");0 R' a) ]& ^* @" K2 V
System.err.println(name + "." + method + " returns " + e.getMessage());0 F( g0 U8 ?" r/ S
System.err.println("The process will be terminated.");* n! e5 L1 @7 r7 L6 `1 w8 Z& ^0 G
System.exit(1);( o9 p' V! `& w2 Q" N
return null;1 P; `* [4 T9 J1 I- X* Z1 [" A
}; L; K2 W7 ?) {- ]6 ~* m
return sel;+ r- q+ i! a# P& s0 @' N; j
}
4 [0 e2 u. e$ c. z2 k3 B3 I' f$ d" u6 k! d, U
public static Selector getSelector(Object obj, String method) {: G5 ^" H4 u2 B) l. c
Selector sel;8 ~- y3 ]/ O3 K4 b
try {
. k. o; V" h3 b0 Y sel = new Selector(obj.getClass(), method, false);
. g. p# a$ A6 y7 e } catch (Exception e) {7 P& L7 D. {* I! h- K; L# v
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
) f" [7 f* @" V + (obj.getClass()).getName() + ".");2 o. q. k6 U) [9 {
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
1 T6 K6 p# c% M, S8 e) Q System.err.println("The process will be terminated.");
- z! t" I% t5 }3 A9 @# X" e System.exit(1);
1 }* H3 I' M& C# s return null;2 C5 R' Q) T I/ I6 \
}
1 w9 N- C4 t' Y; e2 g5 U return sel;4 }9 i5 h4 i& G
}+ d- o u* u1 A3 Y) ?2 Y
} |