com.maxifier.mxcache.impl.caches.def.ObjectLongWeakTroveStorage Maven / Gradle / Ivy
/*
* 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.*;
/**
* THIS IS GENERATED CLASS! DON'T EDIT IT MANUALLY!
*
* GENERATED FROM O2PWeakTroveStorage.template
*
* @author Andrey Yakoushin ([email protected])
* @author Alexander Kochurov ([email protected])
*/
public class ObjectLongWeakTroveStorage extends ObjectLongTroveStorage {
private final List removed = Collections.synchronizedList(new ArrayList());
public ObjectLongWeakTroveStorage() {
}
public ObjectLongWeakTroveStorage(gnu.trove.strategy.HashingStrategy strategy) {
super(strategy);
}
private void cleanup() {
for(T t: removed) {
remove(t);
}
removed.clear();
}
@Override
public long load(T o) {
cleanup();
return super.load(o);
}
@Override
public void save(final T o, long t) {
cleanup();
o.setCallback(new Callback(o));
super.save(o, t);
}
private class Callback implements Runnable {
private final T o;
public Callback(T o) {
this.o = o;
}
@Override
public void run() {
removed.add(o);
}
}
}