1 package org.jgroups.tests; 2 3 import org.jgroups.*; 4 import org.jgroups.blocks.GroupRequest; 5 import org.jgroups.blocks.RpcDispatcher; 6 7 13 public class NAKACKTest2 { 14 Channel ch; 15 Address local_addr; 16 Receiver receiver; 17 RpcDispatcher disp; 18 19 class Receiver extends Thread { 20 public void run() { 21 Object obj; 22 Message msg; 23 boolean running=true; 24 while(running) { 25 try { 26 obj=ch.receive(0); 27 if(obj instanceof Message) { 28 msg=(Message)obj; 29 System.out.println(msg.getSrc() + "::" + msg.getObject()); 30 } 31 else 32 System.out.println("received " + obj); 33 } 34 catch(ChannelNotConnectedException e) { 35 running=false; 36 } 37 catch(ChannelClosedException e) { 38 running=false; 39 } 40 catch(TimeoutException e) { 41 ; 42 } 43 } 44 } 45 } 46 47 public void receive(Address sender, Long i) { 48 System.out.println(sender + "::" + i); 49 } 50 51 void start(String props, boolean use_rpc) throws Exception { 52 long i=0; 53 Message msg; 54 ch=new JChannel(props); 55 if(use_rpc) 56 disp=new RpcDispatcher(ch, null, null, this); 57 ch.connect("NAKACKTest"); 58 local_addr=ch.getLocalAddress(); 59 if(use_rpc == false) { 60 receiver=new Receiver(); 61 receiver.start(); 62 } 63 while(true) { 64 if(use_rpc) { 66 disp.callRemoteMethods(null, "receive", new Object []{local_addr, new Long (i++)}, 67 new Class []{Address.class, Long .class}, GroupRequest.GET_ALL, 10000); 68 } 69 else { 70 msg=new Message(null, null, new Long (i++)); 71 ch.send(msg); 72 } 73 } 75 76 } 78 79 public static void main(String [] args) { 80 String props=null; 81 boolean use_rpc=false; 82 83 for(int i=0; i < args.length; i++) { 84 if("-props".equals(args[i])) { 85 props=args[++i]; 86 continue; 87 } 88 if("-use_rpc".equals(args[i])) { 89 use_rpc=true; 90 continue; 91 } 92 help(); 93 return; 94 } 95 96 97 try { 98 new NAKACKTest2().start(props, use_rpc); 99 } 100 catch(Exception e) { 101 e.printStackTrace(); 102 } 103 } 104 105 private static void help() { 106 System.out.println("NAKACKTest [-help] [-props properties] [-use_rpc]"); 107 } 108 } 109 | Popular Tags |