com.maxifier.mxcache.impl.caches.def.TupleDoubleWeakTroveStorage 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.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 TupleDoubleWeakTroveStorage extends ObjectDoubleTroveStorage {
private final List removed = Collections.synchronizedList(new ArrayList());
private final int[] tupleIndices;
public TupleDoubleWeakTroveStorage() {
throw new UnsupportedOperationException("TupleDoubleWeakTroveStorage actually is not externalizable");
}
public TupleDoubleWeakTroveStorage(int[] tupleIndices) {
this.tupleIndices = tupleIndices;
}
public TupleDoubleWeakTroveStorage(HashingStrategy strategy, int[] tupleIndices) {
super(strategy);
this.tupleIndices = tupleIndices;
}
private void cleanup() {
for(Tuple t: removed) {
remove(t);
}
removed.clear();
}
@Override
public double load(Tuple o) {
cleanup();
return super.load(o);
}
@Override
public void save(Tuple o, double 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);
}
}
}