Search in sources :

Example 16 with DataConversion

use of org.infinispan.encoding.DataConversion in project infinispan by infinispan.

the class CallInterceptor method visitReadWriteManyEntriesCommand.

@Override
public Object visitReadWriteManyEntriesCommand(InvocationContext ctx, ReadWriteManyEntriesCommand command) throws Throwable {
    Map<Object, Object> arguments = command.getArguments();
    List<Object> returns = new ArrayList<>(arguments.size());
    boolean skipStats = Param.StatisticsMode.isSkip(command.getParams());
    BiFunction biFunction = command.getBiFunction();
    DataConversion keyDataConversion = command.getKeyDataConversion();
    DataConversion valueDataConversion = command.getValueDataConversion();
    arguments.forEach((k, arg) -> {
        MVCCEntry entry = (MVCCEntry) ctx.lookupEntry(k);
        if (entry == null) {
            throw new IllegalStateException();
        }
        Object decodedArgument = valueDataConversion.fromStorage(arg);
        boolean exists = entry.getValue() != null;
        EntryViews.AccessLoggingReadWriteView view = EntryViews.readWrite(entry, keyDataConversion, valueDataConversion);
        Object r = snapshot(biFunction.apply(decodedArgument, view));
        returns.add(skipStats ? r : StatsEnvelope.create(r, entry, exists, view.isRead()));
        updateStoreFlags(command, entry);
    });
    return returns;
}
Also used : DataConversion(org.infinispan.encoding.DataConversion) BiFunction(java.util.function.BiFunction) EntryViews(org.infinispan.functional.impl.EntryViews) ArrayList(java.util.ArrayList) MVCCEntry(org.infinispan.container.entries.MVCCEntry)

Example 17 with DataConversion

use of org.infinispan.encoding.DataConversion 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);
}
Also used : Single(io.reactivex.rxjava3.core.Single) LogFactory(org.infinispan.util.logging.LogFactory) InvocationHelper(org.infinispan.cache.impl.InvocationHelper) CompletionStages(org.infinispan.util.concurrent.CompletionStages) EnumUtil(org.infinispan.commons.util.EnumUtil) Start(org.infinispan.factories.annotations.Start) FlagBitSets(org.infinispan.context.impl.FlagBitSets) Scopes(org.infinispan.factories.scopes.Scopes) InternalMetadataImpl(org.infinispan.metadata.impl.InternalMetadataImpl) StoreConfiguration(org.infinispan.configuration.cache.StoreConfiguration) InvocationContext(org.infinispan.context.InvocationContext) LocalTxInvocationContext(org.infinispan.context.impl.LocalTxInvocationContext) ComponentRef(org.infinispan.factories.impl.ComponentRef) AdvancedCache(org.infinispan.AdvancedCache) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) Log(org.infinispan.util.logging.Log) MarshallableEntry(org.infinispan.persistence.spi.MarshallableEntry) Scope(org.infinispan.factories.scopes.Scope) InvocationContextFactory(org.infinispan.context.InvocationContextFactory) Transaction(javax.transaction.Transaction) CommandsFactory(org.infinispan.commands.CommandsFactory) Flowable(io.reactivex.rxjava3.core.Flowable) MethodHandles(java.lang.invoke.MethodHandles) Publisher(org.reactivestreams.Publisher) Util(org.infinispan.commons.util.Util) Completable(io.reactivex.rxjava3.core.Completable) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Inject(org.infinispan.factories.annotations.Inject) CompletionStage(java.util.concurrent.CompletionStage) LocalTransaction(org.infinispan.transaction.impl.LocalTransaction) TransactionCoordinator(org.infinispan.transaction.impl.TransactionCoordinator) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand) Configuration(org.infinispan.configuration.cache.Configuration) DataConversion(org.infinispan.encoding.DataConversion) TransactionManager(javax.transaction.TransactionManager) FakeJTATransaction(org.infinispan.transaction.impl.FakeJTATransaction) TransactionTable(org.infinispan.transaction.impl.TransactionTable) TimeService(org.infinispan.commons.time.TimeService) PersistenceException(org.infinispan.persistence.spi.PersistenceException) Transaction(javax.transaction.Transaction) LocalTransaction(org.infinispan.transaction.impl.LocalTransaction) FakeJTATransaction(org.infinispan.transaction.impl.FakeJTATransaction) LocalTransaction(org.infinispan.transaction.impl.LocalTransaction) FakeJTATransaction(org.infinispan.transaction.impl.FakeJTATransaction) InternalMetadataImpl(org.infinispan.metadata.impl.InternalMetadataImpl) LocalTxInvocationContext(org.infinispan.context.impl.LocalTxInvocationContext) InvocationContext(org.infinispan.context.InvocationContext) LocalTxInvocationContext(org.infinispan.context.impl.LocalTxInvocationContext) PersistenceException(org.infinispan.persistence.spi.PersistenceException) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand)

Example 18 with DataConversion

use of org.infinispan.encoding.DataConversion in project infinispan by infinispan.

the class CacheNotifierImpl method registerClusterListeners.

