Search in sources :

Example 1 with SingleKeyNonTxInvocationContext

use of org.infinispan.context.impl.SingleKeyNonTxInvocationContext in project infinispan by infinispan.

the class CacheMgmtInterceptorTest method setup.

@BeforeMethod(alwaysRun = true)
public void setup() {
    nextInterceptor = new ControlledNextInterceptor();
    timeService = new ControlledTimeService();
    ctx = new SingleKeyNonTxInvocationContext(null);
    interceptor = new CacheMgmtInterceptor();
    interceptor.setNextInterceptor(nextInterceptor);
    TestingUtil.inject(interceptor, timeService);
    interceptor.start();
    interceptor.setStatisticsEnabled(true);
}
Also used : ControlledTimeService(org.infinispan.util.ControlledTimeService) SingleKeyNonTxInvocationContext(org.infinispan.context.impl.SingleKeyNonTxInvocationContext) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with SingleKeyNonTxInvocationContext

use of org.infinispan.context.impl.SingleKeyNonTxInvocationContext in project infinispan by infinispan.

the class XSiteStateConsumerImpl method applyStateInNonTransaction.

private void applyStateInNonTransaction(XSiteState[] chunk) {
    SingleKeyNonTxInvocationContext ctx = (SingleKeyNonTxInvocationContext) invocationContextFactory.createSingleKeyNonTxInvocationContext();
    for (XSiteState siteState : chunk) {
        PutKeyValueCommand command = createPut(siteState);
        ctx.setLockOwner(command.getKeyLockOwner());
        interceptorChain.invoke(ctx, command);
        // re-use same context. Old context is not longer needed
        ctx.resetState();
        if (log.isTraceEnabled()) {
            log.tracef("Successfully applied key'%s'", siteState);
        }
    }
    if (log.isDebugEnabled()) {
        log.debugf("Successfully applied state. %s keys inserted", chunk.length);
    }
}
Also used : SingleKeyNonTxInvocationContext(org.infinispan.context.impl.SingleKeyNonTxInvocationContext) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand)

Example 3 with SingleKeyNonTxInvocationContext

use of org.infinispan.context.impl.SingleKeyNonTxInvocationContext in project infinispan by infinispan.

the class EntryWrappingInterceptor method commitContextEntries.

protected final CompletionStage<Void> commitContextEntries(InvocationContext ctx, FlagAffectedCommand command) {
    final Flag stateTransferFlag = FlagBitSets.extractStateTransferFlag(ctx, command);
    if (ctx instanceof SingleKeyNonTxInvocationContext) {
        SingleKeyNonTxInvocationContext singleKeyCtx = (SingleKeyNonTxInvocationContext) ctx;
        return commitEntryIfNeeded(ctx, command, singleKeyCtx.getKey(), singleKeyCtx.getCacheEntry(), stateTransferFlag);
    } else {
        AggregateCompletionStage<Void> aggregateCompletionStage = null;
        Map<Object, CacheEntry> entries = ctx.getLookedUpEntries();
        for (Map.Entry<Object, CacheEntry> entry : entries.entrySet()) {
            CompletionStage<Void> stage = commitEntryIfNeeded(ctx, command, entry.getKey(), entry.getValue(), stateTransferFlag);
            if (!CompletionStages.isCompletedSuccessfully(stage)) {
                if (aggregateCompletionStage == null) {
                    aggregateCompletionStage = CompletionStages.aggregateCompletionStage();
                }
                aggregateCompletionStage.dependsOn(stage);
            }
        }
        return aggregateCompletionStage != null ? aggregateCompletionStage.freeze() : CompletableFutures.completedNull();
    }
}
Also used : SingleKeyNonTxInvocationContext(org.infinispan.context.impl.SingleKeyNonTxInvocationContext) CacheEntry(org.infinispan.container.entries.CacheEntry) Flag(org.infinispan.context.Flag) Map(java.util.Map)

Aggregations

SingleKeyNonTxInvocationContext (org.infinispan.context.impl.SingleKeyNonTxInvocationContext)3 Map (java.util.Map)1 PutKeyValueCommand (org.infinispan.commands.write.PutKeyValueCommand)1 CacheEntry (org.infinispan.container.entries.CacheEntry)1 Flag (org.infinispan.context.Flag)1 ControlledTimeService (org.infinispan.util.ControlledTimeService)1 BeforeMethod (org.testng.annotations.BeforeMethod)1