1 3 4 package org.jgroups.demos; 5 6 7 import org.jgroups.Address; 8 import org.jgroups.blocks.NotificationBus; 9 10 import java.io.BufferedReader ; 11 import java.io.InputStreamReader ; 12 import java.io.Serializable ; 13 import java.util.Vector ; 14 15 16 17 18 23 public class NotificationBusDemo implements NotificationBus.Consumer { 24 NotificationBus bus=null; 25 BufferedReader in=null; 26 String line; 27 final long timeout=0; 28 final Vector cache=null; 29 30 31 32 public void start(String bus_name, String props) { 33 try { 34 35 bus=new NotificationBus(bus_name, props); 36 bus.start(); 37 bus.setConsumer(this); 42 in=new BufferedReader (new InputStreamReader (System.in)); 43 while(true) { 44 try { 45 System.out.print("> "); System.out.flush(); 46 line=in.readLine(); 47 if(line.startsWith("quit") || line.startsWith("exit")) { 48 bus.stop(); 49 bus=null; 50 break; 51 } 52 bus.sendNotification(line); 53 } 54 catch(Exception e) { 55 System.err.println(e); 56 } 57 } 58 } 59 catch(Exception ex) { 60 System.err.println(ex); 61 } 62 finally { 63 if(bus != null) 64 bus.stop(); 65 } 66 } 67 68 69 70 public void handleNotification(Serializable n) { 71 System.out.println("** Received notification: " + n); 72 } 76 77 78 public Serializable getCache() { 79 return null; 81 } 82 83 84 public void memberJoined(Address mbr) { 85 System.out.println("** Member joined: " + mbr); 86 } 87 88 public void memberLeft(Address mbr) { 89 System.out.println("** Member left: " + mbr); 90 } 91 92 93 94 public static void main(String [] args) { 95 String name="BusDemo"; 96 String props="UDP(mcast_addr=224.0.0.35;mcast_port=45566;ip_ttl=32;" + 97 "mcast_send_buf_size=150000;mcast_recv_buf_size=80000):" + 98 "PING(timeout=2000;num_initial_members=3):" + 99 "MERGE2(min_interval=5000;max_interval=10000):" + 100 "FD_SOCK:" + 101 "VERIFY_SUSPECT(timeout=1500):" + 102 "pbcast.NAKACK(gc_lag=50;retransmit_timeout=300,600,1200,2400,4800):" + 103 "UNICAST(timeout=5000):" + 104 "pbcast.STABLE(desired_avg_gossip=20000):" + 105 "FRAG(frag_size=8096;down_thread=false;up_thread=false):" + 106 "pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;" + 108 "shun=false;print_local_addr=true)"; 109 110 for(int i=0; i < args.length; i++) { 111 if("-bus_name".equals(args[i])) { 112 name=args[++i]; 113 continue; 114 } 115 if("-props".equals(args[i])) { 116 props=args[++i]; 117 continue; 118 } 119 System.out.println("NotificationBusDemo [-help] [-bus_name <name>] " + 120 "[-props <properties>]"); 121 return; 122 } 123 System.out.println("Starting NotificationBus with name " + name); 124 new NotificationBusDemo().start(name, props); 125 } 126 127 128 } 129 | Popular Tags |