KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgroups > tests > HammerSender


1 package org.jgroups.tests;
2
3 import org.jgroups.JChannel;
4 import org.jgroups.blocks.GroupRequest;
5 import org.jgroups.blocks.MethodCall;
6 import org.jgroups.blocks.RpcDispatcher;
7
8 /*
9  * @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 JavaDoc 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):" + "FD:" +
22             "VERIFY_SUSPECT(timeout=1500):" + "pbcast.STABLE(desired_avg_gossip=10000):" +
23             "pbcast.NAKACK(gc_lag=50;retransmit_timeout=1000,1500,2000,3000;max_xmit_size=8192):" +
24             "UNICAST(timeout=1000,1500,2000,3000):" +
25             "FLOW_CONTROL(window_size=1000;fwd_mrgn=200;rttweight=0.125;reduction=0.75;expansion=1.25):"+
26             "FRAG(frag_size=8192;down_thread=false;up_thread=false):" +
27             "pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;shun=false;print_local_addr=true):" +
28             "pbcast.STATE_TRANSFER";
29
30     private static MethodCall printnumMethod = null;
31
32     static {
33         initCommChannel();
34         loadMethods();
35     }
36
37     private static void loadMethods()
38     {
39         try {
40             java.lang.reflect.Method JavaDoc method = HammerListener.class.getMethod("printnum",new Class JavaDoc[] { Integer JavaDoc.class });
41             printnumMethod = new org.jgroups.blocks.MethodCall( method, new Object JavaDoc[]{new Integer JavaDoc(2)});
42
43         }
44
45         catch(java.lang.NoSuchMethodException JavaDoc nsme)
46         {
47             System.err.println("No Such method:"+ nsme);
48         }
49         catch(Exception JavaDoc e)
50         {
51             System.err.println("Error:"+ e);
52         }
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().printProtocolSpec(false));
69             disp = new RpcDispatcher(channel, null, null, null);
70             channel.connect("BOSGroup");
71         }
72         catch (org.jgroups.ChannelException ce) {
73             System.err.println("Channel Error"+ ce);
74         }
75     }
76
77
78
79     /**
80      * executes a command across app-servers
81      * @param cmd the command to execute across boxes in an environment
82      */

83     public static void executeDistributedCommand() {
84
85         disp.callRemoteMethods(null, printnumMethod, GroupRequest.GET_NONE, 0);
86     }
87
88     /**
89      * this method will close down the channel forcing out and data, and removing ourselves
90      * from further participation in the group
91      */

92     static void shutdown() {
93         //
94
disp.stop();
95         channel.close();
96     }
97 }
98
99
Popular Tags