All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.hotrod.event.impl.CounterEventDispatcher Maven / Gradle / Ivy

There is a newer version: 14.0.32.Final
Show 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));
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy