01: package org.jgroups.blocks;
02:
03: import org.jgroups.MessageListener;
04: import org.jgroups.MembershipListener;
05: import org.jgroups.Channel;
06: import org.jgroups.ChannelException;
07: import org.jgroups.Message;
08: import org.jgroups.View;
09: 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
18: MessageListener, MembershipListener {
19: int i = 0;
20: private Channel c;
21: private RpcDispatcher d;
22:
23: public RpcDispatcherAnycastServerObject(Channel channel)
24: throws ChannelException {
25: c = channel;
26: c.connect("test");
27: d = new RpcDispatcher(c, this , this , this );
28: }
29:
30: public void doSomething() {
31: System.out.println("doSomething invoked on "
32: + c.getLocalAddress() + ". i = " + i);
33: i++;
34: System.out.println("Now i = " + i);
35: }
36:
37: public void callRemote(boolean useAnycast, boolean excludeSelf) {
38: // we need to copy the vector, otherwise the modification below will throw an exception because the underlying
39: // vector is unmodifiable
40: Vector v = new Vector(c.getView().getMembers());
41: if (excludeSelf)
42: v.remove(c.getLocalAddress());
43: RspList rsps = d.callRemoteMethods(v, "doSomething",
44: new Object[] {}, new Class[] {}, GroupRequest.GET_ALL,
45: 10000, useAnycast);
46: Map.Entry entry;
47: for (Iterator it = rsps.entrySet().iterator(); it.hasNext();) {
48: entry = (Map.Entry) it.next();
49: Address member = (Address) entry.getKey();
50: Rsp rsp = (Rsp) entry.getValue();
51: if (!rsp.wasReceived())
52: throw new RuntimeException("response from " + member
53: + " was not received, rsp=" + rsp);
54: }
55:
56: }
57:
58: public void shutdown() {
59: c.close();
60: }
61:
62: public void receive(Message msg) {
63: }
64:
65: public byte[] getState() {
66: return new byte[0];
67: }
68:
69: public void setState(byte[] state) {
70: }
71:
72: public void viewAccepted(View new_view) {
73: }
74:
75: public void suspect(Address suspected_mbr) {
76: }
77:
78: public void block() {
79: }
80: }
|