use of org.infinispan.metadata.impl.InternalMetadataImpl in project infinispan by infinispan.
the class StateConsumerImpl method invokePut.
private CompletableFuture<?> invokePut(int segmentId, InvocationContext ctx, InternalCacheEntry<?, ?> e) {
// CallInterceptor will preserve the timestamps if the metadata is an InternalMetadataImpl instance
InternalMetadataImpl metadata = new InternalMetadataImpl(e);
PutKeyValueCommand put = commandsFactory.buildPutKeyValueCommand(e.getKey(), e.getValue(), segmentId, metadata, STATE_TRANSFER_FLAGS);
put.setInternalMetadata(e.getInternalMetadata());
ctx.setLockOwner(put.getKeyLockOwner());
return interceptorChain.invokeAsync(ctx, put);
}
use of org.infinispan.metadata.impl.InternalMetadataImpl in project infinispan by infinispan.
the class CallInterceptor method visitPutKeyValueCommand.
@Override
public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable {
// It's not worth looking up the entry if we're never going to apply the change.
ValueMatcher valueMatcher = command.getValueMatcher();
if (valueMatcher == ValueMatcher.MATCH_NEVER) {
command.fail();
return null;
}
// noinspection unchecked
Object key = command.getKey();
MVCCEntry<Object, Object> e = (MVCCEntry) ctx.lookupEntry(key);
if (e == null) {
throw new IllegalStateException("Not wrapped");
}
Object newValue = command.getValue();
Metadata metadata = command.getMetadata();
if (metadata instanceof InternalMetadataImpl) {
InternalMetadataImpl internalMetadata = (InternalMetadataImpl) metadata;
metadata = internalMetadata.actual();
e.setCreated(internalMetadata.created());
e.setLastUsed(internalMetadata.lastUsed());
}
Object prevValue = e.getValue();
if (!valueMatcher.matches(prevValue, null, newValue)) {
command.fail();
return prevValue;
}
return performPut(e, ctx, valueMatcher, key, newValue, metadata, command, command.hasAnyFlag(FlagBitSets.PUT_FOR_STATE_TRANSFER | FlagBitSets.PUT_FOR_X_SITE_STATE_TRANSFER));
}
use of org.infinispan.metadata.impl.InternalMetadataImpl in project infinispan by infinispan.
the class PreloadManager method preloadEntry.
private Single<?> preloadEntry(long flags, MarshallableEntry<Object, Object> me, DataConversion keyDataConversion, DataConversion valueDataConversion) {
// CallInterceptor will preserve the timestamps if the metadata is an InternalMetadataImpl instance
InternalMetadataImpl metadata = new InternalMetadataImpl(me.getMetadata(), me.created(), me.lastUsed());
// TODO If the storage media type is application/x-protostream, this will convert to POJOs and back
Object key = keyDataConversion.toStorage(me.getKey());
Object value = valueDataConversion.toStorage(me.getValue());
PutKeyValueCommand cmd = commandsFactory.buildPutKeyValueCommand(key, value, keyPartitioner.getSegment(key), metadata, flags);
cmd.setInternalMetadata(me.getInternalMetadata());
CompletionStage<?> stage;
if (configuration.transaction().transactionMode().isTransactional()) {
try {
Transaction transaction = new FakeJTATransaction();
InvocationContext ctx = invocationContextFactory.createInvocationContext(transaction, false);
LocalTransaction localTransaction = ((LocalTxInvocationContext) ctx).getCacheTransaction();
stage = CompletionStages.handleAndCompose(invocationHelper.invokeAsync(ctx, cmd), (__, t) -> completeTransaction(key, localTransaction, t)).whenComplete((__, t) -> transactionTable.removeLocalTransaction(localTransaction));
} catch (Exception e) {
throw log.problemPreloadingKey(key, e);
}
} else {
stage = invocationHelper.invokeAsync(cmd, 1);
}
// The return value doesn't matter, but it cannot be null
return Completable.fromCompletionStage(stage).toSingleDefault(me);
}
use of org.infinispan.metadata.impl.InternalMetadataImpl in project infinispan by infinispan.
the class InternalMetadataTest method testWithInternalCacheEntry.
public void testWithInternalCacheEntry() {
TestMetadata metadata = new TestMetadata(1, 2);
InternalMetadataImpl internalMetadata = new InternalMetadataImpl(metadata, 3, 4);
assertInternalMetadataValues(internalMetadata, 1, 2, 3, 4);
assertInternalMetadataActual(internalMetadata);
TestInternalCacheEntry cacheEntry = new TestInternalCacheEntry(internalMetadata, 5, 6);
InternalMetadataImpl internalMetadata2 = new InternalMetadataImpl(cacheEntry);
assertInternalMetadataValues(internalMetadata2, 1, 2, 5, 6);
assertInternalMetadataActual(internalMetadata2);
}
use of org.infinispan.metadata.impl.InternalMetadataImpl in project infinispan by infinispan.
the class InternalMetadataTest method testWithInternalCacheEntry2.
public void testWithInternalCacheEntry2() {
TestMetadata metadata = new TestMetadata(1, 2);
TestInternalCacheEntry cacheEntry = new TestInternalCacheEntry(metadata, 3, 4);
InternalMetadataImpl internalMetadata = new InternalMetadataImpl(cacheEntry);
assertInternalMetadataValues(internalMetadata, 1, 2, 3, 4);
assertInternalMetadataActual(internalMetadata);
}
Aggregations