kz.greetgo.logging.zookeeper.config.EventConfigStorageAbstract Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of greetgo-logging-zookeeper Show documentation
Show all versions of greetgo-logging-zookeeper Show documentation
Logging mechanism using in greetgo!
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();
}
}