private <C> CompletionStage<Void> registerClusterListeners(List<Address> members, UUID generatedId, Address ourAddress, CacheEventFilter<? super K, ? super V> filter, CacheEventConverter<? super K, ? super V, C> converter, Listener l, Object listener, DataConversion keyDataConversion, DataConversion valueDataConversion, boolean useStorageFormat) {
    if (log.isTraceEnabled()) {
        log.tracef("Replicating cluster listener to other nodes %s for cluster listener with id %s", members, generatedId);
    }
    ClusterListenerReplicateCallable<K, V> callable = new ClusterListenerReplicateCallable(cache.wired().getName(), generatedId, ourAddress, filter, converter, l.sync(), findListenerCallbacks(listener), keyDataConversion, valueDataConversion, useStorageFormat);
    TriConsumer<Address, Void, Throwable> handleSuspect = (a, ignore, t) -> {
        if (t != null && !(t instanceof SuspectException)) {
            log.debugf(t, "Address: %s encountered an exception while adding cluster listener", a);
            throw new CacheListenerException(t);
        }
    };
    // Send to all nodes but ours
    CompletionStage<Void> completionStage = clusterExecutor.filterTargets(a -> !ourAddress.equals(a)).submitConsumer(callable, handleSuspect);
    // the listener - unfortunately if there are no nodes it throws a SuspectException, so we ignore that
    return completionStage.thenCompose(v -> clusterExecutor.filterTargets(a -> !members.contains(a) && !a.equals(ourAddress)).submitConsumer(callable, handleSuspect).exceptionally(t -> {
        // Ignore any suspect exception
        if (!(t instanceof SuspectException)) {
            throw new CacheListenerException(t);
        }
        return null;
    }));
}
Also used : WriteCommand(org.infinispan.commands.write.WriteCommand) LogFactory(org.infinispan.util.logging.LogFactory) CacheListenerException(org.infinispan.commons.CacheListenerException) Wrapper(org.infinispan.commons.dataconversion.Wrapper) PartitionStatusChanged(org.infinispan.notifications.cachelistener.annotation.PartitionStatusChanged) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) PersistenceAvailabilityChanged(org.infinispan.notifications.cachelistener.annotation.PersistenceAvailabilityChanged) Scopes(org.infinispan.factories.scopes.Scopes) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) CONTAINER(org.infinispan.util.logging.Log.CONTAINER) AdvancedCache(org.infinispan.AdvancedCache) CACHE_ENTRY_INVALIDATED(org.infinispan.notifications.cachelistener.event.Event.Type.CACHE_ENTRY_INVALIDATED) TxInvocationContext(org.infinispan.context.impl.TxInvocationContext) CacheEventFilterAsKeyValueFilter(org.infinispan.notifications.cachelistener.filter.CacheEventFilterAsKeyValueFilter) Map(java.util.Map) Transaction(javax.transaction.Transaction) Listener(org.infinispan.notifications.Listener) ClusterEventManager(org.infinispan.notifications.cachelistener.cluster.ClusterEventManager) ConsistentHash(org.infinispan.distribution.ch.ConsistentHash) CacheEntryPassivatedEvent(org.infinispan.notifications.cachelistener.event.CacheEntryPassivatedEvent) Set(java.util.Set) TransactionCompletedEvent(org.infinispan.notifications.cachelistener.event.TransactionCompletedEvent) CacheTopology(org.infinispan.topology.CacheTopology) CACHE_ENTRY_PASSIVATED(org.infinispan.notifications.cachelistener.event.Event.Type.CACHE_ENTRY_PASSIVATED) CacheEntryLoadedEvent(org.infinispan.notifications.cachelistener.event.CacheEntryLoadedEvent) CACHE_ENTRY_MODIFIED(org.infinispan.notifications.cachelistener.event.Event.Type.CACHE_ENTRY_MODIFIED) CacheEntryCreated(org.infinispan.notifications.cachelistener.annotation.CacheEntryCreated) CacheEventFilterConverter(org.infinispan.notifications.cachelistener.filter.CacheEventFilterConverter) CacheIntermediatePublisher(org.infinispan.stream.impl.CacheIntermediatePublisher) CompletionStage(java.util.concurrent.CompletionStage) TRANSACTION_REGISTERED(org.infinispan.notifications.cachelistener.event.Event.Type.TRANSACTION_REGISTERED) DataConversion(org.infinispan.encoding.DataConversion) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) AvailabilityMode(org.infinispan.partitionhandling.AvailabilityMode) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) CacheEntryRemoved(org.infinispan.notifications.cachelistener.annotation.CacheEntryRemoved) TopologyChanged(org.infinispan.notifications.cachelistener.annotation.TopologyChanged) CacheEventFilterConverterAsKeyValueFilterConverter(org.infinispan.notifications.cachelistener.filter.CacheEventFilterConverterAsKeyValueFilterConverter) CacheEntryPassivated(org.infinispan.notifications.cachelistener.annotation.CacheEntryPassivated) CacheEntryInvalidated(org.infinispan.notifications.cachelistener.annotation.CacheEntryInvalidated) CacheEntriesEvictedEvent(org.infinispan.notifications.cachelistener.event.CacheEntriesEvictedEvent) CacheEntryVisitedEvent(org.infinispan.notifications.cachelistener.event.CacheEntryVisitedEvent) CACHE_ENTRY_EXPIRED(org.infinispan.notifications.cachelistener.event.Event.Type.CACHE_ENTRY_EXPIRED) PersistenceAvailabilityChangedEvent(org.infinispan.notifications.cachelistener.event.PersistenceAvailabilityChangedEvent) AbstractListenerImpl(org.infinispan.notifications.impl.AbstractListenerImpl) SegmentPublisherSupplier(org.infinispan.reactive.publisher.impl.SegmentPublisherSupplier) EnumUtil(org.infinispan.commons.util.EnumUtil) ArrayList(java.util.ArrayList) Start(org.infinispan.factories.annotations.Start) PARTITION_STATUS_CHANGED(org.infinispan.notifications.cachelistener.event.Event.Type.PARTITION_STATUS_CHANGED) CacheFilters(org.infinispan.filter.CacheFilters) CACHE_ENTRY_REMOVED(org.infinispan.notifications.cachelistener.event.Event.Type.CACHE_ENTRY_REMOVED) EventType(org.infinispan.notifications.cachelistener.filter.EventType) ClusterExecutor(org.infinispan.manager.ClusterExecutor) TransactionCompleted(org.infinispan.notifications.cachelistener.annotation.TransactionCompleted) PublisherTransformers(org.infinispan.reactive.publisher.PublisherTransformers) Address(org.infinispan.remoting.transport.Address) Transcoder(org.infinispan.commons.dataconversion.Transcoder) CACHE_ENTRY_CREATED(org.infinispan.notifications.cachelistener.event.Event.Type.CACHE_ENTRY_CREATED) InternalEntryFactory(org.infinispan.container.impl.InternalEntryFactory) CacheEntry(org.infinispan.container.entries.CacheEntry) CacheEventFilter(org.infinispan.notifications.cachelistener.filter.CacheEventFilter) ClusterListenerReplicateCallable(org.infinispan.notifications.cachelistener.cluster.ClusterListenerReplicateCallable) TOPOLOGY_CHANGED(org.infinispan.notifications.cachelistener.event.Event.Type.TOPOLOGY_CHANGED) Inject(org.infinispan.factories.annotations.Inject) PERSISTENCE_AVAILABILITY_CHANGED(org.infinispan.notifications.cachelistener.event.Event.Type.PERSISTENCE_AVAILABILITY_CHANGED) CacheEntryInvalidatedEvent(org.infinispan.notifications.cachelistener.event.CacheEntryInvalidatedEvent) ClusterEvent(org.infinispan.notifications.cachelistener.cluster.ClusterEvent) CacheEntryEvent(org.infinispan.notifications.cachelistener.event.CacheEntryEvent) CacheEventConverterAsConverter(org.infinispan.notifications.cachelistener.filter.CacheEventConverterAsConverter) GlobalTransaction(org.infinispan.transaction.xa.GlobalTransaction) Event(org.infinispan.notifications.cachelistener.event.Event) CACHE_ENTRY_LOADED(org.infinispan.notifications.cachelistener.event.Event.Type.CACHE_ENTRY_LOADED) DataRehashedEvent(org.infinispan.notifications.cachelistener.event.DataRehashedEvent) SuspectException(org.infinispan.remoting.transport.jgroups.SuspectException) AggregateCompletionStage(org.infinispan.util.concurrent.AggregateCompletionStage) TransactionRegisteredEvent(org.infinispan.notifications.cachelistener.event.TransactionRegisteredEvent) ClusterListenerRemoveCallable(org.infinispan.notifications.cachelistener.cluster.ClusterListenerRemoveCallable) MapOperation(org.infinispan.stream.impl.intops.object.MapOperation) CACHE_ENTRY_EVICTED(org.infinispan.notifications.cachelistener.event.Event.Type.CACHE_ENTRY_EVICTED) CacheEntryModifiedEvent(org.infinispan.notifications.cachelistener.event.CacheEntryModifiedEvent) IndexedFilter(org.infinispan.notifications.cachelistener.filter.IndexedFilter) InvocationContext(org.infinispan.context.InvocationContext) ComponentRef(org.infinispan.factories.impl.ComponentRef) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) CacheEntryRemovedEvent(org.infinispan.notifications.cachelistener.event.CacheEntryRemovedEvent) DeliveryGuarantee(org.infinispan.reactive.publisher.impl.DeliveryGuarantee) FilterOperation(org.infinispan.stream.impl.intops.object.FilterOperation) Scope(org.infinispan.factories.scopes.Scope) TriConsumer(org.infinispan.util.function.TriConsumer) CACHE_ENTRY_VISITED(org.infinispan.notifications.cachelistener.event.Event.Type.CACHE_ENTRY_VISITED) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CacheEventConverter(org.infinispan.notifications.cachelistener.filter.CacheEventConverter) UUID(java.util.UUID) CacheEntryExpired(org.infinispan.notifications.cachelistener.annotation.CacheEntryExpired) Objects(java.util.Objects) List(java.util.List) TRANSACTION_COMPLETED(org.infinispan.notifications.cachelistener.event.Event.Type.TRANSACTION_COMPLETED) ClusterPublisherManager(org.infinispan.reactive.publisher.impl.ClusterPublisherManager) Annotation(java.lang.annotation.Annotation) TransactionRegistered(org.infinispan.notifications.cachelistener.annotation.TransactionRegistered) FilterIndexingServiceProvider(org.infinispan.notifications.cachelistener.filter.FilterIndexingServiceProvider) EventImpl(org.infinispan.notifications.cachelistener.event.impl.EventImpl) CacheEntryLoaded(org.infinispan.notifications.cachelistener.annotation.CacheEntryLoaded) FlagAffectedCommand(org.infinispan.commands.FlagAffectedCommand) ClusterCacheNotifier(org.infinispan.notifications.cachelistener.cluster.ClusterCacheNotifier) DataRehashed(org.infinispan.notifications.cachelistener.annotation.DataRehashed) CommandInvocationId(org.infinispan.commands.CommandInvocationId) ServiceFinder(org.infinispan.commons.util.ServiceFinder) HashMap(java.util.HashMap) Metadata(org.infinispan.metadata.Metadata) Function(java.util.function.Function) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) FlagBitSets(org.infinispan.context.impl.FlagBitSets) DATA_REHASHED(org.infinispan.notifications.cachelistener.event.Event.Type.DATA_REHASHED) MediaType(org.infinispan.commons.dataconversion.MediaType) CacheEntryVisited(org.infinispan.notifications.cachelistener.annotation.CacheEntryVisited) CacheEntryExpiredEvent(org.infinispan.notifications.cachelistener.event.CacheEntryExpiredEvent) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) IntermediateOperation(org.infinispan.stream.impl.intops.IntermediateOperation) CacheEntryModified(org.infinispan.notifications.cachelistener.annotation.CacheEntryModified) Log(org.infinispan.util.logging.Log) SegmentSpecificCommand(org.infinispan.commands.SegmentSpecificCommand) EncoderRegistry(org.infinispan.marshall.core.EncoderRegistry) CACHE_ENTRY_ACTIVATED(org.infinispan.notifications.cachelistener.event.Event.Type.CACHE_ENTRY_ACTIVATED) ClusteringDependentLogic(org.infinispan.interceptors.locking.ClusteringDependentLogic) CacheEntriesEvicted(org.infinispan.notifications.cachelistener.annotation.CacheEntriesEvicted) CacheException(org.infinispan.commons.CacheException) Flowable(io.reactivex.rxjava3.core.Flowable) DelegatingCacheEntryListenerInvocation(org.infinispan.notifications.cachelistener.filter.DelegatingCacheEntryListenerInvocation) ListenerInvocation(org.infinispan.notifications.impl.ListenerInvocation) Util(org.infinispan.commons.util.Util) CacheEntryActivated(org.infinispan.notifications.cachelistener.annotation.CacheEntryActivated) PartitionStatusChangedEvent(org.infinispan.notifications.cachelistener.event.PartitionStatusChangedEvent) RpcManager(org.infinispan.remoting.rpc.RpcManager) Completable(io.reactivex.rxjava3.core.Completable) CacheEntryActivatedEvent(org.infinispan.notifications.cachelistener.event.CacheEntryActivatedEvent) RemoteClusterListener(org.infinispan.notifications.cachelistener.cluster.RemoteClusterListener) TopologyChangedEvent(org.infinispan.notifications.cachelistener.event.TopologyChangedEvent) Status(javax.transaction.Status) CacheMode(org.infinispan.configuration.cache.CacheMode) EncoderEntryMapper(org.infinispan.cache.impl.EncoderEntryMapper) Configuration(org.infinispan.configuration.cache.Configuration) TransactionManager(javax.transaction.TransactionManager) CacheEntryCreatedEvent(org.infinispan.notifications.cachelistener.event.CacheEntryCreatedEvent) CacheListenerException(org.infinispan.commons.CacheListenerException) Address(org.infinispan.remoting.transport.Address) ClusterListenerReplicateCallable(org.infinispan.notifications.cachelistener.cluster.ClusterListenerReplicateCallable) SuspectException(org.infinispan.remoting.transport.jgroups.SuspectException)

