Skip to content

Instantly share code, notes, and snippets.

@gurbuzali
Created January 7, 2015 19:26
Show Gist options
  • Save gurbuzali/95bf6ad0d415547a47d3 to your computer and use it in GitHub Desktop.
Save gurbuzali/95bf6ad0d415547a47d3 to your computer and use it in GitHub Desktop.
queue memory limit
public static void main(String[] args) {
Config config = new Config();
QueueConfig queueConfig = config.getQueueConfig("q");
QueueStoreConfig queueStoreConfig = new QueueStoreConfig();
queueStoreConfig.setEnabled(true);
queueStoreConfig.setProperty("memory-limit", "10");
queueStoreConfig.setStoreImplementation(new QueueStore() {
Map<Long, Object> map = new HashMap();
@Override
public void store(Long key, Object value) {
System.err.println("store key: " + key + " val: " + value);
map.put(key, value);
}
@Override
public void storeAll(Map map) {
Set<Map.Entry<Long, Object>> entrySet = map.entrySet();
for (Map.Entry<Long, Object> entry : entrySet) {
store(entry.getKey(), entry.getValue());
}
}
@Override
public void delete(Long key) {
System.err.println("delete key: " + key);
map.remove(key);
}
@Override
public void deleteAll(Collection keys) {
for (Object key : keys) {
delete((Long)key);
}
}
@Override
public Object load(Long key) {
System.err.println("load key: " + key);
return map.get(key);
}
@Override
public Map loadAll(Collection keys) {
HashMap map = new HashMap();
for (Object key : keys) {
map.put(key, load((Long)key));
}
return map;
}
@Override
public Set<Long> loadAllKeys() {
return map.keySet();
}
});
queueConfig.setQueueStoreConfig(queueStoreConfig);
HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
IQueue<Object> q = instance.getQueue("q");
for (int i = 0; i < 11; i++) {
q.offer(i);
}
for (int i = 0; i < 11; i++) {
q.poll();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment