use of org.vcell.util.CacheException in project vcell by virtualcell.
the class DataSetControllerImpl method getChomboExtrapolatedValues.
private SimDataBlock getChomboExtrapolatedValues(VCDataIdentifier vcdID, String varName, double time) throws DataAccessException {
final String methodName = "DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ")";
VCMongoMessage.sendTrace(methodName + " <<ENTER>>");
try {
//
// check if already cached for non-function variables
//
VCData vcData = getVCData(vcdID);
if (vcData == null || !(vcData instanceof SimulationData)) {
return null;
}
SimulationData simData = (SimulationData) vcData;
VCMongoMessage.sendTrace(methodName + " got VCData");
long dataBlockTimeStamp = simData.getDataBlockTimeStamp(PDE_DATA, time);
VCMongoMessage.sendTrace(methodName + " got dataBlockTimeStamp");
PDEDataInfo pdeDataInfo = new PDEDataInfo(vcdID.getOwner(), vcdID.getID(), varName, time, dataBlockTimeStamp);
SimDataBlock simDataBlock = null;
if (dataCachingEnabled && chomboExtrapolatedValuesCache == null) {
chomboExtrapolatedValuesCache = new Cachetable(MessageConstants.MINUTE_IN_MS * 10, 1000000L);
}
simDataBlock = chomboExtrapolatedValuesCache.get(pdeDataInfo);
if (simDataBlock == null) {
VCMongoMessage.sendTrace(methodName + " read chombo extrapolated values");
simDataBlock = simData.getChomboExtrapolatedValues(varName, time);
if (simDataBlock != null && dataCachingEnabled) {
if (chomboExtrapolatedValuesCache != null) {
try {
chomboExtrapolatedValuesCache.put(pdeDataInfo, simDataBlock);
} catch (CacheException e) {
// if can't cache the data, it is ok
e.printStackTrace();
}
}
}
}
if (simDataBlock != null) {
VCMongoMessage.sendTrace(methodName + " <<EXIT-Success>>");
return simDataBlock;
}
String msg = "failure reading " + varName + " at t=" + time + " for " + vcdID.getOwner().getName() + "'s " + vcdID.getID();
if (lg.isWarnEnabled())
lg.warn(methodName + msg);
throw new DataAccessException(msg);
} catch (Exception e) {
lg.error(e.getMessage(), e);
VCMongoMessage.sendTrace(methodName + " <<EXIT-Exception>>");
throw new DataAccessException(e.getMessage());
}
}
use of org.vcell.util.CacheException in project vcell by virtualcell.
the class DataSetControllerImpl method getSimDataBlock.
/**
* This method was created by a SmartGuide.
* @return double[]
* @param varName java.lang.String
* @param time double
*/
public SimDataBlock getSimDataBlock(OutputContext outputContext, VCDataIdentifier vcdID, String varName, double time) throws DataAccessException {
VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ") <<ENTER>>");
try {
//
// check if already cached for non-function variables
//
VCData simData = getVCData(vcdID);
VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ") got VCData");
long dataBlockTimeStamp = simData.getDataBlockTimeStamp(PDE_DATA, time);
VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ") got dataBlockTimeStamp");
PDEDataInfo pdeDataInfo = new PDEDataInfo(vcdID.getOwner(), vcdID.getID(), varName, time, dataBlockTimeStamp);
SimDataBlock simDataBlock = null;
AnnotatedFunction function = getFunction(outputContext, vcdID, varName);
VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ") got function");
if (function == null) {
simDataBlock = (cacheTable0 != null ? cacheTable0.get(pdeDataInfo) : null);
if (simDataBlock == null) {
simDataBlock = simData.getSimDataBlock(outputContext, varName, time);
if (simDataBlock != null && dataCachingEnabled) {
// cacheTable.put(pdeDataInfo,simDataBlock);
if (cacheTable0 != null) {
try {
cacheTable0.put(pdeDataInfo, simDataBlock);
} catch (CacheException e) {
// if can't cache the data, it is ok
e.printStackTrace();
}
}
}
}
} else {
if (simData instanceof SimulationData) {
function = ((SimulationData) simData).simplifyFunction(function);
}
VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ") evaluating function");
simDataBlock = evaluateFunction(outputContext, vcdID, simData, function, time);
}
CartesianMesh mesh = getMesh(vcdID);
if (mesh != null && mesh.isChomboMesh()) {
for (int i = 0; i < simDataBlock.getData().length; i++) {
if (simDataBlock.getData()[i] == 1.23456789e300) {
simDataBlock.getData()[i] = Double.NaN;
}
}
}
if (simDataBlock != null) {
VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ") <<EXIT-simDataBlock not null>>");
return simDataBlock;
} else {
String msg = "failure reading " + varName + " at t=" + time + " for " + vcdID.getOwner().getName() + "'s " + vcdID.getID();
if (lg.isWarnEnabled())
lg.warn("DataSetControllerImpl.getDataBlockValues(): " + msg);
VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ") <<EXIT-Exception>>");
throw new DataAccessException(msg);
}
} catch (MathException e) {
lg.error(e.getMessage(), e);
VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ") <<EXIT-Exception>>");
throw new DataAccessException(e.getMessage());
} catch (IOException e) {
lg.error(e.getMessage(), e);
VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ") <<EXIT-Exception>>");
throw new DataAccessException(e.getMessage());
} catch (ExpressionException e) {
lg.error(e.getMessage(), e);
VCMongoMessage.sendTrace("DataSetControllerImpl.getSimDataBlock(" + varName + ", " + time + ") <<EXIT-Exception>>");
throw new DataAccessException(e.getMessage());
}
}
use of org.vcell.util.CacheException 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();
}
use of org.vcell.util.CacheException in project vcell by virtualcell.
the class DataSetControllerImpl method getVCData.
/**
* This method was created in VisualAge.
* @return cbit.vcell.simdata.SimResults
* @param user User
* @param simID java.lang.String
*/
public VCData getVCData(VCDataIdentifier vcdID) throws DataAccessException, IOException {
VCMongoMessage.sendTrace("DataSetControllerImpl.getVCData(" + vcdID.getID() + ") ... <<ENTER>>");
VCData vcData = (cacheTable0 != null ? cacheTable0.get(vcdID) : null);
//
if (vcData == null) {
// System.out.println("getVCData " + vcdID);
if (vcdID instanceof MergedDataInfo) {
try {
User user = vcdID.getOwner();
VCDataIdentifier[] vcdIdentifiers = ((MergedDataInfo) vcdID).getDataIDs();
VCMongoMessage.sendTrace("DataSetControllerImpl.getVCData(" + vcdID.getID() + ") : creating new MergedData : <<BEGIN>>");
vcData = new MergedData(user, getPrimaryUserDir(vcdID.getOwner(), false), getSecondaryUserDir(vcdID.getOwner()), this, vcdIdentifiers, ((MergedDataInfo) vcdID).getDataSetPrefix());
VCMongoMessage.sendTrace("DataSetControllerImpl.getVCData(" + vcdID.getID() + ") : creating new MergedData : <<END>>");
} catch (IOException e) {
e.printStackTrace(System.out);
throw new RuntimeException(e.getMessage());
}
} else {
// assume vcdID instanceof cbit.vcell.solver.SimulationInfo or a test adapter
VCMongoMessage.sendTrace("DataSetControllerImpl.getVCData(" + vcdID.getID() + ") : creating new SimulationData : <<BEGIN>>");
SimulationData.SimDataAmplistorInfo simDataAmplistorInfo = AmplistorUtils.getSimDataAmplistorInfoFromPropertyLoader();
vcData = new SimulationData(vcdID, getPrimaryUserDir(vcdID.getOwner(), false), getSecondaryUserDir(vcdID.getOwner()), simDataAmplistorInfo);
VCMongoMessage.sendTrace("DataSetControllerImpl.getVCData(" + vcdID.getID() + ") : creating new SimulationData : <<END>>");
}
if (cacheTable0 != null) {
try {
VCMongoMessage.sendTrace("DataSetControllerImpl.getVCData(" + vcdID.getID() + ") : caching vcData : <<BEGIN>>");
cacheTable0.put(vcdID, vcData);
VCMongoMessage.sendTrace("DataSetControllerImpl.getVCData(" + vcdID.getID() + ") : caching vcData : <<END>>");
} catch (CacheException e) {
// if can't cache the data, it is ok
e.printStackTrace();
}
}
}
VCMongoMessage.sendTrace("DataSetControllerImpl.getVCData(" + vcdID.getID() + ") ... <<EXIT>>");
return vcData;
}
use of org.vcell.util.CacheException 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;
}
Aggregations