001: // $Id: ViewDemo.java,v 1.11 2006/03/27 08:34:24 belaban Exp $
002:
003: package org.jgroups.demos;
004:
005: import org.jgroups.*;
006: import org.jgroups.blocks.PullPushAdapter;
007: import org.jgroups.util.Util;
008:
009: import java.util.HashMap;
010:
011: /**
012: * Demos the reception of views using a PullPushAdapter. Just start a number of members, and kill them
013: * randomly. The view should always be correct.
014: */
015: public class ViewDemo implements MembershipListener {
016: private Channel channel;
017:
018: public void viewAccepted(View new_view) {
019: System.out.println("** New view: " + new_view);
020: // ", channel.getView()=" + channel.getView());
021: }
022:
023: /**
024: * Called when a member is suspected
025: */
026: public void suspect(Address suspected_mbr) {
027: System.out.println("Suspected(" + suspected_mbr + ')');
028: }
029:
030: /**
031: * Block sending and receiving of messages until ViewAccepted is called
032: */
033: public void block() {
034:
035: }
036:
037: public void start(String props, boolean use_additional_data)
038: throws Exception {
039:
040: channel = new JChannel(props);
041: channel.setOpt(Channel.AUTO_RECONNECT, Boolean.TRUE);
042:
043: if (use_additional_data) {
044: HashMap m = new HashMap();
045: m.put("additional_data", "bela".getBytes());
046: channel.down(new Event(Event.CONFIG, m));
047: }
048:
049: channel.connect("ViewDemo");
050: new PullPushAdapter(channel, this );
051:
052: while (true) {
053: Util.sleep(10000);
054: }
055: }
056:
057: public static void main(String args[]) {
058: ViewDemo t = new ViewDemo();
059: boolean use_additional_data = false;
060: String props = "UDP(mcast_addr=228.5.5.5;mcast_port=45566;ip_ttl=32;"
061: + "mcast_send_buf_size=150000;mcast_recv_buf_size=80000):"
062: + "PING(timeout=2000;num_initial_members=3):"
063: + "MERGE2(min_interval=5000;max_interval=10000):"
064: + "FD_SOCK:"
065: + "VERIFY_SUSPECT(timeout=1500):"
066: + "pbcast.NAKACK(gc_lag=50;retransmit_timeout=300,600,1200,2400,4800):"
067: + "UNICAST(timeout=600,1200,2400):"
068: + "pbcast.STABLE(desired_avg_gossip=20000):"
069: + "FRAG(frag_size=4096;down_thread=false;up_thread=false):"
070: + "pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;"
071: + "shun=false;print_local_addr=true)";
072:
073: /*
074: String props="TCP(start_port=7800):" +
075: "TCPPING(initial_hosts=66.87.163.92[7800];port_range=2;" +
076: "timeout=5000;num_initial_members=3;up_thread=true;down_thread=true):" +
077: "VERIFY_SUSPECT(timeout=1500):" +
078: "pbcast.STABLE(desired_avg_gossip=200000;down_thread=false;up_thread=false):"+
079: "pbcast.NAKACK(down_thread=true;up_thread=true;gc_lag=100;retransmit_timeout=3000):" +
080: "pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;shun=false;" +
081: "print_local_addr=true;down_thread=true;up_thread=true)";
082: */
083:
084: for (int i = 0; i < args.length; i++) {
085: if ("-help".equals(args[i])) {
086: help();
087: return;
088: }
089: if ("-props".equals(args[i])) {
090: props = args[++i];
091: continue;
092: }
093: if ("-use_additional_data".equals(args[i])) {
094: use_additional_data = new Boolean(args[++i])
095: .booleanValue();
096: continue;
097: }
098: help();
099: return;
100: }
101:
102: try {
103: t.start(props, use_additional_data);
104: } catch (Exception e) {
105: System.err.println(e);
106: }
107: }
108:
109: static void help() {
110: System.out
111: .println("ViewDemo [-props <properties>] [-help] [-use_additional_data <flag>]");
112: }
113:
114: }
|