use of org.jgroups.blocks.RpcDispatcher in project JGroups by belaban.
the class RSVPTest method testRpcWithFuture.
public void testRpcWithFuture() throws Exception {
final Method method = getClass().getMethod("getGreeting");
RpcDispatcher[] dispatchers = new RpcDispatcher[channels.length];
for (int i = 0; i < dispatchers.length; i++) {
channels[i].setReceiver(null);
dispatchers[i] = new RpcDispatcher(channels[i], this);
dispatchers[i].start();
}
DISCARD discard = channels[0].getProtocolStack().findProtocol(DISCARD.class);
discard.dropDownMulticasts(1);
RequestOptions opts = RequestOptions.SYNC().flags(Message.Flag.RSVP_NB);
long start = System.currentTimeMillis();
Future<RspList<String>> future = dispatchers[0].callRemoteMethodsWithFuture(null, new MethodCall(method), opts);
long rpc_time = System.currentTimeMillis() - start;
start = System.currentTimeMillis();
RspList<String> rsps = future.get(3000, TimeUnit.MILLISECONDS);
long get_time = System.currentTimeMillis() - start;
System.out.printf("rsps=\n%s\nRPC time=%d ms, Get time=%d ms", rsps, rpc_time, get_time);
assert rsps.size() == channels.length;
for (Rsp rsp : rsps) assert rsp.wasReceived() && rsp.getValue() != null;
// take a GC into account
assert rpc_time < 500;
}
use of org.jgroups.blocks.RpcDispatcher in project JGroups by belaban.
the class RemoteGetStressTest method start.
protected void start() throws Exception {
String[] names = { "A", "B", "C", "D" };
channels = new JChannel[4];
dispatchers = new RpcDispatcher[channels.length];
for (int i = 0; i < channels.length; i++) {
channels[i] = createChannel(names[i]);
dispatchers[i] = new RpcDispatcher(channels[i], this);
channels[i].connect("cluster");
}
Util.waitUntilAllChannelsHaveSameView(10000, 500, channels);
System.out.println("view A: " + channels[0].getView());
target_members = Arrays.asList(channels[1].getAddress(), channels[2].getAddress(), channels[3].getAddress());
final AtomicInteger success = new AtomicInteger(0), failure = new AtomicInteger(0);
if (USE_SLEEPS)
insertDISCARD(channels[0], 0.2);
long start = System.currentTimeMillis();
Invoker[] invokers = new Invoker[NUM_THREADS];
for (int i = 0; i < invokers.length; i++) {
invokers[i] = new Invoker(dispatchers[0], success, failure);
invokers[i].start();
}
for (Invoker invoker : invokers) invoker.join();
long time = System.currentTimeMillis() - start;
System.out.println("\n\n**** success: " + success + ", failure=" + failure + ", time=" + time + " ms");
Util.keyPress("enter to terminate");
stop();
}
use of org.jgroups.blocks.RpcDispatcher in project JGroups by belaban.
the class UPerf method init.
public void init(String props, String name, AddressGenerator generator, int bind_port, boolean use_fibers) throws Throwable {
thread_factory = new DefaultThreadFactory("invoker", false, true).useFibers(use_fibers);
if (use_fibers && Util.fibersAvailable())
System.out.println("-- using fibers instead of threads");
channel = new JChannel(props).addAddressGenerator(generator).setName(name);
if (bind_port > 0) {
TP transport = channel.getProtocolStack().getTransport();
transport.setBindPort(bind_port);
}
disp = new RpcDispatcher(channel, this).setReceiver(this).setMethodLookup(id -> METHODS[id]);
channel.connect(groupname);
local_addr = channel.getAddress();
try {
MBeanServer server = Util.getMBeanServer();
JmxConfigurator.registerChannel(channel, server, "jgroups", channel.getClusterName(), true);
} catch (Throwable ex) {
System.err.println("registering the channel in JMX failed: " + ex);
}
if (members.size() < 2)
return;
Address coord = members.get(0);
Config config = disp.callRemoteMethod(coord, new MethodCall(GET_CONFIG), new RequestOptions(ResponseMode.GET_ALL, 5000));
if (config != null) {
applyConfig(config);
System.out.println("Fetched config from " + coord + ": " + config + "\n");
} else
System.err.println("failed to fetch config from " + coord);
}
use of org.jgroups.blocks.RpcDispatcher in project JGroups by belaban.
the class RpcDispatcherSpeedTest method start.
public void start(String props, boolean jmx, String name) throws Exception {
channel = new JChannel(props).name(name);
disp = // no concurrent processing on incoming method calls
new RpcDispatcher(channel, this).setReceiver(this).setMethodLookup(id -> METHODS[0]);
if (jmx) {
MBeanServer srv = Util.getMBeanServer();
if (srv == null)
throw new Exception("No MBeanServers found");
JmxConfigurator.registerChannel(channel, srv, "jgroups", channel.getClusterName(), true);
}
channel.connect("rpc-speed-test");
View view = channel.getView();
if (view.size() > 2)
System.err.printf("More than 2 members in cluster: %s; terminating\n", view);
else
loop();
Util.close(disp, channel);
}
use of org.jgroups.blocks.RpcDispatcher 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).setReceiver(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.setArgs(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.forEach((key, val) -> System.out.println("<< " + val.getValue() + " from " + key));
}
}
}
Aggregations