Search in sources :

Example 1 with InvocationFinallyAction

use of org.infinispan.interceptors.InvocationFinallyAction in project infinispan by infinispan.

the class NonTxDistributionInterceptor method createLocalInvocationHandler.

private <C extends WriteCommand, F extends CountDownCompletableFuture, Item> InvocationFinallyAction<C> createLocalInvocationHandler(F allFuture, IntSet segments, WriteManyCommandHelper<C, ?, Item> helper, BiConsumer<F, Object> returnValueConsumer, LocalizedCacheTopology topology) {
    return (rCtx, rCommand, rv, throwable) -> {
        if (throwable != null) {
            allFuture.completeExceptionally(throwable);
        } else
            try {
                returnValueConsumer.accept(allFuture, rv);
                Map<Address, IntSet> backupOwners = backupOwnersOfSegments(topology, segments);
                for (Entry<Address, IntSet> backup : backupOwners.entrySet()) {
                    // rCommand is the original command
                    C backupCopy = helper.copyForBackup(rCommand, topology, backup.getKey(), backup.getValue());
                    backupCopy.setTopologyId(rCommand.getTopologyId());
                    if (helper.getItems(backupCopy).isEmpty())
                        continue;
                    Address backupOwner = backup.getKey();
                    if (isSynchronous(backupCopy)) {
                        allFuture.increment();
                        rpcManager.invokeCommand(backupOwner, backupCopy, SingleResponseCollector.validOnly(), rpcManager.getSyncRpcOptions()).whenComplete((response, remoteThrowable) -> {
                            if (remoteThrowable != null) {
                                allFuture.completeExceptionally(remoteThrowable);
                            } else {
                                allFuture.countDown();
                            }
                        });
                    } else {
                        rpcManager.sendTo(backupOwner, backupCopy, DeliverOrder.PER_SENDER);
                    }
                }
                allFuture.countDown();
            } catch (Throwable t) {
                allFuture.completeExceptionally(t);
            }
    };
}
Also used : WriteCommand(org.infinispan.commands.write.WriteCommand) IntSets(org.infinispan.commons.util.IntSets) ComputeCommand(org.infinispan.commands.write.ComputeCommand) LogFactory(org.infinispan.util.logging.LogFactory) ReplaceCommand(org.infinispan.commands.write.ReplaceCommand) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) WriteOnlyManyEntriesCommand(org.infinispan.commands.functional.WriteOnlyManyEntriesCommand) FlagBitSets(org.infinispan.context.impl.FlagBitSets) InvocationContext(org.infinispan.context.InvocationContext) SingleResponseCollector(org.infinispan.remoting.transport.impl.SingleResponseCollector) OutdatedTopologyException(org.infinispan.statetransfer.OutdatedTopologyException) Map(java.util.Map) IracPutKeyValueCommand(org.infinispan.commands.write.IracPutKeyValueCommand) Log(org.infinispan.util.logging.Log) BiConsumer(java.util.function.BiConsumer) Address(org.infinispan.remoting.transport.Address) RemoveCommand(org.infinispan.commands.write.RemoveCommand) CacheEntry(org.infinispan.container.entries.CacheEntry) ConsistentHash(org.infinispan.distribution.ch.ConsistentHash) WriteOnlyKeyValueCommand(org.infinispan.commands.functional.WriteOnlyKeyValueCommand) Collection(java.util.Collection) ReadWriteManyEntriesCommand(org.infinispan.commands.functional.ReadWriteManyEntriesCommand) WriteOnlyManyCommand(org.infinispan.commands.functional.WriteOnlyManyCommand) ReadWriteKeyValueCommand(org.infinispan.commands.functional.ReadWriteKeyValueCommand) Set(java.util.Set) PutMapCommand(org.infinispan.commands.write.PutMapCommand) InvocationSuccessFunction(org.infinispan.interceptors.InvocationSuccessFunction) PrimitiveIterator(java.util.PrimitiveIterator) IntSet(org.infinispan.commons.util.IntSet) List(java.util.List) SingletonMapResponseCollector(org.infinispan.remoting.transport.impl.SingletonMapResponseCollector) CompletionStage(java.util.concurrent.CompletionStage) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) ReadWriteKeyCommand(org.infinispan.commands.functional.ReadWriteKeyCommand) ComputeIfAbsentCommand(org.infinispan.commands.write.ComputeIfAbsentCommand) LocalizedCacheTopology(org.infinispan.distribution.LocalizedCacheTopology) InvocationFinallyAction(org.infinispan.interceptors.InvocationFinallyAction) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand) Entry(java.util.Map.Entry) WriteOnlyKeyCommand(org.infinispan.commands.functional.WriteOnlyKeyCommand) ReadWriteManyCommand(org.infinispan.commands.functional.ReadWriteManyCommand) DeliverOrder(org.infinispan.remoting.inboundhandler.DeliverOrder) Address(org.infinispan.remoting.transport.Address) IntSet(org.infinispan.commons.util.IntSet)

Aggregations

ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 PrimitiveIterator (java.util.PrimitiveIterator)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionStage (java.util.concurrent.CompletionStage)1 BiConsumer (java.util.function.BiConsumer)1 ReadWriteKeyCommand (org.infinispan.commands.functional.ReadWriteKeyCommand)1 ReadWriteKeyValueCommand (org.infinispan.commands.functional.ReadWriteKeyValueCommand)1 ReadWriteManyCommand (org.infinispan.commands.functional.ReadWriteManyCommand)1 ReadWriteManyEntriesCommand (org.infinispan.commands.functional.ReadWriteManyEntriesCommand)1 WriteOnlyKeyCommand (org.infinispan.commands.functional.WriteOnlyKeyCommand)1 WriteOnlyKeyValueCommand (org.infinispan.commands.functional.WriteOnlyKeyValueCommand)1 WriteOnlyManyCommand (org.infinispan.commands.functional.WriteOnlyManyCommand)1 WriteOnlyManyEntriesCommand (org.infinispan.commands.functional.WriteOnlyManyEntriesCommand)1 ComputeCommand (org.infinispan.commands.write.ComputeCommand)1