use of org.vcell.util.TimeWrapper in project vcell by virtualcell.
the class Cachetable method resize.
/**
* This method was created in VisualAge.
* @param desiredMemSize long
*/
private synchronized void resize(long desiredMemSize) {
//
while (currMemSize > desiredMemSize) {
//
// calculate the maximum, avg cost
// decide on a cost threshold for deletion
//
double maxCost = -1e10;
double minCost = 1e10;
double totalCost = 0;
long count = 0;
Enumeration enum1 = hashTable.elements();
while (enum1.hasMoreElements()) {
TimeWrapper timeWrapper = (TimeWrapper) enum1.nextElement();
double cost = timeWrapper.getCost(costPerMilliSecond, costPerByte);
maxCost = Math.max(cost, maxCost);
minCost = Math.min(cost, minCost);
totalCost += cost;
count++;
}
double avgCost = totalCost / count;
double thresholdCost = avgCost + (maxCost - avgCost) * 0.5;
//
// delete all records with a cost greater than the threshold
//
enum1 = hashTable.elements();
while (enum1.hasMoreElements()) {
TimeWrapper timeWrapper = (TimeWrapper) enum1.nextElement();
double cost = timeWrapper.getCost(costPerMilliSecond, costPerByte);
if (cost > thresholdCost) {
remove0(timeWrapper.getKey());
}
}
//
// evaluate how we did (may need to increase 'costPerByte' if poor convergence)
//
System.out.println("resize(): desiredMemSize=" + desiredMemSize + " cost min=" + minCost + ", max=" + maxCost + ", avg=" + avgCost + " thresholdCost=" + thresholdCost);
show();
}
}
use of org.vcell.util.TimeWrapper in project vcell by virtualcell.
the class Cachetable method put.
public VCData put(VCDataIdentifier vcdID, VCData data) throws CacheException {
VCData oldData = null;
TimeWrapper oldTimeWrapper = put(vcdID, new TimeWrapper(data, data.getSizeInBytes(), vcdID));
if (oldTimeWrapper != null) {
oldData = (VCData) oldTimeWrapper.getObject();
}
show();
return oldData;
}
use of org.vcell.util.TimeWrapper in project vcell by virtualcell.
the class Cachetable method put.
public SimDataBlock put(PDEDataInfo pdeDataInfo, SimDataBlock simData) throws CacheException {
SimDataBlock oldSimDataBlock = null;
TimeWrapper oldTimeWrapper = put(pdeDataInfo, new TimeWrapper(simData, simData.getSizeInBytes(), pdeDataInfo));
if (oldTimeWrapper != null) {
oldSimDataBlock = (SimDataBlock) oldTimeWrapper.getObject();
}
show();
return oldSimDataBlock;
}
use of org.vcell.util.TimeWrapper in project vcell by virtualcell.
the class Cachetable method removeAll.
/**
* This method was created in VisualAge.
* @param key java.lang.Double
*/
public synchronized void removeAll(VCDataIdentifier vcDataID) {
System.out.println("removeAll(vcDataID=" + vcDataID + ")");
remove0(vcDataID);
Enumeration enum1 = hashTable.elements();
while (enum1.hasMoreElements()) {
TimeWrapper tw = (TimeWrapper) enum1.nextElement();
if (tw.getKey() instanceof PDEDataInfo) {
PDEDataInfo pdeDataInfo = (PDEDataInfo) tw.getKey();
if (pdeDataInfo.belongsTo(vcDataID)) {
remove0(pdeDataInfo);
}
}
}
show();
}
use of org.vcell.util.TimeWrapper in project vcell by virtualcell.
the class Cachetable method put.
public ParticleDataBlock put(ParticleDataInfo particleDataInfo, ParticleDataBlock particleDataBlock) throws CacheException {
ParticleDataBlock oldParticleDataBlock = null;
TimeWrapper oldTimeWrapper = put(particleDataInfo, new TimeWrapper(particleDataBlock, particleDataBlock.getSizeInBytes(), particleDataInfo));
if (oldTimeWrapper != null) {
oldParticleDataBlock = (ParticleDataBlock) oldTimeWrapper.getObject();
}
show();
return oldParticleDataBlock;
}
Aggregations