1 3 package org.jgroups.tests; 4 5 import org.jgroups.*; 6 import org.jgroups.blocks.GroupRequest; 7 import org.jgroups.blocks.RpcDispatcher; 8 import org.jgroups.util.RspList; 9 import org.jgroups.util.Util; 10 11 12 13 14 32 public class RpcDispatcherBlocking implements MembershipListener { 33 RpcDispatcher disp; 34 Channel channel; 35 long timeout=30000; 36 String props=null; 37 int i=0; 38 39 40 public RpcDispatcherBlocking(String props, long timeout) { 41 this.props=props; this.timeout=timeout; 42 } 43 44 45 public void print(int i) throws Exception { 46 System.out.println("<-- " + i + " [sleeping for " + timeout + " msecs"); 47 Util.sleep(timeout); 48 } 49 50 51 public void viewAccepted(View new_view) { 52 System.out.println("new view: " + new_view); 53 } 54 55 56 57 public void suspect(Address suspected_mbr) { 58 System.out.println(suspected_mbr + " is suspected"); 59 } 60 61 62 63 public void block() { 64 65 } 66 67 68 public void start() throws Exception { 69 int c; 70 RspList rsps; 71 72 channel=new JChannel(); disp=new RpcDispatcher(channel, null, this, this); 74 channel.connect("rpc-test"); 75 76 while(true) { 77 System.out.println("[x]: exit [s]: send sync group RPC"); 78 System.out.flush(); 79 c=System.in.read(); 80 switch(c) { 81 case 'x': 82 channel.close(); 83 disp.stop(); 84 return; 85 case 's': 86 rsps=sendGroupRpc(); 87 System.out.println("responses:\n" + rsps); 88 break; 89 } 90 91 System.in.skip(System.in.available()); 92 } 93 } 94 95 96 RspList sendGroupRpc() throws Exception { 97 return disp.callRemoteMethods(null, "print", new Object []{new Integer (i++)}, new Class [] {int.class}, 98 GroupRequest.GET_ALL, 0); 99 } 100 101 102 public static void main(String [] args) { 103 long timeout=30000; 104 String props=null; 105 106 for(int i=0; i < args.length; i++) { 107 if("-props".equals(args[i])) { 108 props=args[++i]; 109 continue; 110 } 111 if("-timeout".equals(args[i])) { 112 timeout=Long.parseLong(args[++i]); 113 continue; 114 } 115 help(); 116 return; 117 } 118 119 120 121 try { 122 new RpcDispatcherBlocking(props, timeout).start(); 123 } 124 catch(Exception ex) { 125 System.err.println(ex); 126 } 127 } 128 129 130 static void help() { 131 System.out.println("RpcDispatcherBlocking [-help] [-props <properties>] [-timeout <timeout>]"); 132 } 133 } 134 | Popular Tags |