Search in sources :

Example 1 with TimeWrapper

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

Example 2 with TimeWrapper

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

Example 3 with TimeWrapper

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

Example 4 with TimeWrapper

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

Example 5 with TimeWrapper

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

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