com.bagri.server.hazelcast.store.system.ConfigCacheStore Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bagri-server-hazelcast Show documentation
Show all versions of bagri-server-hazelcast Show documentation
Bagri DB Cache: Hazelcast implementation
The newest version!
package com.bagri.server.hazelcast.store.system;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.bagri.server.hazelcast.config.EntityConfig;
public abstract class ConfigCacheStore {
protected final Logger logger = LoggerFactory.getLogger(getClass());
protected EntityConfig cfg;
protected Map entities;
public void setEntityManagement(EntityConfig cfg) {
this.cfg = cfg;
entities = loadEntities();
}
abstract protected Map loadEntities();
abstract protected void storeEntities(Map entities);
public Map loadAll(Collection keys) {
logger.trace("loadAll.enter; keys: {}", keys);
Map result = new HashMap(keys.size());
for (K key: keys) {
V value = entities.get(key);
if (value != null) {
result.put(key, value);
}
}
logger.trace("loadAll.exit; returning {} entities", result.size());
return result;
}
public V load(K key) {
logger.trace("load.enter; key: {}", key);
return entities.get(key);
}
public Set loadAllKeys() {
logger.trace("loadAllKeys.enter;");
Set result = new HashSet(entities.keySet());
logger.trace("loadAllKeys.exit; returning {} keys", result.size());
return result;
}
public void store(K key, V value) {
logger.trace("store.enter; key: {}; value: {}", key, value);
entities.put(key, value);
storeEntities(entities);
}
public void storeAll(Map map) {
logger.trace("storeAll.enter; map: {}", map);
entities.putAll(map);
storeEntities(entities);
}
public void delete(K key) {
logger.trace("delete.enter; key: {}", key);
if (entities.remove(key) != null) {
storeEntities(entities);
}
}
public void deleteAll(Collection keys) {
logger.trace("deleteAll.enter; keys: {}", keys);
boolean changed = false;
for (K key: keys) {
if (entities.remove(key) != null) {
changed = true;
}
}
if (changed) {
storeEntities(entities);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy