org.infinispan.hotrod.event.impl.CounterEventDispatcher Maven / Gradle / Ivy
The newest version!
package org.infinispan.hotrod.event.impl;
import java.net.SocketAddress;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentMap;
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.infinispan.hotrod.impl.counter.HotRodCounterEvent;
public class CounterEventDispatcher extends EventDispatcher {
private final ConcurrentMap>> clientListeners;
private final Supplier> failover;
public CounterEventDispatcher(byte[] listenerId,
ConcurrentMap>> clientListeners,
SocketAddress address, Supplier> failover, Runnable cleanup) {
super("", null, listenerId, address, cleanup);
this.clientListeners = clientListeners;
this.failover = failover;
}
@Override
public CompletableFuture executeFailover() {
return failover.get();
}
@Override
protected void invokeEvent(HotRodCounterEvent event) {
if (log.isTraceEnabled()) {
log.tracef("Received counter event %s", event);
}
clientListeners.getOrDefault(event.getCounterName(), Collections.emptyList())
.parallelStream()
.forEach(handle -> handle.accept(event));
}
}