Search in sources :

Example 1 with CommandsFactory

use of org.infinispan.commands.CommandsFactory in project infinispan by infinispan.

the class GlobalInboundInvocationHandler method handleCacheRpcCommand.

private void handleCacheRpcCommand(Address origin, CacheRpcCommand command, Reply reply, DeliverOrder mode) {
    if (log.isTraceEnabled()) {
        log.tracef("Attempting to execute CacheRpcCommand: %s [sender=%s]", command, origin);
    }
    ByteString cacheName = command.getCacheName();
    ComponentRegistry cr = globalComponentRegistry.getNamedComponentRegistry(cacheName);
    if (cr == null) {
        if (log.isTraceEnabled()) {
            log.tracef("Silently ignoring that %s cache is not defined", cacheName);
        }
        reply.reply(CacheNotFoundResponse.INSTANCE);
        return;
    }
    CommandsFactory commandsFactory = cr.getCommandsFactory();
    // initialize this command with components specific to the intended cache instance
    commandsFactory.initializeReplicableCommand(command, true);
    PerCacheInboundInvocationHandler handler = cr.getPerCacheInboundInvocationHandler();
    handler.handle(command, reply, mode);
}
Also used : CommandsFactory(org.infinispan.commands.CommandsFactory) ComponentRegistry(org.infinispan.factories.ComponentRegistry) GlobalComponentRegistry(org.infinispan.factories.GlobalComponentRegistry) ByteString(org.infinispan.util.ByteString)

Example 2 with CommandsFactory

use of org.infinispan.commands.CommandsFactory in project infinispan by infinispan.

the class MessageSentToLeaverTest method testGroupRequestSentToMemberAfterLeaving.

public void testGroupRequestSentToMemberAfterLeaving() {
    EmbeddedCacheManager cm1 = null, cm2 = null, cm3 = null;
    try {
        ConfigurationBuilder c = new ConfigurationBuilder();
        c.clustering().cacheMode(CacheMode.REPL_SYNC).hash().numOwners(3);
        cm1 = TestCacheManagerFactory.createClusteredCacheManager(c);
        cm2 = TestCacheManagerFactory.createClusteredCacheManager(c);
        cm3 = TestCacheManagerFactory.createClusteredCacheManager(c);
        Cache<Object, Object> c1 = cm1.getCache();
        Cache<Object, Object> c2 = cm2.getCache();
        Cache<Object, Object> c3 = cm3.getCache();
        TestingUtil.blockUntilViewsReceived(30000, c1, c2, c3);
        c2.put("k", "v1");
        RpcManager rpcManager = TestingUtil.extractComponent(c1, RpcManager.class);
        Collection<Address> addresses = cm1.getMembers();
        CommandsFactory cf = TestingUtil.extractCommandsFactory(c1);
        PutKeyValueCommand cmd = cf.buildPutKeyValueCommand("k", "v2", 0, new EmbeddedMetadata.Builder().build(), EnumUtil.EMPTY_BIT_SET);
        RpcOptions rpcOptions = rpcManager.getSyncRpcOptions();
        cmd.setTopologyId(rpcManager.getTopologyId());
        Map<Address, Response> responseMap = rpcManager.blocking(rpcManager.invokeCommand(addresses, cmd, MapResponseCollector.validOnly(), rpcOptions));
        assert responseMap.size() == 2;
        TestingUtil.killCacheManagers(cm2);
        TestingUtil.blockUntilViewsReceived(30000, false, c1, c3);
        try {
            rpcManager.blocking(rpcManager.invokeCommand(addresses, cmd, MapResponseCollector.validOnly(), rpcOptions));
            assert false : "invokeRemotely should have thrown an exception";
        } catch (SuspectException e) {
        // expected
        }
    } finally {
        TestingUtil.killCacheManagers(cm1, cm2, cm3);
    }
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) CommandsFactory(org.infinispan.commands.CommandsFactory) RpcManager(org.infinispan.remoting.rpc.RpcManager) Address(org.infinispan.remoting.transport.Address) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) SuspectException(org.infinispan.remoting.transport.jgroups.SuspectException) Response(org.infinispan.remoting.responses.Response) RpcOptions(org.infinispan.remoting.rpc.RpcOptions) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand)

Example 3 with CommandsFactory

use of org.infinispan.commands.CommandsFactory in project infinispan by infinispan.

the class IracTombstoneUnitTest method createCommandFactory.

