org.infinispan.client.hotrod.event.impl.CounterEventDispatcher Maven / Gradle / Ivy
package org.infinispan.client.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.client.hotrod.counter.impl.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));
}
}