com.maxifier.mxcache.impl.caches.def.ObjectObjectWeakTroveStorage Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mxcache-runtime Show documentation
Show all versions of mxcache-runtime Show documentation
Constains all classes necessary for launching a MxCache-instrumentated application
/*
* Copyright (c) 2008-2014 Maxifier Ltd. All Rights Reserved.
*/
package com.maxifier.mxcache.impl.caches.def;
import com.maxifier.mxcache.transform.SmartReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* ObjectObjectWeakTroveStorage
*
* @author Andrey Yakoushin ([email protected])
* @author Alexander Kochurov ([email protected])
*/
public class ObjectObjectWeakTroveStorage extends ObjectObjectTroveStorage {
private final List removed = Collections.synchronizedList(new ArrayList());
public ObjectObjectWeakTroveStorage() {
}
private void cleanup() {
for(K k : removed) {
remove(k);
}
removed.clear();
}
@Override
public Object load(K o) {
cleanup();
return super.load(o);
}
@Override
public void save(final K o, V t) {
cleanup();
o.setCallback(new Callback(o));
super.save(o, t);
}
private class Callback implements Runnable {
private final K o;
public Callback(K o) {
this.o = o;
}
@Override
public void run() {
removed.add(o);
}
}
}