Example 19 with DataConversion

use of org.infinispan.encoding.DataConversion in project infinispan by infinispan.

the class CacheNotifierImpl method convertKey.

private K convertKey(CacheEntryListenerInvocation listenerInvocation, K key) {
    if (key == null)
        return null;
    DataConversion keyDataConversion = listenerInvocation.getKeyDataConversion();
    Wrapper wrp = keyDataConversion.getWrapper();
    Object unwrappedKey = keyDataConversion.getEncoder().fromStorage(wrp.unwrap(key));
    CacheEventFilter filter = listenerInvocation.getFilter();
    CacheEventConverter converter = listenerInvocation.getConverter();
    if (filter == null && converter == null) {
        if (listenerInvocation.useStorageFormat()) {
            return (K) unwrappedKey;
        }
        // If no filter is present, convert to the requested format directly
        return (K) keyDataConversion.fromStorage(key);
    }
    MediaType convertFormat = filter == null ? converter.format() : filter.format();
    if (listenerInvocation.useStorageFormat() || convertFormat == null) {
        // Filter will be run on the storage format, return the unwrapped key
        return (K) unwrappedKey;
    }
    // Filter has a specific format to run, convert to that format
    return (K) encoderRegistry.convert(unwrappedKey, keyDataConversion.getStorageMediaType(), convertFormat);
}
Also used : DataConversion(org.infinispan.encoding.DataConversion) Wrapper(org.infinispan.commons.dataconversion.Wrapper) CacheEventConverter(org.infinispan.notifications.cachelistener.filter.CacheEventConverter) CacheEventFilter(org.infinispan.notifications.cachelistener.filter.CacheEventFilter) MediaType(org.infinispan.commons.dataconversion.MediaType)

