Search in sources :

Example 11 with TimeWrapper

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;
    }
}
Also used : TimeWrapper(org.vcell.util.TimeWrapper) Cacheable(org.vcell.util.Cacheable)

Example 12 with TimeWrapper

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();
    }
}
Also used : TimeWrapper(org.vcell.util.TimeWrapper) Enumeration(java.util.Enumeration)

Example 13 with TimeWrapper

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;
}
Also used : TimeWrapper(org.vcell.util.TimeWrapper) CacheException(org.vcell.util.CacheException)

Example 14 with TimeWrapper

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;
}
Also used : TimeWrapper(org.vcell.util.TimeWrapper) Enumeration(java.util.Enumeration)

Example 15 with TimeWrapper

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();
}
Also used : TimeWrapper(org.vcell.util.TimeWrapper) Enumeration(java.util.Enumeration)

Aggregations

TimeWrapper (org.vcell.util.TimeWrapper)18 Enumeration (java.util.Enumeration)8 CacheException (org.vcell.util.CacheException)4 IOException (java.io.IOException)2 Serializable (java.io.Serializable)2 Cacheable (org.vcell.util.Cacheable)2 Immutable (org.vcell.util.Immutable)2