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);
}
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);
}
}
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;
}
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);
}
}
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;
}
}
Aggregations