use of org.vcell.util.TimeWrapper in project vcell by virtualcell.
the class DBCacheTable 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);
}
return oldTimeWrapper;
}
use of org.vcell.util.TimeWrapper in project vcell by virtualcell.
the class DBCacheTable method putUnprotected.
public void putUnprotected(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;
try {
byte[] objData = org.vcell.util.BeanUtils.toSerialized(cacheable);
dataSize = objData.length;
} catch (IOException e) {
e.printStackTrace(System.out);
throw new CacheException(e.getMessage());
}
TimeWrapper oldTimeWrapper = put(key, new TimeWrapper(new DbObjectWrapper(cacheable), 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();
}
use of org.vcell.util.TimeWrapper in project vcell by virtualcell.
the class DBCacheTable method get.
public synchronized Cacheable get(KeyValue key) {
TimeWrapper timeWrapper = (TimeWrapper) hashTable.get(key);
if (timeWrapper != null) {
DbObjectWrapper objWrapper = (DbObjectWrapper) timeWrapper.getObject();
Cacheable cacheable = objWrapper.getWorkingCopy();
// System.out.println("DBCacheTable.get: "+cacheable.getClass().getName());
return cacheable;
} else {
// System.out.println("DBCacheTable.get: null");
return null;
}
}
Aggregations