KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgroups > tests > adapt > JGroupsTester


1 package org.jgroups.tests.adapt;
2
3 import org.jgroups.*;
4
5
6
7 /** Javagroups version used was 2.0.3. Recompiled and tested again with 2.0.6.
8  * JGroupsTester:
9  * 1. Instantiates a JChannel object and joins the group.
10  * Partition properties conf. is the same as in the JBoss
11  * default configuration except for min_wait_time parameter
12  * that causes the following error:
13  * UNICAST.setProperties():
14  * these properties are not recognized:
15  * -- listing properties --
16  * min_wait_time=2000
17  * 2. Starts receiving until it receives a view change message
18  * with the expected number of members.
19  * 3. Starts the receiver thread and if(sender), the sender thread.
20  * @author Milcan Prica (prica@deei.units.it)
21  * @author Bela Ban (belaban@yahoo.com)
22  */

23 public class JGroupsTester {
24
25     private String JavaDoc props="UDP(mcast_recv_buf_size=64000;mcast_send_buf_size=32000;mcast_port=45566;use_packet_handler=true;ucast_recv_buf_size=64000;mcast_addr=228.8.8.8;loopback=true;ucast_send_buf_size=32000;ip_ttl=32):AUTOCONF:PING(timeout=2000;num_initial_members=3):MERGE2(max_interval=10000;min_interval=5000):FD(timeout=2000;max_tries=3;shun=true):VERIFY_SUSPECT(timeout=1500):pbcast.NAKACK(max_xmit_size=8192;gc_lag=50;retransmit_timeout=300,600,1200,2400,4800):UNICAST(timeout=300,600,1200,2400,3600):pbcast.STABLE(stability_delay=1000;desired_avg_gossip=5000;max_bytes=250000):pbcast.GMS(print_local_addr=true;join_timeout=3000;join_retry_timeout=2000;shun=true):FC(max_credits=2000000;down_thread=false;direct_blocking=true;min_credits=52000):FRAG(frag_size=8192;down_thread=false;up_thread=true)";
26
27
28     private JChannel channel;
29     private View view;
30     private String JavaDoc myGrpName="myGroup";
31     private boolean sender;
32     private int msg_size;
33     private int grpMembers;
34     private int num_senders;
35     private long log_interval=1000;
36     private int num_msgs=1000;
37
38
39     public JGroupsTester(boolean snd, int num_msgs,
40                          int msg_size, int gm, int ns, String JavaDoc props, long log_interval) {
41         sender=snd;
42         this.num_msgs=num_msgs;
43         this.msg_size=msg_size;
44         grpMembers=gm;
45         num_senders=ns;
46         if(props != null)
47             this.props=props;
48         this.log_interval=log_interval;
49
50         System.out.println("props=" + this.props);
51     }
52
53     public void initialize() {
54
55         try {
56             channel=new JChannel(props);
57             // Debugger d=new Debugger(channel, false);
58
// d.start();
59
channel.connect(myGrpName);
60         }
61         catch(ChannelException e) {
62             e.printStackTrace();
63         }
64
65         boolean loop=true;
66         while(loop) {
67             try {
68                 view=(View)channel.receive(0);
69                 System.out.println("-- view: " + view.getMembers());
70                 if(view.size() >= grpMembers) {
71                     loop=false;
72                     System.out.println(
73                             "Everyone joined, ready to begin test...");
74                 }
75             }
76             catch(ClassCastException JavaDoc e) {
77                 continue;
78             }
79             catch(ChannelNotConnectedException e) {
80                 e.printStackTrace();
81             }
82             catch(ChannelClosedException e) {
83                 e.printStackTrace();
84             }
85             catch(TimeoutException e) {
86                 e.printStackTrace();
87             }
88
89         }
90
91         new ReceiverThread(channel, num_msgs,
92                 msg_size, num_senders, log_interval).start();
93         if(sender) {
94             new SenderThread(channel, num_msgs, msg_size, log_interval).start();
95         }
96     }
97 }
98
Popular Tags