Search in sources :

Example 6 with RpcDispatcher

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;
}
Also used : RpcDispatcher(org.jgroups.blocks.RpcDispatcher) RequestOptions(org.jgroups.blocks.RequestOptions) RspList(org.jgroups.util.RspList) BeforeMethod(org.testng.annotations.BeforeMethod) AfterMethod(org.testng.annotations.AfterMethod) Method(java.lang.reflect.Method) MethodCall(org.jgroups.blocks.MethodCall) Rsp(org.jgroups.util.Rsp)

Example 7 with RpcDispatcher

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();
}
Also used : RpcDispatcher(org.jgroups.blocks.RpcDispatcher) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 8 with RpcDispatcher

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);
}
Also used : Property(org.jgroups.annotations.Property) Config(org.jgroups.tests.perf.PerfUtil.Config) LongAdder(java.util.concurrent.atomic.LongAdder) java.util(java.util) ResponseMode(org.jgroups.blocks.ResponseMode) RpcDispatcher(org.jgroups.blocks.RpcDispatcher) AddressGenerator(org.jgroups.stack.AddressGenerator) IOException(java.io.IOException) MethodCall(org.jgroups.blocks.MethodCall) PutCall(org.jgroups.tests.perf.PerfUtil.PutCall) Field(java.lang.reflect.Field) GetCall(org.jgroups.tests.perf.PerfUtil.GetCall) CountDownLatch(java.util.concurrent.CountDownLatch) org.jgroups.util(org.jgroups.util) RequestOptions(org.jgroups.blocks.RequestOptions) RELAY2(org.jgroups.protocols.relay.RELAY2) MBeanServer(javax.management.MBeanServer) org.jgroups(org.jgroups) Results(org.jgroups.tests.perf.PerfUtil.Results) Method(java.lang.reflect.Method) JmxConfigurator(org.jgroups.jmx.JmxConfigurator) TP(org.jgroups.protocols.TP) RpcDispatcher(org.jgroups.blocks.RpcDispatcher) RequestOptions(org.jgroups.blocks.RequestOptions) Config(org.jgroups.tests.perf.PerfUtil.Config) TP(org.jgroups.protocols.TP) MethodCall(org.jgroups.blocks.MethodCall) MBeanServer(javax.management.MBeanServer)

Example 9 with RpcDispatcher

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);
}
Also used : Rsp(org.jgroups.util.Rsp) Util(org.jgroups.util.Util) RequestOptions(org.jgroups.blocks.RequestOptions) ResponseMode(org.jgroups.blocks.ResponseMode) RpcDispatcher(org.jgroups.blocks.RpcDispatcher) Average(org.jgroups.util.Average) MBeanServer(javax.management.MBeanServer) org.jgroups(org.jgroups) RspList(org.jgroups.util.RspList) MethodCall(org.jgroups.blocks.MethodCall) Method(java.lang.reflect.Method) JmxConfigurator(org.jgroups.jmx.JmxConfigurator) RpcDispatcher(org.jgroups.blocks.RpcDispatcher) MBeanServer(javax.management.MBeanServer)

Example 10 with RpcDispatcher

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));
        }
    }
}
Also used : RpcDispatcher(org.jgroups.blocks.RpcDispatcher) RequestOptions(org.jgroups.blocks.RequestOptions) MethodCall(org.jgroups.blocks.MethodCall) Rsp(org.jgroups.util.Rsp) SiteMaster(org.jgroups.protocols.relay.SiteMaster)

Aggregations

RpcDispatcher (org.jgroups.blocks.RpcDispatcher)13 MethodCall (org.jgroups.blocks.MethodCall)7 RequestOptions (org.jgroups.blocks.RequestOptions)7 Method (java.lang.reflect.Method)3 MBeanServer (javax.management.MBeanServer)3 Rsp (org.jgroups.util.Rsp)3 RspList (org.jgroups.util.RspList)3 org.jgroups (org.jgroups)2 ResponseMode (org.jgroups.blocks.ResponseMode)2 JmxConfigurator (org.jgroups.jmx.JmxConfigurator)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 LongAdder (java.util.concurrent.atomic.LongAdder)1 JChannel (org.jgroups.JChannel)1 Property (org.jgroups.annotations.Property)1