Search in sources :

Example 1 with ReplicableCommand

use of org.infinispan.commands.ReplicableCommand in project hibernate-orm by hibernate.

the class CacheCommandFactory method fromStream.

@Override
public ReplicableCommand fromStream(byte commandId, Object[] args) {
    ReplicableCommand c;
    switch(commandId) {
        case CacheCommandIds.BEGIN_INVALIDATION:
            c = new BeginInvalidationCommand();
            break;
        default:
            throw new IllegalArgumentException("Not registered to handle command id " + commandId);
    }
    c.setParameters(commandId, args);
    return c;
}
Also used : ReplicableCommand(org.infinispan.commands.ReplicableCommand)

Example 2 with ReplicableCommand

use of org.infinispan.commands.ReplicableCommand in project hibernate-orm by hibernate.

the class TxInvalidationInterceptor method invalidateAcrossCluster.

private void invalidateAcrossCluster(boolean synchronous, Object[] keys, InvocationContext ctx) throws Throwable {
    // increment invalidations counter if statistics maintained
    incrementInvalidations();
    final InvalidateCommand invalidateCommand = commandsFactory.buildInvalidateCommand(InfinispanCollections.<Flag>emptySet(), keys);
    if (log.isDebugEnabled()) {
        log.debug("Cache [" + rpcManager.getAddress() + "] replicating " + invalidateCommand);
    }
    ReplicableCommand command = invalidateCommand;
    if (ctx.isInTxScope()) {
        TxInvocationContext txCtx = (TxInvocationContext) ctx;
        // A Prepare command containing the invalidation command in its 'modifications' list is sent to the remote nodes
        // so that the invalidation is executed in the same transaction and locks can be acquired and released properly.
        // This is 1PC on purpose, as an optimisation, even if the current TX is 2PC.
        // If the cache uses 2PC it's possible that the remotes will commit the invalidation and the originator rolls back,
        // but this does not impact consistency and the speed benefit is worth it.
        command = commandsFactory.buildPrepareCommand(txCtx.getGlobalTransaction(), Collections.<WriteCommand>singletonList(invalidateCommand), true);
    }
    rpcManager.invokeRemotely(getMembers(), command, synchronous ? syncRpcOptions : asyncRpcOptions);
}
Also used : WriteCommand(org.infinispan.commands.write.WriteCommand) ReplicableCommand(org.infinispan.commands.ReplicableCommand) LocalTxInvocationContext(org.infinispan.context.impl.LocalTxInvocationContext) TxInvocationContext(org.infinispan.context.impl.TxInvocationContext) InvalidateCommand(org.infinispan.commands.write.InvalidateCommand)

Aggregations

ReplicableCommand (org.infinispan.commands.ReplicableCommand)2 InvalidateCommand (org.infinispan.commands.write.InvalidateCommand)1 WriteCommand (org.infinispan.commands.write.WriteCommand)1 LocalTxInvocationContext (org.infinispan.context.impl.LocalTxInvocationContext)1 TxInvocationContext (org.infinispan.context.impl.TxInvocationContext)1