import swarm.Selector;. P( V0 i) W: z' b1 S2 D' P
, r7 M% s; ?' p0 u5 Fpublic class SwarmUtils {
% b) ]/ Y5 Z' K5 ?& H public static Selector getSelector(String name, String method) {- @6 y I9 D: L% y4 D, D9 d7 D; j
Selector sel;. W3 h, U, E) d$ J6 ^! X+ l% P8 H
try {4 A( a. H: B+ D$ @8 H. a' m1 Q
sel = new Selector(Class.forName(name), method, false);% {, I6 v/ e9 w
} catch (Exception e) {, t* m: S8 S7 L4 j! C- m
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
: }$ [# F f3 E, N System.err.println(name + "." + method + " returns " + e.getMessage());
! F; V) y. h K- ^0 @) l9 G System.err.println("The process will be terminated."); [0 D0 n$ [7 h1 m% [2 a9 C7 b8 V* D
System.exit(1);
0 X: ?9 W3 F4 Q/ K6 R" ^ return null;/ G7 _' a" a# h! F
}
3 I+ ~, }/ k# q, x" F& S5 K! w* E return sel;
, r/ G* x$ A/ r; k1 E }
: B8 j6 Y$ g; `
* ~6 y W; f" |* Z4 Y9 ?+ [ public static Selector getSelector(Object obj, String method) {9 r0 ?: @* H; }, D! r% Z
Selector sel;
c6 [5 D3 w) s, C1 X f try {
7 x# `5 G: z2 N& ~ p) i sel = new Selector(obj.getClass(), method, false);
7 ?$ Y# `$ _4 G/ n: \1 U: Q8 l# q u* a } catch (Exception e) {, U9 C' L' S! Y% `% n
System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "5 k) q- d( n9 o: X( b; Q. _* ]- h
+ (obj.getClass()).getName() + ".");
5 l0 U! l: Y4 j System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());: `* d0 P6 N# [9 U5 t5 g0 G
System.err.println("The process will be terminated.");
0 l% f+ d; k1 `; P; @- P System.exit(1);
) }* S0 I4 ?; M1 h, y3 S1 ], C return null;
6 t2 J$ t4 A. |# K, E. D0 l }
! q* s7 ]% q; \% e8 q return sel;$ Y( _5 z& l j( q4 M2 S
}2 O1 p7 v2 g" x/ o X: Y
} |