use of org.jgroups.protocols.relay.SiteMaster in project JGroups by belaban.
the class RelayDemoRpc method start.
public void start(String props, String name) throws Exception {
ch = new JChannel(props);
if (name != null)
ch.setName(name);
disp = new RpcDispatcher(ch, this).setMembershipListener(this);
ch.connect("RelayDemo");
local_addr = ch.getAddress().toString();
MethodCall call = new MethodCall(getClass().getMethod("handleMessage", String.class, String.class));
for (; ; ) {
String line = Util.readStringFromStdin(": ");
if (line.startsWith("help")) {
System.out.println("unicast <text> // unicasts to all members of local view\n" + "site <site>+ // unicasts to all listed site masters, e.g. \"site sfo lon\"\n" + "mcast <site>+ // anycasts to all local members, plus listed site masters \n" + "<text> // multicast, RELAY2 will relay to all members of sites");
continue;
}
call.args(line, local_addr);
// unicast to every member of the local cluster
if (line.equalsIgnoreCase("unicast")) {
for (Address dest : view.getMembers()) {
System.out.println("invoking method in " + dest + ": ");
try {
Object rsp = disp.callRemoteMethod(dest, call, new RequestOptions(ResponseMode.GET_ALL, RPC_TIMEOUT));
System.out.println("rsp from " + dest + ": " + rsp);
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
} else // unicast to 1 SiteMaster
if (line.startsWith("site")) {
Collection<String> site_masters = parseSiteMasters(line.substring("site".length()));
for (String site_master : site_masters) {
try {
SiteMaster dest = new SiteMaster(site_master);
System.out.println("invoking method in " + dest + ": ");
Object rsp = disp.callRemoteMethod(dest, call, new RequestOptions(ResponseMode.GET_ALL, RPC_TIMEOUT));
System.out.println("rsp from " + dest + ": " + rsp);
} catch (Throwable t) {
t.printStackTrace();
}
}
} else // mcast to all local members and N SiteMasters
if (line.startsWith("mcast")) {
Collection<String> site_masters = parseSiteMasters(line.substring("mcast".length()));
Collection<Address> dests = new ArrayList<>(site_masters.size());
for (String site_master : site_masters) {
try {
dests.add(new SiteMaster(site_master));
} catch (Throwable t) {
System.err.println("failed adding SiteMaster for " + site_master + ": " + t);
}
}
dests.addAll(view.getMembers());
System.out.println("invoking method in " + dests + ": ");
RspList<Object> rsps = disp.callRemoteMethods(dests, call, new RequestOptions(ResponseMode.GET_ALL, RPC_TIMEOUT).anycasting(true));
for (Map.Entry<Address, Rsp<Object>> entry : rsps.entrySet()) {
Address sender = entry.getKey();
Rsp<Object> rsp = entry.getValue();
if (rsp.wasUnreachable())
System.out.println("<< unreachable: " + sender);
else
System.out.println("<< " + rsp.getValue() + " from " + sender);
}
} else {
// mcasting the call to all local cluster members
RspList<Object> rsps = disp.callRemoteMethods(null, call, new RequestOptions(ResponseMode.GET_ALL, RPC_TIMEOUT).anycasting(false));
rsps.entrySet().stream().forEach(entry -> {
Rsp<Object> val = entry.getValue();
System.out.println("<< " + val.getValue() + " from " + entry.getKey());
});
}
}
}
use of org.jgroups.protocols.relay.SiteMaster in project JGroups by belaban.
the class Relay2RpcDispatcherTest method testNotificationAndRpcRelay2Transit.
/**
* Tests that notifications are routed to all sites.
*/
public void testNotificationAndRpcRelay2Transit() throws Exception {
a.connect(LON_CLUSTER);
b.connect(LON_CLUSTER);
rpca.start();
rpcb.start();
Util.waitUntilAllChannelsHaveSameView(30000, 1000, a, b);
x.connect(SFO_CLUSTER);
y.connect(SFO_CLUSTER);
rpcx.start();
rpcy.start();
Util.waitUntilAllChannelsHaveSameView(30000, 1000, x, y);
assert a.getView().size() == 2;
assert x.getView().size() == 2;
RELAY2 ar = a.getProtocolStack().findProtocol(RELAY2.class);
RELAY2 xr = x.getProtocolStack().findProtocol(RELAY2.class);
assert ar != null && xr != null;
JChannel a_bridge = null, x_bridge = null;
for (int i = 0; i < 20; i++) {
a_bridge = ar.getBridge(SFO);
x_bridge = xr.getBridge(LON);
if (a_bridge != null && x_bridge != null && a_bridge.getView().size() == 2 && x_bridge.getView().size() == 2)
break;
Util.sleep(500);
}
assert a_bridge != null && x_bridge != null;
System.out.println("A's bridge channel: " + a_bridge.getView());
System.out.println("X's bridge channel: " + x_bridge.getView());
assert a_bridge.getView().size() == 2 : "bridge view is " + a_bridge.getView();
assert x_bridge.getView().size() == 2 : "bridge view is " + x_bridge.getView();
Route route = getRoute(x, LON);
System.out.println("Route at sfo to lon: " + route);
assert route != null;
System.out.println("B: sending message 0 to the site master of SFO");
Address sm_sfo = new SiteMaster(SFO);
MethodCall call = new MethodCall(ServerObject.class.getMethod("foo"));
System.out.println("B: call foo method on A");
Object rsp = rpcb.callRemoteMethod(a.getAddress(), call, new RequestOptions(ResponseMode.GET_ALL, 5000));
System.out.println("RSP is: " + rsp);
System.out.println("B: call foo method on SFO master site");
rsp = rpcb.callRemoteMethod(sm_sfo, call, new RequestOptions(ResponseMode.GET_ALL, 15000));
System.out.println("RSP is: " + rsp);
System.out.println("B: call foo method on all members in site LON");
RspList<Integer> rsps = rpcb.callRemoteMethods(null, call, new RequestOptions(ResponseMode.GET_ALL, 5000));
System.out.println("RSPs are: \n" + rsps);
assert rsps.size() == 2;
assert rsps.containsKey(a.getAddress()) && rsps.containsKey(b.getAddress());
View bridge_view = xr.getBridgeView(BRIDGE_CLUSTER);
System.out.println("bridge_view = " + bridge_view);
route = getRoute(x, LON);
System.out.println("Route at sfo to lon: " + route);
assert route != null;
}
use of org.jgroups.protocols.relay.SiteMaster in project JGroups by belaban.
the class ExtendedUUIDTest method testSiteMaster.
public void testSiteMaster() {
SiteMaster sm1 = new SiteMaster("sfo"), sm2 = new SiteMaster("nyc"), sm3 = new SiteMaster("sfo");
assert !sm1.equals(sm2);
assert sm1.equals(sm3);
assert sm1.compareTo(sm3) == 0;
long hc1 = sm1.hashCode(), hc2 = sm2.hashCode(), hc3 = sm3.hashCode();
assert hc1 == hc3;
assert hc1 != hc2;
Map<SiteMaster, Integer> map = new HashMap<>(3);
map.put(sm1, 1);
map.put(sm2, 2);
map.put(sm3, 3);
System.out.println("map = " + map);
assert map.size() == 2;
assert map.get(sm3) == 3;
assert map.get(sm1) == 3;
assert map.get(sm2) == 2;
}
use of org.jgroups.protocols.relay.SiteMaster in project JGroups by belaban.
the class Util method readAddress.
public static Address readAddress(DataInput in) throws Exception {
byte flags = in.readByte();
if (Util.isFlagSet(flags, Address.NULL))
return null;
Address addr;
if (Util.isFlagSet(flags, Address.UUID_ADDR)) {
addr = new UUID();
addr.readFrom(in);
} else if (Util.isFlagSet(flags, Address.SITE_UUID)) {
addr = new SiteUUID();
addr.readFrom(in);
} else if (Util.isFlagSet(flags, Address.SITE_MASTER)) {
addr = new SiteMaster();
addr.readFrom(in);
} else if (Util.isFlagSet(flags, Address.IP_ADDR)) {
addr = new IpAddress();
addr.readFrom(in);
} else if (Util.isFlagSet(flags, Address.IP_ADDR_UUID)) {
addr = new IpAddressUUID();
addr.readFrom(in);
} else {
addr = readOtherAddress(in);
}
return addr;
}
Aggregations