use of org.vcell.util.TimeWrapper in project vcell by virtualcell.
the class DBCacheTable method getCloned.
public synchronized Cacheable getCloned(KeyValue key) {
TimeWrapper timeWrapper = (TimeWrapper) hashTable.get(key);
if (timeWrapper != null) {
DbObjectWrapper objWrapper = (DbObjectWrapper) timeWrapper.getObject();
Cacheable cacheable = objWrapper.getClonedCopy();
// System.out.println("DBCacheTable.get: "+cacheable.getClass().getName());
return cacheable;
} else {
// System.out.println("DBCacheTable.get: null");
return null;
}
}
use of org.vcell.util.TimeWrapper in project vcell by virtualcell.
the class DBCacheTable 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.
private synchronized TimeWrapper put(Object key, TimeWrapper timeWrapper) throws CacheException {
long dataMemSize = timeWrapper.getSize();
if (dataMemSize >= maxMemSize) {
throw new CacheException("data item " + key + " with memSize=" + dataMemSize + " too large, maxCacheSize=" + maxMemSize);
}
//
if (dataMemSize + currMemSize >= maxMemSize) {
resize(Math.min((long) (maxMemSize * cleanupFraction), maxMemSize - dataMemSize));
}
TimeWrapper oldTimeWrapper = (TimeWrapper) hashTable.put(key, timeWrapper);
currMemSize += dataMemSize;
if (oldTimeWrapper != null) {
currMemSize -= oldTimeWrapper.getSize();
}
if (currMemSize < 0 || currMemSize >= maxMemSize) {
throw new CacheException("Error: adding data item " + key + ". currMemSize=" + currMemSize + " maxMemSize=" + maxMemSize);
}
// System.out.println("........Cachetable.put(key="+key+")");
return oldTimeWrapper;
}
use of org.vcell.util.TimeWrapper in project vcell by virtualcell.
the class Cachetable method calcSize.
/**
* This method was created in VisualAge.
* @return long
*/
private synchronized long calcSize() {
long count = 0;
Enumeration enum1 = hashTable.elements();
while (enum1.hasMoreElements()) {
TimeWrapper timeWrapper = (TimeWrapper) enum1.nextElement();
count += timeWrapper.getSize();
}
return count;
}
use of org.vcell.util.TimeWrapper in project vcell by virtualcell.
the class Cachetable method removeVariable.
/**
* This method was created in VisualAge.
* @param key java.lang.Double
*/
public synchronized void removeVariable(VCDataIdentifier vcDataID, String varName) {
System.out.println("Cachetable.removeVariable(vcDataID=" + vcDataID + ",varName=" + varName + ")");
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) && pdeDataInfo.getVarName().equals(varName)) {
remove0(pdeDataInfo);
}
}
}
show();
}
Aggregations