private static CommandsFactory createCommandFactory() {
    CommandsFactory factory = Mockito.mock(CommandsFactory.class);
    IracTombstoneRemoteSiteCheckCommand cmd = Mockito.mock(IracTombstoneRemoteSiteCheckCommand.class);
    Mockito.when(factory.buildIracTombstoneRemoteSiteCheckCommand(ArgumentMatchers.any())).thenReturn(cmd);
    return factory;
}
Also used : IracTombstoneRemoteSiteCheckCommand(org.infinispan.commands.irac.IracTombstoneRemoteSiteCheckCommand) CommandsFactory(org.infinispan.commands.CommandsFactory)

Example 4 with CommandsFactory

use of org.infinispan.commands.CommandsFactory in project infinispan by infinispan.

the class PrepareCoordinator method rollbackRemoteTransaction.

/**
 * Rollbacks a transaction that is remove in all the cluster members.
 */
public final void rollbackRemoteTransaction(GlobalTransaction gtx) {
    RpcManager rpcManager = cache.getRpcManager();
    ComponentRegistry componentRegistry = cache.getComponentRegistry();
    CommandsFactory factory = componentRegistry.getCommandsFactory();
    try {
        RollbackCommand rollbackCommand = factory.buildRollbackCommand(gtx);
        rollbackCommand.setTopologyId(rpcManager.getTopologyId());
        CompletionStage<Void> cs = rpcManager.invokeCommandOnAll(rollbackCommand, validOnly(), rpcManager.getSyncRpcOptions());
        rollbackCommand.invokeAsync(componentRegistry).toCompletableFuture().join();
        cs.toCompletableFuture().join();
    } catch (Throwable throwable) {
        throw Util.rewrapAsCacheException(throwable);
    } finally {
        forgetTransaction(gtx, rpcManager, factory);
    }
}
Also used : CommandsFactory(org.infinispan.commands.CommandsFactory) RpcManager(org.infinispan.remoting.rpc.RpcManager) ComponentRegistry(org.infinispan.factories.ComponentRegistry) RollbackCommand(org.infinispan.commands.tx.RollbackCommand)

Example 5 with CommandsFactory

use of org.infinispan.commands.CommandsFactory in project infinispan by infinispan.

the class PrepareCoordinator method onePhaseCommitRemoteTransaction.

/**
 * Commits a remote 1PC transaction that is already in MARK_COMMIT state
 */
public int onePhaseCommitRemoteTransaction(GlobalTransaction gtx, List<WriteCommand> modifications) {
    RpcManager rpcManager = cache.getRpcManager();
    ComponentRegistry componentRegistry = cache.getComponentRegistry();
    CommandsFactory factory = componentRegistry.getCommandsFactory();
    try {
        // only pessimistic tx are committed in 1PC and it doesn't use versions.
        PrepareCommand command = factory.buildPrepareCommand(gtx, modifications, true);
        CompletionStage<Void> cs = rpcManager.invokeCommandOnAll(command, validOnly(), rpcManager.getSyncRpcOptions());
        command.invokeAsync(componentRegistry).toCompletableFuture().join();
        cs.toCompletableFuture().join();
        forgetTransaction(gtx, rpcManager, factory);
        return loggingCompleted(true) == Status.OK ? XAResource.XA_OK : XAException.XAER_RMERR;
    } catch (Throwable throwable) {
        // transaction should commit but we still can have exceptions (timeouts or similar)
        return XAException.XAER_RMERR;
    }
}
Also used : CommandsFactory(org.infinispan.commands.CommandsFactory) RpcManager(org.infinispan.remoting.rpc.RpcManager) ComponentRegistry(org.infinispan.factories.ComponentRegistry) PrepareCommand(org.infinispan.commands.tx.PrepareCommand)

Aggregations

CommandsFactory (org.infinispan.commands.CommandsFactory)12 RpcManager (org.infinispan.remoting.rpc.RpcManager)7 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)4 RpcOptions (org.infinispan.remoting.rpc.RpcOptions)4 Address (org.infinispan.remoting.transport.Address)4 InternalDataContainer (org.infinispan.container.impl.InternalDataContainer)3 ComponentRegistry (org.infinispan.factories.ComponentRegistry)3 TransactionTable (org.infinispan.transaction.impl.TransactionTable)3 BeforeMethod (org.testng.annotations.BeforeMethod)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ExecutorService (java.util.concurrent.ExecutorService)2 TimeUnit (java.util.concurrent.TimeUnit)2 Cache (org.infinispan.Cache)2 StateTransferCancelCommand (org.infinispan.commands.statetransfer.StateTransferCancelCommand)2 CacheMode (org.infinispan.configuration.cache.CacheMode)2