Search in sources :

Example 1 with FilterMapResponseCollector

use of org.infinispan.remoting.transport.impl.FilterMapResponseCollector in project infinispan by infinispan.

the class RpcManagerTimeoutTest method testTimeoutWithResponseFilter.

@Test(expectedExceptions = TimeoutException.class)
public void testTimeoutWithResponseFilter() {
    RpcManager rpcManager = advancedCache(0, CACHE_NAME).getRpcManager();
    final List<Address> members = rpcManager.getMembers();
    // wait for the responses from the last two members.
    ResponseFilter filter = new ResponseFilter() {

        private int expectedResponses = 2;

        @Override
        public boolean isAcceptable(Response response, Address sender) {
            if (sender.equals(members.get(2)) || sender.equals(members.get(3))) {
                expectedResponses--;
            }
            return true;
        }

        @Override
        public boolean needMoreResponses() {
            return expectedResponses > 0;
        }
    };
    doTest(new FilterMapResponseCollector(filter, true, 2), false);
}
Also used : Response(org.infinispan.remoting.responses.Response) Address(org.infinispan.remoting.transport.Address) FilterMapResponseCollector(org.infinispan.remoting.transport.impl.FilterMapResponseCollector) MultipleCacheManagersTest(org.infinispan.test.MultipleCacheManagersTest) Test(org.testng.annotations.Test)

Example 2 with FilterMapResponseCollector

use of org.infinispan.remoting.transport.impl.FilterMapResponseCollector in project infinispan by infinispan.

the class JGroupsTransport method performSyncRemoteInvocation.

private CompletableFuture<Map<Address, Response>> performSyncRemoteInvocation(Collection<Address> targets, ReplicableCommand command, ResponseMode mode, long timeout, ResponseFilter responseFilter, DeliverOrder deliverOrder, boolean ignoreLeavers, boolean sendStaggeredRequest, boolean broadcast, Address singleTarget) {
    CompletionStage<Map<Address, Response>> request;
    if (sendStaggeredRequest) {
        FilterMapResponseCollector collector = new FilterMapResponseCollector(responseFilter, false, targets.size());
        request = invokeCommandStaggered(targets, command, collector, deliverOrder, timeout, TimeUnit.MILLISECONDS);
    } else {
        if (singleTarget != null) {
            ResponseCollector<Map<Address, Response>> collector = ignoreLeavers ? SingletonMapResponseCollector.ignoreLeavers() : SingletonMapResponseCollector.validOnly();
            request = invokeCommand(singleTarget, command, collector, deliverOrder, timeout, TimeUnit.MILLISECONDS);
        } else {
            ResponseCollector<Map<Address, Response>> collector;
            if (mode == ResponseMode.WAIT_FOR_VALID_RESPONSE) {
                collector = new FilterMapResponseCollector(responseFilter, false, targets.size());
            } else if (responseFilter != null) {
                collector = new FilterMapResponseCollector(responseFilter, true, targets.size());
            } else {
                collector = MapResponseCollector.ignoreLeavers(ignoreLeavers, targets.size());
            }
            if (broadcast) {
                request = invokeCommandOnAll(command, collector, deliverOrder, timeout, TimeUnit.MILLISECONDS);
            } else {
                request = invokeCommand(targets, command, collector, deliverOrder, timeout, TimeUnit.MILLISECONDS);
            }
        }
    }
    return request.toCompletableFuture();
}
Also used : FilterMapResponseCollector(org.infinispan.remoting.transport.impl.FilterMapResponseCollector) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Aggregations

FilterMapResponseCollector (org.infinispan.remoting.transport.impl.FilterMapResponseCollector)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Response (org.infinispan.remoting.responses.Response)1 Address (org.infinispan.remoting.transport.Address)1 MultipleCacheManagersTest (org.infinispan.test.MultipleCacheManagersTest)1 Test (org.testng.annotations.Test)1