com.maxifier.mxcache.impl.caches.def.TupleBooleanWeakTroveStorage Maven / Gradle / Ivy
/*
* Copyright (c) 2008-2014 Maxifier Ltd. All Rights Reserved.
*/
package com.maxifier.mxcache.impl.caches.def;
import com.maxifier.mxcache.tuple.Tuple;
import com.maxifier.mxcache.transform.SmartReference;
import gnu.trove.strategy.HashingStrategy;
import java.util.*;
/**
* THIS IS GENERATED CLASS! DON'T EDIT IT MANUALLY!
*
* GENERATED FROM O2PTupleWeakTroveStorage.template
*
* @author Andrey Yakoushin ([email protected])
* @author Alexander Kochurov ([email protected])
*/
public class TupleBooleanWeakTroveStorage extends ObjectBooleanTroveStorage {
private final List removed = Collections.synchronizedList(new ArrayList());
private final int[] tupleIndices;
public TupleBooleanWeakTroveStorage() {
throw new UnsupportedOperationException("TupleBooleanWeakTroveStorage actually is not externalizable");
}
public TupleBooleanWeakTroveStorage(int[] tupleIndices) {
this.tupleIndices = tupleIndices;
}
public TupleBooleanWeakTroveStorage(HashingStrategy strategy, int[] tupleIndices) {
super(strategy);
this.tupleIndices = tupleIndices;
}
private void cleanup() {
for(Tuple t: removed) {
remove(t);
}
removed.clear();
}
@Override
public boolean load(Tuple o) {
cleanup();
return super.load(o);
}
@Override
public void save(Tuple o, boolean t) {
cleanup();
Callback callback = new Callback(o);
for (int index: tupleIndices) {
((SmartReference)o.get(index)).setCallback(callback);
}
super.save(o, t);
}
private class Callback implements Runnable {
private final Tuple o;
public Callback(Tuple o) {
this.o = o;
}
@Override
public void run() {
removed.add(o);
}
}
}