use of org.vcell.util.CacheException in project vcell by virtualcell.
the class DataSetControllerImpl method getParticleDataBlock.
/**
* This method was created by a SmartGuide.
* @return double[]
* @param varName java.lang.String
* @param time double
*/
public ParticleDataBlock getParticleDataBlock(VCDataIdentifier vcdID, double time) throws DataAccessException {
if (lg.isTraceEnabled())
lg.trace("DataSetControllerImpl.getParticleDataBlock(" + time + ")");
try {
//
// check if already cached
//
VCData simData = getVCData(vcdID);
ParticleDataInfo particleDataInfo = new ParticleDataInfo(vcdID.getOwner(), vcdID.getID(), time, simData.getDataBlockTimeStamp(PARTICLE_DATA, time));
ParticleDataBlock particleDataBlock = (cacheTable0 != null ? cacheTable0.get(particleDataInfo) : null);
if (particleDataBlock != null) {
return particleDataBlock;
} else {
particleDataBlock = simData.getParticleDataBlock(time);
if (particleDataBlock != null) {
// cacheTable.put(particleDataInfo, particleDataBlock);
if (cacheTable0 != null) {
try {
cacheTable0.put(particleDataInfo, particleDataBlock);
} catch (CacheException e) {
// if can't cache the data, it is ok
e.printStackTrace();
}
}
return particleDataBlock;
} else {
String msg = "failure reading at t = " + time + " for " + vcdID.getOwner().getName() + "'s " + vcdID.getID();
if (lg.isWarnEnabled())
lg.warn("DataSetControllerImpl.getParticleDataBlock(): " + msg);
throw new DataAccessException(msg);
}
}
} catch (IOException e) {
lg.error(e.getMessage(), e);
throw new DataAccessException(e.getMessage());
}
}
use of org.vcell.util.CacheException in project vcell by virtualcell.
the class DataSetControllerImpl method getODEDataBlock.
/**
* Insert the method's description here.
* Creation date: (1/14/00 1:43:47 PM)
* @return cbit.vcell.simdata.ODEDataBlock
* @param user cbit.vcell.server.User
* @param simID java.lang.String
*/
public ODEDataBlock getODEDataBlock(VCDataIdentifier vcdID) throws DataAccessException {
if (lg.isTraceEnabled())
lg.trace("DataSetControllerImpl.getODEDataBlock()");
try {
//
// check if already cached
//
VCData simData = getVCData(vcdID);
ODEDataInfo odeDataInfo = new ODEDataInfo(vcdID.getOwner(), vcdID.getID(), simData.getDataBlockTimeStamp(ODE_DATA, 0));
ODEDataBlock odeDataBlock = (cacheTable0 != null ? cacheTable0.get(odeDataInfo) : null);
if (odeDataBlock != null) {
return odeDataBlock;
} else {
odeDataBlock = simData.getODEDataBlock();
if (odeDataBlock != null) {
// cacheTable.put(odeDataInfo, odeDataBlock);
if (cacheTable0 != null) {
try {
cacheTable0.put(odeDataInfo, odeDataBlock);
} catch (CacheException e) {
// if can't cache the results, it is ok
e.printStackTrace();
}
}
return odeDataBlock;
} else {
String msg = "failure reading ODE data for " + vcdID.getOwner().getName() + "'s " + vcdID.getID();
if (lg.isWarnEnabled())
lg.warn("DataSetControllerImpl.getODEDataBlock(): " + msg);
throw new DataAccessException(msg);
}
}
} catch (IOException e) {
lg.error(e.getMessage(), e);
throw new DataAccessException(e.getMessage());
}
}
use of org.vcell.util.CacheException 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.CacheException 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;
}
Aggregations