Search in sources :

Example 6 with TimeWrapper

use of org.vcell.util.TimeWrapper in project vcell by virtualcell.

the class Cachetable method put.

public ODEDataBlock put(ODEDataInfo odeDataInfo, ODEDataBlock odeDataBlock) throws CacheException {
    ODEDataBlock oldODEDataBlock = null;
    TimeWrapper oldTimeWrapper = put(odeDataInfo, new TimeWrapper(odeDataBlock, odeDataBlock.getEstimatedSizeInBytes(), odeDataInfo));
    if (oldTimeWrapper != null) {
        oldODEDataBlock = (ODEDataBlock) oldTimeWrapper.getObject();
    }
    show();
    return oldODEDataBlock;
}
Also used : TimeWrapper(org.vcell.util.TimeWrapper)

Example 7 with TimeWrapper

use of org.vcell.util.TimeWrapper in project vcell by virtualcell.

the class Cachetable method ping.

public synchronized void ping() {
    boolean bRemovedAny = false;
    Enumeration e = hashTable.keys();
    while (e.hasMoreElements()) {
        Object key = e.nextElement();
        TimeWrapper tw = (TimeWrapper) hashTable.get(key);
        if ((tw != null) && (tw.getAge() > expireTime)) {
            remove0(key);
            bRemovedAny = true;
        // System.out.println("Cachetable.ping(), expiring key="+key.toString());
        }
    }
    if (bRemovedAny) {
        show();
    }
// System.gc();
}
Also used : TimeWrapper(org.vcell.util.TimeWrapper) Enumeration(java.util.Enumeration)

Example 8 with TimeWrapper

use of org.vcell.util.TimeWrapper in project vcell by virtualcell.

the class DBCacheTable method ping.

public synchronized void ping() {
    boolean bRemovedAny = false;
    Enumeration e = hashTable.keys();
    while (e.hasMoreElements()) {
        Object key = e.nextElement();
        TimeWrapper tw = (TimeWrapper) hashTable.get(key);
        if ((tw != null) && (tw.getAge() > expireTimeMillisec)) {
            remove0(key);
            bRemovedAny = true;
        // System.out.println("Cachetable.ping(), expiring key="+key.toString());
        }
    }
    if (bRemovedAny) {
        show();
    }
// System.gc();
}
Also used : TimeWrapper(org.vcell.util.TimeWrapper) Enumeration(java.util.Enumeration)

Example 9 with TimeWrapper

use of org.vcell.util.TimeWrapper in project vcell by virtualcell.

the class DBCacheTable 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 10 with TimeWrapper

use of org.vcell.util.TimeWrapper in project vcell by virtualcell.

the class DBCacheTable method putProtected.

public void putProtected(KeyValue key, Cacheable cacheable) throws CacheException {
    if (!((cacheable instanceof Cloneable) || (cacheable instanceof Immutable) || (cacheable instanceof Serializable))) {
        throw new CacheException("put:Object not Cloneable, Immutable or Serializable");
    }
    if (key == null) {
        throw new CacheException("put: key == null");
    }
    long dataSize = 1000;
    byte[] objData = null;
    try {
        objData = org.vcell.util.BeanUtils.toSerialized(cacheable);
        // 
        // dataSize is length*3 because three copies are stored in DbObjectWrapper (reference/bytes/working).
        // 
        dataSize = objData.length * 3;
    } catch (IOException e) {
        e.printStackTrace(System.out);
        throw new CacheException(e.getMessage());
    }
    TimeWrapper oldTimeWrapper = put(key, new TimeWrapper(new DbObjectWrapper(cacheable, objData), dataSize, key));
    // 
    if (oldTimeWrapper != null) {
        System.out.println("replacing object ALREADY IN DATABASE_CACHE " + oldTimeWrapper.getObject() + " at key " + key);
    }
    // 
    // checking to see if same object (using compareEqual) already in hash
    // 
    // if (cacheable instanceof cbit.vcell.model.Species){
    // Enumeration enum1 = hashTable.elements();
    // while (enum1.hasMoreElements()){
    // TimeWrapper timeWrapper = (TimeWrapper) enum1.nextElement();
    // DbObjectWrapper objWrapper = (DbObjectWrapper) timeWrapper.getObject();
    // Cacheable cacheObj = objWrapper.getWorkingCopy();
    // if (cacheable != cacheObj && cacheable.compareEqual(cacheObj)){
    // //	throw new RuntimeException("DBCacheTable.put("+cacheable+"), already in cache as ("+cacheObj+")");
    // System.out.println("DBCacheTable.put("+cacheable+"), already in cache as ("+cacheObj+")");
    // }
    // }
    // }
    // System.out.print("put(cacheable="+cacheable+") ");
    show();
}
Also used : Immutable(org.vcell.util.Immutable) TimeWrapper(org.vcell.util.TimeWrapper) Serializable(java.io.Serializable) CacheException(org.vcell.util.CacheException) IOException(java.io.IOException)

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