use of org.infinispan.encoding.DataConversion in project keycloak by keycloak.
the class PersistenceManagerImpl method preload.
@Override
public CompletionStage<Void> preload() {
long stamp = acquireReadLock();
NonBlockingStore<Object, Object> nonBlockingStore = getStoreLocked(status -> status.config.preload());
if (nonBlockingStore == null) {
releaseReadLock(stamp);
return CompletableFutures.completedNull();
}
Publisher<MarshallableEntry<Object, Object>> publisher = nonBlockingStore.publishEntries(IntSets.immutableRangeSet(segmentCount), null, true);
long start = timeService.time();
final long maxEntries = getMaxEntries();
final long flags = getFlagsForStateInsertion();
AdvancedCache<?, ?> tmpCache = this.cache.wired().withStorageMediaType();
DataConversion keyDataConversion = tmpCache.getKeyDataConversion();
DataConversion valueDataConversion = tmpCache.getValueDataConversion();
return Flowable.fromPublisher(publisher).doFinally(() -> releaseReadLock(stamp)).take(maxEntries).concatMapSingle(me -> preloadEntry(flags, me, keyDataConversion, valueDataConversion)).count().toCompletionStage().thenAccept(insertAmount -> {
this.preloaded = insertAmount < maxEntries;
log.debugf("Preloaded %d keys in %s", insertAmount, Util.prettyPrintTime(timeService.timeDuration(start, MILLISECONDS)));
});
}
use of org.infinispan.encoding.DataConversion in project infinispan by infinispan.
the class Mutations method readFrom.
static <K, V, T> Mutation<K, V, ?> readFrom(ObjectInput input) throws IOException, ClassNotFoundException {
DataConversion keyDataConversion = DataConversion.readFrom(input);
DataConversion valueDataConversion = DataConversion.readFrom(input);
switch(input.readByte()) {
case ReadWrite.TYPE:
return new ReadWrite<>(keyDataConversion, valueDataConversion, (Function<EntryView.ReadWriteEntryView<K, V>, T>) input.readObject());
case ReadWriteWithValue.TYPE:
return new ReadWriteWithValue<>(keyDataConversion, valueDataConversion, input.readObject(), (BiFunction<V, EntryView.ReadWriteEntryView<K, V>, T>) input.readObject());
case Write.TYPE:
return new Write<>(keyDataConversion, valueDataConversion, (Consumer<EntryView.WriteEntryView<K, V>>) input.readObject());
case WriteWithValue.TYPE:
return new WriteWithValue<>(keyDataConversion, valueDataConversion, input.readObject(), (BiConsumer<T, EntryView.WriteEntryView<K, V>>) input.readObject());
default:
throw new IllegalStateException("Unknown type of mutation, broken input?");
}
}
use of org.infinispan.encoding.DataConversion in project infinispan by infinispan.
the class InternalCacheFactory method buildEncodingCache.
private AdvancedCache<K, V> buildEncodingCache(AdvancedCache<K, V> wrappedCache) {
DataConversion keyDataConversion = newKeyDataConversion();
DataConversion valueDataConversion = newValueDataConversion();
return new EncoderCache<>(wrappedCache, null, null, keyDataConversion, valueDataConversion);
}
use of org.infinispan.encoding.DataConversion in project infinispan by infinispan.
the class EncoderCache method withKeyEncoding.
@Override
public AdvancedCache<K, V> withKeyEncoding(Class<? extends Encoder> encoderClass) {
checkSubclass(encoderClass, Encoder.class);
DataConversion newKeyDataConversion = keyDataConversion.withEncoding(encoderClass);
EncoderCache<K, V> encoderCache = new EncoderCache<>(cache, entryFactory, componentRegistry, newKeyDataConversion, valueDataConversion);
encoderCache.lookupEncoderWrapper();
return encoderCache;
}
use of org.infinispan.encoding.DataConversion in project infinispan by infinispan.
the class CallInterceptor method visitWriteOnlyKeyValueCommand.
@Override
public Object visitWriteOnlyKeyValueCommand(InvocationContext ctx, WriteOnlyKeyValueCommand command) throws Throwable {
MVCCEntry e = (MVCCEntry) ctx.lookupEntry(command.getKey());
// Could be that the key is not local
if (e == null)
return null;
DataConversion valueDataConversion = command.getValueDataConversion();
Object decodedArgument = valueDataConversion.fromStorage(command.getArgument());
boolean exists = e.getValue() != null;
command.getBiConsumer().accept(decodedArgument, EntryViews.writeOnly(e, valueDataConversion));
// The effective result of retried command is not safe; we'll go to backup anyway
if (!e.isChanged() && !command.hasAnyFlag(FlagBitSets.COMMAND_RETRY)) {
command.fail();
}
updateStoreFlags(command, e);
return Param.StatisticsMode.isSkip(command.getParams()) ? null : StatsEnvelope.create(null, e, exists, false);
}
Aggregations