Example 20 with DataConversion

use of org.infinispan.encoding.DataConversion in project infinispan by infinispan.

the class CacheNotifierImpl method addFilteredListenerInternal.

private <C> CompletionStage<Void> addFilteredListenerInternal(Object listener, DataConversion keyDataConversion, DataConversion valueDataConversion, CacheEventFilter<? super K, ? super V> filter, CacheEventConverter<? super K, ? super V, C> converter, Set<Class<? extends Annotation>> filterAnnotations, boolean useStorageFormat) {
    final Listener l = testListenerClassValidity(listener.getClass());
    final UUID generatedId = Util.threadLocalRandomUUID();
    final CacheMode cacheMode = config.clustering().cacheMode();
    FilterIndexingServiceProvider indexingProvider = null;
    boolean foundMethods = false;
    // We use identity for null as this means it was invoked by a non encoder cache
    DataConversion keyConversion = keyDataConversion == null ? DataConversion.IDENTITY_KEY : keyDataConversion;
    DataConversion valueConversion = valueDataConversion == null ? DataConversion.IDENTITY_VALUE : valueDataConversion;
    if (filter instanceof IndexedFilter) {
        indexingProvider = findIndexingServiceProvider((IndexedFilter) filter);
        if (indexingProvider != null) {
            DelegatingCacheInvocationBuilder builder = new DelegatingCacheInvocationBuilder(indexingProvider);
            adjustCacheInvocationBuilder(builder, filter, converter, filterAnnotations, l, useStorageFormat, generatedId, keyConversion, valueConversion, null);
            foundMethods = validateAndAddFilterListenerInvocations(listener, builder, filterAnnotations);
            builder.registerListenerInvocations();
        }
    }
    if (indexingProvider == null) {
        CacheInvocationBuilder builder = new CacheInvocationBuilder();
        adjustCacheInvocationBuilder(builder, filter, converter, filterAnnotations, l, useStorageFormat, generatedId, keyConversion, valueConversion, null);
        foundMethods = validateAndAddFilterListenerInvocations(listener, builder, filterAnnotations);
    }
    CompletionStage<Void> stage = CompletableFutures.completedNull();
    if (foundMethods && l.clustered()) {
        if (l.observation() == Listener.Observation.PRE) {
            throw CONTAINER.clusterListenerRegisteredWithOnlyPreEvents(listener.getClass());
        } else if (cacheMode.isInvalidation()) {
            throw new UnsupportedOperationException("Cluster listeners cannot be used with Invalidation Caches!");
        } else if (clusterListenerOnPrimaryOnly()) {
            clusterListenerIDs.put(listener, generatedId);
            // This way we only retrieve members of the cache itself
            Address ourAddress = rpcManager.getAddress();
            List<Address> members = rpcManager.getMembers();
            // If we are the only member don't even worry about sending listeners
            if (members != null && members.size() > 1) {
                stage = registerClusterListeners(members, generatedId, ourAddress, filter, converter, l, listener, keyDataConversion, valueDataConversion, useStorageFormat);
            }
        }
    }
    // If we have a segment listener handler, it means we have to do initial state
    QueueingSegmentListener<K, V, ? extends Event<K, V>> handler = segmentHandler.remove(generatedId);
    if (handler != null) {
        if (log.isTraceEnabled()) {
            log.tracef("Listener %s requests initial state for cache", generatedId);
        }
        Collection<IntermediateOperation<?, ?, ?, ?>> intermediateOperations = new ArrayList<>();
        MediaType storage = valueConversion.getStorageMediaType();
        MediaType keyReq = keyConversion.getRequestMediaType();
        MediaType valueReq = valueConversion.getRequestMediaType();
        AdvancedCache advancedCache = cache.running();
        DataConversion chainedKeyDataConversion = advancedCache.getKeyDataConversion();
        DataConversion chainedValueDataConversion = advancedCache.getValueDataConversion();
        if (keyReq != null && valueReq != null) {
            chainedKeyDataConversion = chainedKeyDataConversion.withRequestMediaType(keyReq);
            chainedValueDataConversion = chainedValueDataConversion.withRequestMediaType(valueReq);
        }
        boolean hasFilter = false;
        MediaType filterMediaType = null;
        if (filter != null) {
            hasFilter = true;
            filterMediaType = useStorageFormat ? null : filter.format();
            if (filterMediaType == null) {
                // iterate in the storage format
                chainedKeyDataConversion = chainedKeyDataConversion.withRequestMediaType(storage);
                chainedValueDataConversion = chainedValueDataConversion.withRequestMediaType(storage);
            } else {
                // iterate in the filter format
                chainedKeyDataConversion = chainedKeyDataConversion.withRequestMediaType(filterMediaType);
                chainedValueDataConversion = chainedValueDataConversion.withRequestMediaType(filterMediaType);
            }
        }
        if (converter != null) {
            hasFilter = true;
            filterMediaType = useStorageFormat ? null : converter.format();
            if (filterMediaType == null) {
                // iterate in the storage format
                chainedKeyDataConversion = chainedKeyDataConversion.withRequestMediaType(storage);
                chainedValueDataConversion = chainedValueDataConversion.withRequestMediaType(storage);
            } else {
                // iterate in the filter format
                chainedKeyDataConversion = chainedKeyDataConversion.withRequestMediaType(filterMediaType);
                chainedValueDataConversion = chainedValueDataConversion.withRequestMediaType(filterMediaType);
            }
        }
        if (!Objects.equals(chainedKeyDataConversion, keyDataConversion) || !Objects.equals(chainedValueDataConversion, valueDataConversion)) {
            componentRegistry.wireDependencies(chainedKeyDataConversion, false);
            componentRegistry.wireDependencies(chainedValueDataConversion, false);
            intermediateOperations.add(new MapOperation<>(EncoderEntryMapper.newCacheEntryMapper(chainedKeyDataConversion, chainedValueDataConversion, entryFactory)));
        }
        if (filter instanceof CacheEventFilterConverter && (filter == converter || converter == null)) {
            intermediateOperations.add(new MapOperation<>(CacheFilters.converterToFunction(new CacheEventFilterConverterAsKeyValueFilterConverter<>((CacheEventFilterConverter<?, ?, ?>) filter))));
            intermediateOperations.add(new FilterOperation<>(CacheFilters.notNullCacheEntryPredicate()));
        } else {
            if (filter != null) {
                intermediateOperations.add(new FilterOperation<>(CacheFilters.predicate(new CacheEventFilterAsKeyValueFilter<>(filter))));
            }
            if (converter != null) {
                intermediateOperations.add(new MapOperation<>(CacheFilters.function(new CacheEventConverterAsConverter<>(converter))));
            }
        }
        boolean finalHasFilter = hasFilter;
        MediaType finalFilterMediaType = filterMediaType;
        Function<Object, Object> kc = k -> {
            if (!finalHasFilter)
                return k;
            if (finalFilterMediaType == null || useStorageFormat || keyReq == null) {
                return keyDataConversion.fromStorage(k);
            }
            return encoderRegistry.convert(k, finalFilterMediaType, keyDataConversion.getRequestMediaType());
        };
        Function<Object, Object> kv = v -> {
            if (!finalHasFilter)
                return v;
            if (finalFilterMediaType == null || useStorageFormat || valueReq == null) {
                return valueConversion.fromStorage(v);
            }
            return encoderRegistry.convert(v, finalFilterMediaType, valueConversion.getRequestMediaType());
        };
        stage = handlePublisher(stage, intermediateOperations, handler, generatedId, l, kc, kv);
    }
    return stage;
}
Also used : WriteCommand(org.infinispan.commands.write.WriteCommand) LogFactory(org.infinispan.util.logging.LogFactory) CacheListenerException(org.infinispan.commons.CacheListenerException) Wrapper(org.infinispan.commons.dataconversion.Wrapper) PartitionStatusChanged(org.infinispan.notifications.cachelistener.annotation.PartitionStatusChanged) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) PersistenceAvailabilityChanged(org.infinispan.notifications.cachelistener.annotation.PersistenceAvailabilityChanged) Scopes(org.infinispan.factories.scopes.Scopes) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) CONTAINER(org.infinispan.util.logging.Log.CONTAINER) AdvancedCache(org.infinispan.AdvancedCache) CACHE_ENTRY_INVALIDATED(org.infinispan.notifications.cachelistener.event.Event.Type.CACHE_ENTRY_INVALIDATED) TxInvocationContext(org.infinispan.context.impl.TxInvocationContext) CacheEventFilterAsKeyValueFilter(org.infinispan.notifications.cachelistener.filter.CacheEventFilterAsKeyValueFilter) Map(java.util.Map) Transaction(javax.transaction.Transaction) Listener(org.infinispan.notifications.Listener) ClusterEventManager(org.infinispan.notifications.cachelistener.cluster.ClusterEventManager) ConsistentHash(org.infinispan.distribution.ch.ConsistentHash) CacheEntryPassivatedEvent(org.infinispan.notifications.cachelistener.event.CacheEntryPassivatedEvent) Set(java.util.Set) TransactionCompletedEvent(org.infinispan.notifications.cachelistener.event.TransactionCompletedEvent) CacheTopology(org.infinispan.topology.CacheTopology) CACHE_ENTRY_PASSIVATED(org.infinispan.notifications.cachelistener.event.Event.Type.CACHE_ENTRY_PASSIVATED) CacheEntryLoadedEvent(org.infinispan.notifications.cachelistener.event.CacheEntryLoadedEvent) CACHE_ENTRY_MODIFIED(org.infinispan.notifications.cachelistener.event.Event.Type.CACHE_ENTRY_MODIFIED) CacheEntryCreated(org.infinispan.notifications.cachelistener.annotation.CacheEntryCreated) CacheEventFilterConverter(org.infinispan.notifications.cachelistener.filter.CacheEventFilterConverter) CacheIntermediatePublisher(org.infinispan.stream.impl.CacheIntermediatePublisher) CompletionStage(java.util.concurrent.CompletionStage) TRANSACTION_REGISTERED(org.infinispan.notifications.cachelistener.event.Event.Type.TRANSACTION_REGISTERED) DataConversion(org.infinispan.encoding.DataConversion) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) AvailabilityMode(org.infinispan.partitionhandling.AvailabilityMode) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) CacheEntryRemoved(org.infinispan.notifications.cachelistener.annotation.CacheEntryRemoved) TopologyChanged(org.infinispan.notifications.cachelistener.annotation.TopologyChanged) CacheEventFilterConverterAsKeyValueFilterConverter(org.infinispan.notifications.cachelistener.filter.CacheEventFilterConverterAsKeyValueFilterConverter) CacheEntryPassivated(org.infinispan.notifications.cachelistener.annotation.CacheEntryPassivated) CacheEntryInvalidated(org.infinispan.notifications.cachelistener.annotation.CacheEntryInvalidated) CacheEntriesEvictedEvent(org.infinispan.notifications.cachelistener.event.CacheEntriesEvictedEvent) CacheEntryVisitedEvent(org.infinispan.notifications.cachelistener.event.CacheEntryVisitedEvent) CACHE_ENTRY_EXPIRED(org.infinispan.notifications.cachelistener.event.Event.Type.CACHE_ENTRY_EXPIRED) PersistenceAvailabilityChangedEvent(org.infinispan.notifications.cachelistener.event.PersistenceAvailabilityChangedEvent) AbstractListenerImpl(org.infinispan.notifications.impl.AbstractListenerImpl) SegmentPublisherSupplier(org.infinispan.reactive.publisher.impl.SegmentPublisherSupplier) EnumUtil(org.infinispan.commons.util.EnumUtil) ArrayList(java.util.ArrayList) Start(org.infinispan.factories.annotations.Start) PARTITION_STATUS_CHANGED(org.infinispan.notifications.cachelistener.event.Event.Type.PARTITION_STATUS_CHANGED) CacheFilters(org.infinispan.filter.CacheFilters) CACHE_ENTRY_REMOVED(org.infinispan.notifications.cachelistener.event.Event.Type.CACHE_ENTRY_REMOVED) EventType(org.infinispan.notifications.cachelistener.filter.EventType) ClusterExecutor(org.infinispan.manager.ClusterExecutor) TransactionCompleted(org.infinispan.notifications.cachelistener.annotation.TransactionCompleted) PublisherTransformers(org.infinispan.reactive.publisher.PublisherTransformers) Address(org.infinispan.remoting.transport.Address) Transcoder(org.infinispan.commons.dataconversion.Transcoder) CACHE_ENTRY_CREATED(org.infinispan.notifications.cachelistener.event.Event.Type.CACHE_ENTRY_CREATED) InternalEntryFactory(org.infinispan.container.impl.InternalEntryFactory) CacheEntry(org.infinispan.container.entries.CacheEntry) CacheEventFilter(org.infinispan.notifications.cachelistener.filter.CacheEventFilter) ClusterListenerReplicateCallable(org.infinispan.notifications.cachelistener.cluster.ClusterListenerReplicateCallable) TOPOLOGY_CHANGED(org.infinispan.notifications.cachelistener.event.Event.Type.TOPOLOGY_CHANGED) Inject(org.infinispan.factories.annotations.Inject) PERSISTENCE_AVAILABILITY_CHANGED(org.infinispan.notifications.cachelistener.event.Event.Type.PERSISTENCE_AVAILABILITY_CHANGED) CacheEntryInvalidatedEvent(org.infinispan.notifications.cachelistener.event.CacheEntryInvalidatedEvent) ClusterEvent(org.infinispan.notifications.cachelistener.cluster.ClusterEvent) CacheEntryEvent(org.infinispan.notifications.cachelistener.event.CacheEntryEvent) CacheEventConverterAsConverter(org.infinispan.notifications.cachelistener.filter.CacheEventConverterAsConverter) GlobalTransaction(org.infinispan.transaction.xa.GlobalTransaction) Event(org.infinispan.notifications.cachelistener.event.Event) CACHE_ENTRY_LOADED(org.infinispan.notifications.cachelistener.event.Event.Type.CACHE_ENTRY_LOADED) DataRehashedEvent(org.infinispan.notifications.cachelistener.event.DataRehashedEvent) SuspectException(org.infinispan.remoting.transport.jgroups.SuspectException) AggregateCompletionStage(org.infinispan.util.concurrent.AggregateCompletionStage) TransactionRegisteredEvent(org.infinispan.notifications.cachelistener.event.TransactionRegisteredEvent) ClusterListenerRemoveCallable(org.infinispan.notifications.cachelistener.cluster.ClusterListenerRemoveCallable) MapOperation(org.infinispan.stream.impl.intops.object.MapOperation) CACHE_ENTRY_EVICTED(org.infinispan.notifications.cachelistener.event.Event.Type.CACHE_ENTRY_EVICTED) CacheEntryModifiedEvent(org.infinispan.notifications.cachelistener.event.CacheEntryModifiedEvent) IndexedFilter(org.infinispan.notifications.cachelistener.filter.IndexedFilter) InvocationContext(org.infinispan.context.InvocationContext) ComponentRef(org.infinispan.factories.impl.ComponentRef) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) CacheEntryRemovedEvent(org.infinispan.notifications.cachelistener.event.CacheEntryRemovedEvent) DeliveryGuarantee(org.infinispan.reactive.publisher.impl.DeliveryGuarantee) FilterOperation(org.infinispan.stream.impl.intops.object.FilterOperation) Scope(org.infinispan.factories.scopes.Scope) TriConsumer(org.infinispan.util.function.TriConsumer) CACHE_ENTRY_VISITED(org.infinispan.notifications.cachelistener.event.Event.Type.CACHE_ENTRY_VISITED) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CacheEventConverter(org.infinispan.notifications.cachelistener.filter.CacheEventConverter) UUID(java.util.UUID) CacheEntryExpired(org.infinispan.notifications.cachelistener.annotation.CacheEntryExpired) Objects(java.util.Objects) List(java.util.List) TRANSACTION_COMPLETED(org.infinispan.notifications.cachelistener.event.Event.Type.TRANSACTION_COMPLETED) ClusterPublisherManager(org.infinispan.reactive.publisher.impl.ClusterPublisherManager) Annotation(java.lang.annotation.Annotation) TransactionRegistered(org.infinispan.notifications.cachelistener.annotation.TransactionRegistered) FilterIndexingServiceProvider(org.infinispan.notifications.cachelistener.filter.FilterIndexingServiceProvider) EventImpl(org.infinispan.notifications.cachelistener.event.impl.EventImpl) CacheEntryLoaded(org.infinispan.notifications.cachelistener.annotation.CacheEntryLoaded) FlagAffectedCommand(org.infinispan.commands.FlagAffectedCommand) ClusterCacheNotifier(org.infinispan.notifications.cachelistener.cluster.ClusterCacheNotifier) DataRehashed(org.infinispan.notifications.cachelistener.annotation.DataRehashed) CommandInvocationId(org.infinispan.commands.CommandInvocationId) ServiceFinder(org.infinispan.commons.util.ServiceFinder) HashMap(java.util.HashMap) Metadata(org.infinispan.metadata.Metadata) Function(java.util.function.Function) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) FlagBitSets(org.infinispan.context.impl.FlagBitSets) DATA_REHASHED(org.infinispan.notifications.cachelistener.event.Event.Type.DATA_REHASHED) MediaType(org.infinispan.commons.dataconversion.MediaType) CacheEntryVisited(org.infinispan.notifications.cachelistener.annotation.CacheEntryVisited) CacheEntryExpiredEvent(org.infinispan.notifications.cachelistener.event.CacheEntryExpiredEvent) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) IntermediateOperation(org.infinispan.stream.impl.intops.IntermediateOperation) CacheEntryModified(org.infinispan.notifications.cachelistener.annotation.CacheEntryModified) Log(org.infinispan.util.logging.Log) SegmentSpecificCommand(org.infinispan.commands.SegmentSpecificCommand) EncoderRegistry(org.infinispan.marshall.core.EncoderRegistry) CACHE_ENTRY_ACTIVATED(org.infinispan.notifications.cachelistener.event.Event.Type.CACHE_ENTRY_ACTIVATED) ClusteringDependentLogic(org.infinispan.interceptors.locking.ClusteringDependentLogic) CacheEntriesEvicted(org.infinispan.notifications.cachelistener.annotation.CacheEntriesEvicted) CacheException(org.infinispan.commons.CacheException) Flowable(io.reactivex.rxjava3.core.Flowable) DelegatingCacheEntryListenerInvocation(org.infinispan.notifications.cachelistener.filter.DelegatingCacheEntryListenerInvocation) ListenerInvocation(org.infinispan.notifications.impl.ListenerInvocation) Util(org.infinispan.commons.util.Util) CacheEntryActivated(org.infinispan.notifications.cachelistener.annotation.CacheEntryActivated) PartitionStatusChangedEvent(org.infinispan.notifications.cachelistener.event.PartitionStatusChangedEvent) RpcManager(org.infinispan.remoting.rpc.RpcManager) Completable(io.reactivex.rxjava3.core.Completable) CacheEntryActivatedEvent(org.infinispan.notifications.cachelistener.event.CacheEntryActivatedEvent) RemoteClusterListener(org.infinispan.notifications.cachelistener.cluster.RemoteClusterListener) TopologyChangedEvent(org.infinispan.notifications.cachelistener.event.TopologyChangedEvent) Status(javax.transaction.Status) CacheMode(org.infinispan.configuration.cache.CacheMode) EncoderEntryMapper(org.infinispan.cache.impl.EncoderEntryMapper) Configuration(org.infinispan.configuration.cache.Configuration) TransactionManager(javax.transaction.TransactionManager) CacheEntryCreatedEvent(org.infinispan.notifications.cachelistener.event.CacheEntryCreatedEvent) Listener(org.infinispan.notifications.Listener) RemoteClusterListener(org.infinispan.notifications.cachelistener.cluster.RemoteClusterListener) Address(org.infinispan.remoting.transport.Address) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) CacheMode(org.infinispan.configuration.cache.CacheMode) DataConversion(org.infinispan.encoding.DataConversion) MediaType(org.infinispan.commons.dataconversion.MediaType) AdvancedCache(org.infinispan.AdvancedCache) UUID(java.util.UUID) IntermediateOperation(org.infinispan.stream.impl.intops.IntermediateOperation) IndexedFilter(org.infinispan.notifications.cachelistener.filter.IndexedFilter) FilterIndexingServiceProvider(org.infinispan.notifications.cachelistener.filter.FilterIndexingServiceProvider) CacheEventFilterConverter(org.infinispan.notifications.cachelistener.filter.CacheEventFilterConverter)

Aggregations

DataConversion (org.infinispan.encoding.DataConversion)41 MVCCEntry (org.infinispan.container.entries.MVCCEntry)9 KeyPartitioner (org.infinispan.distribution.ch.KeyPartitioner)9 ArrayList (java.util.ArrayList)8 AdvancedCache (org.infinispan.AdvancedCache)8 Util (org.infinispan.commons.util.Util)8 EnumUtil (org.infinispan.commons.util.EnumUtil)7 InvocationContext (org.infinispan.context.InvocationContext)7 Completable (io.reactivex.rxjava3.core.Completable)6 Flowable (io.reactivex.rxjava3.core.Flowable)6 Set (java.util.Set)6 CompletionStage (java.util.concurrent.CompletionStage)6 Function (java.util.function.Function)6 Transaction (javax.transaction.Transaction)6 TransactionManager (javax.transaction.TransactionManager)6 MediaType (org.infinispan.commons.dataconversion.MediaType)6 TimeService (org.infinispan.commons.time.TimeService)6 Configuration (org.infinispan.configuration.cache.Configuration)6 CacheEntry (org.infinispan.container.entries.CacheEntry)6 FlagBitSets (org.infinispan.context.impl.FlagBitSets)6