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

kz.greetgo.logging.zookeeper.config.EventConfigStorageAbstract Maven / Gradle / Ivy

There is a newer version: 0.2.0
Show newest version
package kz.greetgo.logging.zookeeper.config;

import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;

public abstract class EventConfigStorageAbstract implements EventConfigStorage {

  private final ConcurrentHashMap map = new ConcurrentHashMap<>();

  private final AtomicLong nextId = new AtomicLong(1);

  @Override
  public EventRegistration addEventHandler(ConfigEventHandler configEventHandler) {
    final long id = nextId.getAndIncrement();
    map.put(id, configEventHandler);
    return () -> map.remove(id);
  }

  protected void fireConfigEventHandler(String path, ConfigEventType type) {
    for (ConfigEventHandler configEventHandler : new ArrayList<>(map.values())) {
      configEventHandler.configEventHappened(path, type);
    }
  }

  @Override
  public void close() {
    map.clear();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy