01: package org.jgroups.tests;
02:
03: import org.jgroups.JChannel;
04: import org.jgroups.blocks.GroupRequest;
05: import org.jgroups.blocks.MethodCall;
06: import org.jgroups.blocks.RpcDispatcher;
07:
08: /*
09: * @author Bob Stevenson - HAMMER
10: * @author Ananda Bollu - FLOW_CONTROL
11: */
12: public class HammerSender {
13: private static JChannel channel = null;
14:
15: private static RpcDispatcher disp;
16:
17: private static String props = "UDP(mcast_addr=228.1.2.3;mcast_port=45566;ip_ttl=64;"
18: + "ucast_recv_buf_size=16000;ucast_send_buf_size=16000;"
19: + "mcast_send_buf_size=32000;mcast_recv_buf_size=64000;loopback=true):"
20: + "PING(timeout=2000;num_initial_members=3):"
21: + "MERGE2(min_interval=5000;max_interval=10000):"
22: + "FD:"
23: + "VERIFY_SUSPECT(timeout=1500):"
24: + "pbcast.STABLE(desired_avg_gossip=10000):"
25: + "pbcast.NAKACK(gc_lag=50;retransmit_timeout=1000,1500,2000,3000;max_xmit_size=8192):"
26: + "UNICAST(timeout=1000,1500,2000,3000):"
27: + "FLOW_CONTROL(window_size=1000;fwd_mrgn=200;rttweight=0.125;reduction=0.75;expansion=1.25):"
28: + "FRAG(frag_size=8192;down_thread=false;up_thread=false):"
29: + "pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;shun=false;print_local_addr=true):"
30: + "pbcast.STATE_TRANSFER";
31:
32: private static MethodCall printnumMethod = null;
33:
34: static {
35: initCommChannel();
36: loadMethods();
37: }
38:
39: private static void loadMethods() {
40: try {
41: java.lang.reflect.Method method = HammerListener.class
42: .getMethod("printnum",
43: new Class[] { Integer.class });
44: printnumMethod = new org.jgroups.blocks.MethodCall(method,
45: new Object[] { new Integer(2) });
46:
47: }
48:
49: catch (java.lang.NoSuchMethodException nsme) {
50: System.err.println("No Such method:" + nsme);
51: } catch (Exception e) {
52: System.err.println("Error:" + e);
53: }
54: }
55:
56: /**
57: * this class initializes the communication channel to the broadcast
58: * group defined, this is a two-way communication channel with full error-recovery
59: * auto-resend capabilities and group auto-discovery built in it uses udp multi-cast, where multiple users can
60: * all listen for broadcasts on the same port Everyone that's interested in these messages, just joins the group
61: * and they will receive these messages
62: */
63: static private void initCommChannel() {
64: // preload all the static ip's, we only do this once, of course
65:
66: try {
67: channel = new JChannel(props);
68: System.out.println(channel.getProtocolStack()
69: .printProtocolSpec(false));
70: disp = new RpcDispatcher(channel, null, null, null);
71: channel.connect("BOSGroup");
72: } catch (org.jgroups.ChannelException ce) {
73: System.err.println("Channel Error" + ce);
74: }
75: }
76:
77: /**
78: * executes a command across app-servers
79: * @param cmd the command to execute across boxes in an environment
80: */
81: public static void executeDistributedCommand() {
82:
83: disp.callRemoteMethods(null, printnumMethod,
84: GroupRequest.GET_NONE, 0);
85: }
86:
87: /**
88: * this method will close down the channel forcing out and data, and removing ourselves
89: * from further participation in the group
90: */
91: static void shutdown() {
92: //
93: disp.stop();
94: channel.close();
95: }
96: }
|