KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jgroups.tests;
2
3 import org.jgroups.*;
4 import org.jgroups.blocks.RpcDispatcher;
5 /*
6  * @author Bob Stevenson - HAMMER
7  * @author Ananda Bollu - FLOW_CONTROL
8  */

9 public class HammerListener implements ChannelListener, MembershipListener {
10     private static JChannel channel = null;
11     private static int SEND_COUNT= 100000;
12     private static int counter = 0;
13     private static long startTime = 0;
14     static {
15         initCommChannel();
16     }
17
18     public void channelConnected(Channel ch)
19     {
20     }
21
22     public void channelDisconnected(Channel ch)
23     {
24     }
25
26     public void channelClosed(Channel ch)
27     {
28     }
29     public void channelShunned()
30     {
31     }
32     public void channelReconnected(Address addr)
33     {
34     }
35
36     /**
37      * this class initializes the communication channel to the broadcast
38      * group defined, this is a two-way communication channel with full error-recovery
39      * auto-resend capabilities and group auto-discovery built in it uses udp multi-cast, where multiple users can
40      * all listen for broadcasts on the same port Everyone that's interested in these messages, just joins the group
41      * and they will receive these messages
42      */

43     static private void initCommChannel() {
44         // preload all the static ip's, we only do this once, of course
45
String JavaDoc props = "UDP(mcast_addr=228.1.2.3;mcast_port=45566;ip_ttl=32;"+
46                 "ucast_recv_buf_size=16000;ucast_send_buf_size=16000;" +
47                 "mcast_send_buf_size=32000;mcast_recv_buf_size=64000;loopback=true):" +
48                 "PING(timeout=2000;num_initial_members=3):" +
49                 "MERGE2(min_interval=5000;max_interval=10000):" + "FD:" +
50                 "VERIFY_SUSPECT(timeout=1500):" + "pbcast.STABLE(desired_avg_gossip=10000):" +
51                 "pbcast.NAKACK(gc_lag=50;retransmit_timeout=1000,1500,2000,3000;max_xmit_size=8192):" +
52                 "UNICAST(timeout=1000,1500,2000,3000):" +
53                 "FLOW_CONTROL(window_size=1000;fwd_mrgn=200;rttweight=0.125;reduction=0.75;expansion=1.25):"+
54                 "FRAG(frag_size=8192;down_thread=false;up_thread=false):" +
55                 "pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;shun=false;print_local_addr=true):" +
56                 "pbcast.STATE_TRANSFER";
57         try {
58             channel = new JChannel(props);
59             HammerListener listener = new HammerListener();
60             new RpcDispatcher(channel, null, listener, listener);
61             channel.connect("BOSGroup");
62
63         }
64         catch (org.jgroups.ChannelException ce) {
65             System.err.println("Channel Error"+ ce);
66         }
67     }
68
69     static public int printnum(Integer JavaDoc number) throws Exception JavaDoc {
70     counter ++;
71     if(counter >=SEND_COUNT)
72         {
73             long endTime = System.currentTimeMillis();
74             System.out.println("Messages received "+counter);
75             System.out.println("Messages succesfully trasmitted in "+(endTime-startTime));
76             System.exit(0);
77         }
78     return number.intValue() * 2;
79     }
80
81     public void viewAccepted(View new_view) {
82         System.out.println("Accepted view (" + new_view.size() + new_view.getMembers() + ')');
83     }
84
85     public void suspect(Address suspected_mbr) {
86         System.out.println("-- suspected " + suspected_mbr);
87     }
88
89     public void block() {
90         ;
91     }
92
93     /** creates a new commandlistener and kick start's the thread */
94     public HammerListener() {
95         System.out.println("HammerListener loaded");
96     }
97
98     static public void main(String JavaDoc[] args) {
99         startTime = System.currentTimeMillis();
100         System.out.println("startTime "+startTime);
101         for(int i = 0;i<SEND_COUNT;i++) {
102             HammerSender.executeDistributedCommand ();
103         }
104     }
105
106     /** lets' clean up when we are done */
107     protected void finalizer() {
108         channel.disconnect();
109         channel.close();
110     }
111
112 }
113
114
Popular Tags