1 3 package org.jgroups.demos; 4 5 6 import org.jgroups.*; 7 import org.jgroups.blocks.PullPushAdapter; 8 import org.jgroups.util.Util; 9 10 import java.util.HashMap ; 11 12 13 17 public class ViewDemo implements MembershipListener { 18 private Channel channel; 19 20 21 public void viewAccepted(View new_view) { 22 System.out.println("** New view: " + new_view); 23 } 25 26 27 30 public void suspect(Address suspected_mbr) { 31 System.out.println("Suspected(" + suspected_mbr + ')'); 32 } 33 34 35 38 public void block() { 39 40 } 41 42 43 public void start(String props, boolean use_additional_data) throws Exception { 44 45 channel=new JChannel(props); 46 channel.setOpt(Channel.AUTO_RECONNECT, Boolean.TRUE); 47 48 if(use_additional_data) { 49 HashMap m=new HashMap (); 50 m.put("additional_data", "bela".getBytes()); 51 channel.down(new Event(Event.CONFIG, m)); 52 } 53 54 channel.connect("ViewDemo"); 55 channel.setOpt(Channel.VIEW, Boolean.TRUE); 56 new PullPushAdapter(channel, this); 57 58 while(true) { 59 Util.sleep(10000); 60 } 61 } 62 63 64 public static void main(String args[]) { 65 ViewDemo t=new ViewDemo(); 66 boolean use_additional_data=false; 67 String props="UDP(mcast_addr=224.0.0.35;mcast_port=45566;ip_ttl=32;" + 68 "mcast_send_buf_size=150000;mcast_recv_buf_size=80000):" + 69 "PING(timeout=2000;num_initial_members=3):" + 70 "MERGE2(min_interval=5000;max_interval=10000):" + 71 "FD_SOCK:" + 72 "VERIFY_SUSPECT(timeout=1500):" + 73 "pbcast.NAKACK(gc_lag=50;retransmit_timeout=300,600,1200,2400,4800):" + 74 "UNICAST(timeout=600,1200,2400):" + 75 "pbcast.STABLE(desired_avg_gossip=20000):" + 76 "FRAG(frag_size=4096;down_thread=false;up_thread=false):" + 77 "pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;" + 78 "shun=false;print_local_addr=true)"; 79 80 81 82 92 93 94 for(int i=0; i < args.length; i++) { 95 if("-help".equals(args[i])) { 96 help(); 97 return; 98 } 99 if("-props".equals(args[i])) { 100 props=args[++i]; 101 continue; 102 } 103 if("-use_additional_data".equals(args[i])) { 104 use_additional_data=new Boolean (args[++i]).booleanValue(); 105 continue; 106 } 107 help(); 108 return; 109 } 110 111 try { 112 t.start(props, use_additional_data); 113 } 114 catch(Exception e) { 115 System.err.println(e); 116 } 117 } 118 119 static void help() { 120 System.out.println("ViewDemo [-props <properties>] [-help] [-use_additional_data <flag>]"); 121 } 122 123 } 124 | Popular Tags |