import swarm.Selector;% V4 W9 g# X& C0 ?1 @$ B3 A
( j" T4 q; N# o+ ~1 F) w9 opublic class SwarmUtils {0 W0 E w# v- E& Y" F! A6 [! h
public static Selector getSelector(String name, String method) {
1 a5 Q& J# E. n, ]! K$ g$ a Selector sel;
5 z8 P( C k+ Y, s% z( w7 H3 G& B4 F try {
& [: F- Y) o& d. g2 {4 s sel = new Selector(Class.forName(name), method, false);: p' Y# _$ h; o9 K: Y# V
} catch (Exception e) {
5 H t1 h& y* t System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
# l" V# Y: o; z4 s: i3 H s System.err.println(name + "." + method + " returns " + e.getMessage());
; L- o6 z. c# L5 S System.err.println("The process will be terminated.");/ ?" z! y/ W& N" b& y% m8 G( Y
System.exit(1);
! e; Y6 B: [& N0 `1 R; x0 l# ~ return null;6 z7 x+ b; G7 ~
}
0 J; C) w' B* v+ C$ R return sel;9 w, u& h/ z- T9 u) p
}; w* V8 R7 x7 B( h1 s# s# U( y2 W i
1 u6 H1 _; A2 C/ h' {. T0 s public static Selector getSelector(Object obj, String method) {
3 B, L% [1 S9 J; G: g Selector sel;
' f- O3 j/ N, U; A6 U$ p try {
7 {+ ]" {* J1 d, u sel = new Selector(obj.getClass(), method, false);9 I3 T" E0 ^( ~4 ^6 K% M S& L
} catch (Exception e) {
3 }& V- d1 a3 d# g2 Z* K System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
! T9 c$ y- f- u5 s. s' O9 b- b& N + (obj.getClass()).getName() + ".");
( {3 m, U- u$ M C3 { System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());% Z8 v$ W0 G# x4 a& K( K2 Q
System.err.println("The process will be terminated.");! |4 G9 D) n+ N% x: j
System.exit(1);$ D" R7 ~3 q9 v V9 R8 F
return null;
; ]5 Y) g8 b' [" f }' `- H6 ~9 d8 c: j1 t
return sel;
5 V6 Y- c! g% }0 V# b: Q }0 v* D. j# @. U
} |