1 package org.jgroups.blocks; 2 3 import org.jgroups.MessageListener; 4 import org.jgroups.MembershipListener; 5 import org.jgroups.Channel; 6 import org.jgroups.ChannelException; 7 import org.jgroups.Message; 8 import org.jgroups.View; 9 import org.jgroups.Address; 10 import org.jgroups.util.RspList; 11 import org.jgroups.util.Rsp; 12 13 import java.util.Vector ; 14 import java.util.Map ; 15 import java.util.Iterator ; 16 17 public class RpcDispatcherAnycastServerObject implements MessageListener, MembershipListener 18 { 19 int i = 0; 20 private Channel c; 21 private RpcDispatcher d; 22 23 public RpcDispatcherAnycastServerObject(Channel channel) throws ChannelException 24 { 25 c = channel; 26 c.connect("test"); 27 d = new RpcDispatcher(c, this, this, this); 28 } 29 30 public void doSomething() 31 { 32 System.out.println("doSomething invoked on " + c.getLocalAddress() + ". i = " + i); 33 i++; 34 System.out.println("Now i = " + i); 35 } 36 37 public void callRemote(boolean useAnycast, boolean excludeSelf) 38 { 39 Vector v = new Vector (c.getView().getMembers()); 42 if (excludeSelf) v.remove(c.getLocalAddress()); 43 RspList rsps=d.callRemoteMethods(v, "doSomething", new Object []{}, new Class []{}, GroupRequest.GET_ALL, 10000, useAnycast); 44 Map.Entry entry; 45 for(Iterator it=rsps.entrySet().iterator(); it.hasNext();) { 46 entry=(Map.Entry )it.next(); 47 Address member=(Address)entry.getKey(); 48 Rsp rsp=(Rsp)entry.getValue(); 49 if(!rsp.wasReceived()) 50 throw new RuntimeException ("response from " + member + " was not received, rsp=" + rsp); 51 } 52 53 } 54 55 public void shutdown() 56 { 57 c.close(); 58 } 59 60 61 public void receive(Message msg) 62 { 63 } 64 65 public byte[] getState() 66 { 67 return new byte[0]; 68 } 69 70 public void setState(byte[] state) 71 { 72 } 73 74 public void viewAccepted(View new_view) 75 { 76 } 77 78 public void suspect(Address suspected_mbr) 79 { 80 } 81 82 public void block() 83 { 84 } 85 } | Popular Tags |