Search in sources :

Example 1 with TxReadOnlyManyCommand

use of org.infinispan.commands.functional.TxReadOnlyManyCommand in project infinispan by infinispan.

the class CallInterceptor method visitReadOnlyManyCommand.

@Override
public Object visitReadOnlyManyCommand(InvocationContext ctx, ReadOnlyManyCommand command) throws Throwable {
    if (command instanceof TxReadOnlyManyCommand) {
        TxReadOnlyManyCommand txReadOnlyManyCommand = (TxReadOnlyManyCommand) command;
        List<List<Mutation>> mutations = txReadOnlyManyCommand.getMutations();
        if (mutations != null && !mutations.isEmpty()) {
            return visitTxReadOnlyCommand(ctx, (TxReadOnlyManyCommand) command, mutations);
        }
    }
    Collection<?> keys = command.getKeys();
    // lazy execution triggers exceptions on unexpected places
    ArrayList<Object> retvals = new ArrayList<>(keys.size());
    boolean skipStats = Param.StatisticsMode.isSkip(command.getParams());
    DataConversion keyDataConversion = command.getKeyDataConversion();
    DataConversion valueDataConversion = command.getValueDataConversion();
    Function function = command.getFunction();
    for (Object k : keys) {
        CacheEntry me = ctx.lookupEntry(k);
        EntryView.ReadEntryView view = me.isNull() ? EntryViews.noValue(k, keyDataConversion) : EntryViews.readOnly(me, keyDataConversion, valueDataConversion);
        Object ret = snapshot(function.apply(view));
        retvals.add(skipStats ? ret : StatsEnvelope.create(ret, me.isNull()));
    }
    return retvals.stream();
}
Also used : ArrayList(java.util.ArrayList) InternalCacheEntry(org.infinispan.container.entries.InternalCacheEntry) CacheEntry(org.infinispan.container.entries.CacheEntry) DataConversion(org.infinispan.encoding.DataConversion) BiFunction(java.util.function.BiFunction) Function(java.util.function.Function) EntryView(org.infinispan.functional.EntryView) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) TxReadOnlyManyCommand(org.infinispan.commands.functional.TxReadOnlyManyCommand)

Aggregations

ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 BiFunction (java.util.function.BiFunction)1 Function (java.util.function.Function)1 TxReadOnlyManyCommand (org.infinispan.commands.functional.TxReadOnlyManyCommand)1 CacheEntry (org.infinispan.container.entries.CacheEntry)1 InternalCacheEntry (org.infinispan.container.entries.InternalCacheEntry)1 DataConversion (org.infinispan.encoding.DataConversion)1 EntryView (org.infinispan.functional.EntryView)1