import swarm.Selector;2 b+ n, t% i( E5 \& W5 t
2 ~' A* i# b% M: w3 Npublic class SwarmUtils {
+ ^3 A& b% Y! T' k6 ~ o public static Selector getSelector(String name, String method) {1 B: X8 m" a( Q6 d* d8 K/ N+ z# E- n
Selector sel;
- t4 C- g8 e8 ~ try {
7 y" a. @( D7 j* u sel = new Selector(Class.forName(name), method, false);
/ q# G1 k9 f( j s% t3 \( z } catch (Exception e) {
! ]' ]+ F6 p1 _6 {( i9 [) G System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
; V, s8 v: c" I# G System.err.println(name + "." + method + " returns " + e.getMessage());
1 k. T: S$ E% d, c2 A System.err.println("The process will be terminated.");) x' z1 o8 ?6 l- p" i3 l$ {
System.exit(1);
1 z6 r- V9 t# x return null;
& ^, p. J" J9 H+ v; _ }
' d4 \3 t* g" b' U+ i return sel;5 H7 w2 ^+ Y) d
}! V! |) e% J H' A) h6 ?5 d: \
* ^* v" M3 Y" ]7 s, a7 r2 K public static Selector getSelector(Object obj, String method) {2 Q+ T5 D) r) j' T ?
Selector sel;
2 Q2 y7 H+ M6 C, S try {' e2 B% I( X$ v: E/ |7 `
sel = new Selector(obj.getClass(), method, false);
- R7 O* z5 R/ z3 _3 x! N q5 | } catch (Exception e) {
) j# n0 j! B* b! ~ System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
8 }$ g. S) J1 ^$ z + (obj.getClass()).getName() + ".");$ D& ~3 r3 k* C" [
System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());" F" y8 y5 x3 v6 b/ {3 Z- N
System.err.println("The process will be terminated.");
2 w* C! ~; B' T2 }$ G! p System.exit(1);
2 _" h$ o7 |) i* @ return null;
2 [5 c2 P9 q8 L; D }5 q# m* { i3 d
return sel;1 W# H- y0 ]; @. D# h
}4 d0 } r6 y1 k6 b g$ J
} |