use of org.infinispan.notifications.cachelistener.event.impl.EventImpl in project infinispan by infinispan.
the class StateReceiverTest method createEventImpl.
private EventImpl createEventImpl(int topologyId, int numberOfNodes, Event.Type type) {
EventImpl event = EventImpl.createEvent(null, type);
ConsistentHash hash = createConsistentHash(numberOfNodes);
event.setReadConsistentHashAtEnd(hash);
event.setWriteConsistentHashAtEnd(hash);
event.setNewTopologyId(topologyId);
event.setPre(true);
return event;
}
use of org.infinispan.notifications.cachelistener.event.impl.EventImpl in project infinispan by infinispan.
the class CacheNotifierImpl method raiseEventForInitialTransfer.
private CompletionStage<Void> raiseEventForInitialTransfer(UUID identifier, CacheEntry entry, boolean clustered, Function<Object, Object> kc, Function<Object, Object> kv) {
EventImpl preEvent;
if (kc == null)
kc = Function.identity();
if (kv == null)
kv = Function.identity();
if (clustered) {
// In clustered mode we only send post event
preEvent = null;
} else {
preEvent = EventImpl.createEvent(cache.wired(), CACHE_ENTRY_CREATED);
preEvent.setKey(kc.apply(entry.getKey()));
preEvent.setPre(true);
preEvent.setCurrentState(true);
}
EventImpl postEvent = EventImpl.createEvent(cache.wired(), CACHE_ENTRY_CREATED);
postEvent.setKey(kc.apply(entry.getKey()));
postEvent.setValue(kv.apply(entry.getValue()));
postEvent.setMetadata(entry.getMetadata());
postEvent.setPre(false);
postEvent.setCurrentState(true);
AggregateCompletionStage aggregateCompletionStage = null;
for (CacheEntryListenerInvocation<K, V> invocation : cacheEntryCreatedListeners) {
// Now notify all our methods of the creates
if (invocation.getIdentifier() == identifier) {
if (preEvent != null) {
// Non clustered notifications are done twice
aggregateCompletionStage = composeStageIfNeeded(aggregateCompletionStage, invocation.invokeNoChecks(new EventWrapper<>(null, preEvent, null), true, true, false));
}
aggregateCompletionStage = composeStageIfNeeded(aggregateCompletionStage, invocation.invokeNoChecks(new EventWrapper<>(null, postEvent, null), true, true, false));
}
}
return aggregateCompletionStage != null ? aggregateCompletionStage.freeze() : CompletableFutures.completedNull();
}
use of org.infinispan.notifications.cachelistener.event.impl.EventImpl in project infinispan by infinispan.
the class ClusterEvent method fromEvent.
public static <K, V> ClusterEvent<K, V> fromEvent(CacheEntryEvent<K, V> event) {
if (event instanceof ClusterEvent) {
return (ClusterEvent<K, V>) event;
}
V oldValue = null;
Type eventType = event.getType();
boolean commandRetried;
switch(eventType) {
case CACHE_ENTRY_REMOVED:
oldValue = ((CacheEntryRemovedEvent<K, V>) event).getOldValue();
commandRetried = ((CacheEntryRemovedEvent<K, V>) event).isCommandRetried();
break;
case CACHE_ENTRY_CREATED:
commandRetried = ((CacheEntryCreatedEvent<K, V>) event).isCommandRetried();
break;
case CACHE_ENTRY_MODIFIED:
commandRetried = ((CacheEntryModifiedEvent<K, V>) event).isCommandRetried();
break;
case CACHE_ENTRY_EXPIRED:
// Expired doesn't have a retry
commandRetried = false;
break;
default:
throw new IllegalArgumentException("Cluster Event can only be created from a CacheEntryRemoved, CacheEntryCreated or CacheEntryModified event!");
}
GlobalTransaction transaction = ((TransactionalEvent) event).getGlobalTransaction();
Metadata metadata = null;
if (event instanceof EventImpl) {
metadata = ((EventImpl) event).getMetadata();
}
ClusterEvent<K, V> clusterEvent = new ClusterEvent<>(event.getKey(), event.getValue(), oldValue, metadata, eventType, event.getCache().getCacheManager().getAddress(), transaction, commandRetried);
clusterEvent.cache = event.getCache();
return clusterEvent;
}
Aggregations