use of cbit.vcell.solver.VCSimulationIdentifier in project vcell by virtualcell.
the class SolverPostprocessor method main.
public static void main(java.lang.String[] args) {
if (args.length < NUM_STD_ARGS) {
System.out.println("Usage: " + SolverPostprocessor.class.getName() + " simKey username userKey jobindex taskid solverExitCode [postProcessorCommandFile]");
System.exit(1);
}
Logging.init();
Log4jSessionLog log = new Log4jSessionLog(LOG_NAME);
Logger lg = log.getLogger();
VCMessagingService vcMessagingService = null;
try {
PropertyLoader.loadProperties(POST_PROCESSOR_PROPERTIES);
ResourceUtil.setNativeLibraryDirectory();
NativeLoader.setOsType(OsType.LINUX);
KeyValue simKey = new KeyValue(args[0]);
String userName = args[1];
KeyValue userKey = new KeyValue(args[2]);
int jobIndex = Integer.parseInt(args[3]);
int taskID = Integer.parseInt(args[4]);
int solverExitCode = Integer.parseInt(args[5]);
User owner = new User(userName, userKey);
VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(simKey, owner);
String hostName = ManageUtils.getHostName();
VCMongoMessage.serviceStartup(ServiceName.solverPostprocessor, Integer.valueOf(simKey.toString()), args);
//
// JMX registration
//
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
mbs.registerMBean(new VCellServiceMXBeanImpl(), new ObjectName(VCellServiceMXBean.jmxObjectName));
vcMessagingService = VCellServiceHelper.getInstance().loadService(VCMessagingService.class);
vcMessagingService.setDelegate(new ServerMessagingDelegate());
VCMessageSession session = vcMessagingService.createProducerSession();
WorkerEventMessage workerEventMessage;
if (solverExitCode == 0) {
Exception postProcessingException = null;
if (args.length > NUM_STD_ARGS) {
String fname = args[NUM_STD_ARGS];
if (lg.isDebugEnabled()) {
lg.debug("processing " + fname);
}
postProcessingException = runPostprocessingCommands(fname, lg);
}
if (lg.isDebugEnabled()) {
lg.debug("postProcessingException is " + postProcessingException);
}
if (postProcessingException == null) {
lg.debug("sendWorkerExitNormal");
workerEventMessage = WorkerEventMessage.sendWorkerExitNormal(session, SolverPostprocessor.class.getName(), hostName, vcSimID, jobIndex, taskID, solverExitCode);
} else {
lg.debug("sendWorkerExitError postprocessing");
workerEventMessage = WorkerEventMessage.sendWorkerExitError(session, postProcessingException, hostName, vcSimID, jobIndex, taskID, SimulationMessage.WorkerExited(postProcessingException));
}
} else {
// solverExitCode != 0
lg.debug("sendWorkerExitError solverExitCode");
workerEventMessage = WorkerEventMessage.sendWorkerExitError(session, SolverPostprocessor.class.getName(), hostName, vcSimID, jobIndex, taskID, solverExitCode);
}
lg.debug(workerEventMessage);
VCMongoMessage.sendWorkerEvent(workerEventMessage);
} catch (Throwable e) {
log.exception(e);
} finally {
if (vcMessagingService != null) {
try {
vcMessagingService.close();
} catch (VCMessagingException e) {
e.printStackTrace();
}
}
ApplicationTerminator.beginCountdown(TimeUnit.SECONDS, 10, 0);
VCMongoMessage.shutdown();
System.exit(0);
}
}
use of cbit.vcell.solver.VCSimulationIdentifier in project vcell by virtualcell.
the class ClientRequestManager method getDataViewerController.
/**
* Insert the method's description here. Creation date: (6/11/2004 10:53:47 AM)
*
* @return cbit.vcell.desktop.controls.DataManager
* @param vcDataIdentifier cbit.vcell.server.VCDataIdentifier
*/
public DataViewerController getDataViewerController(OutputContext outputContext, Simulation simulation, int jobIndex) throws DataAccessException {
VCSimulationIdentifier vcSimulationIdentifier = simulation.getSimulationInfo().getAuthoritativeVCSimulationIdentifier();
final VCDataIdentifier vcdataIdentifier = new VCSimulationDataIdentifier(vcSimulationIdentifier, jobIndex);
DataManager dataManager = getDataManager(outputContext, vcdataIdentifier, simulation.isSpatial());
return new SimResultsViewerController(dataManager, simulation);
}
use of cbit.vcell.solver.VCSimulationIdentifier in project vcell by virtualcell.
the class ClientSimManager method showSimulationResults0.
private AsynchClientTask[] showSimulationResults0(final boolean isLocal, final ViewerType viewerType) {
// Create the AsynchClientTasks
ArrayList<AsynchClientTask> taskList = new ArrayList<AsynchClientTask>();
taskList.add(new AsynchClientTaskFunction(h -> {
h.put(H_LOCAL_SIM, isLocal);
h.put(H_VIEWER_TYPE, viewerType);
}, "setLocal", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING));
final DocumentWindowManager documentWindowManager = getDocumentWindowManager();
AsynchClientTask retrieveResultsTask = new AsynchClientTask("Retrieving results", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@SuppressWarnings("unchecked")
public void run(Hashtable<String, Object> hashTable) throws Exception {
Simulation[] simsToShow = (Simulation[]) hashTable.get("simsArray");
for (int i = 0; i < simsToShow.length; i++) {
final Simulation sim = simsToShow[i];
final VCSimulationIdentifier vcSimulationIdentifier = sim.getSimulationInfo().getAuthoritativeVCSimulationIdentifier();
final SimulationWindow simWindow = documentWindowManager.haveSimulationWindow(vcSimulationIdentifier);
OutputContext outputContext = (OutputContext) hashTable.get("outputContext");
if (simWindow == null && (viewerType == ViewerType.NativeViewer_only)) {
try {
// make the manager and wire it up
DataViewerController dataViewerController = null;
if (!isLocal) {
dataViewerController = documentWindowManager.getRequestManager().getDataViewerController(outputContext, sim, 0);
// For changes in time or variable
documentWindowManager.addDataListener(dataViewerController);
} else {
// ---- preliminary : construct the localDatasetControllerProvider
File primaryDir = ResourceUtil.getLocalRootDir();
User usr = sim.getVersion().getOwner();
DataSetControllerImpl dataSetControllerImpl = new DataSetControllerImpl(null, primaryDir, null);
ExportServiceImpl localExportServiceImpl = new ExportServiceImpl();
LocalDataSetControllerProvider localDSCProvider = new LocalDataSetControllerProvider(usr, dataSetControllerImpl, localExportServiceImpl);
VCDataManager vcDataManager = new VCDataManager(localDSCProvider);
File localSimDir = ResourceUtil.getLocalSimDir(User.tempUser.getName());
LocalVCDataIdentifier vcDataId = new LocalVCSimulationDataIdentifier(vcSimulationIdentifier, 0, localSimDir);
DataManager dataManager = null;
if (sim.isSpatial()) {
dataManager = new PDEDataManager(outputContext, vcDataManager, vcDataId);
} else {
dataManager = new ODEDataManager(outputContext, vcDataManager, vcDataId);
}
dataViewerController = new SimResultsViewerController(dataManager, sim);
dataSetControllerImpl.addDataJobListener(documentWindowManager);
}
// make the viewer
Hashtable<VCSimulationIdentifier, DataViewerController> dataViewerControllers = (Hashtable<VCSimulationIdentifier, DataViewerController>) hashTable.get(H_DATA_VIEWER_CONTROLLERS);
if (dataViewerControllers == null) {
dataViewerControllers = new Hashtable<VCSimulationIdentifier, DataViewerController>();
hashTable.put(H_DATA_VIEWER_CONTROLLERS, dataViewerControllers);
}
dataViewerControllers.put(vcSimulationIdentifier, dataViewerController);
} catch (Throwable exc) {
exc.printStackTrace(System.out);
saveFailure(hashTable, sim, exc);
}
}
}
}
};
taskList.add(retrieveResultsTask);
AsynchClientTask displayResultsTask = new AsynchClientTask("Showing results", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@SuppressWarnings("unchecked")
public void run(Hashtable<String, Object> hashTable) throws Exception {
boolean isLocal = fetch(hashTable, H_LOCAL_SIM, Boolean.class, true);
SimulationWindow.LocalState localState = isLocal ? LocalState.LOCAL : LocalState.SERVER;
Hashtable<Simulation, Throwable> failures = (Hashtable<Simulation, Throwable>) hashTable.get(H_FAILURES);
Simulation[] simsToShow = (Simulation[]) hashTable.get("simsArray");
for (int i = 0; i < simsToShow.length; i++) {
final Simulation sim = simsToShow[i];
if (failures != null && failures.containsKey(sim)) {
continue;
}
final VCSimulationIdentifier vcSimulationIdentifier = simsToShow[i].getSimulationInfo().getAuthoritativeVCSimulationIdentifier();
final SimulationWindow simWindow = documentWindowManager.haveSimulationWindow(vcSimulationIdentifier);
if (simWindow != null) {
ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(documentWindowManager.getComponent());
ChildWindow childWindow = childWindowManager.getChildWindowFromContext(simWindow);
if (childWindow == null) {
childWindow = childWindowManager.addChildWindow(simWindow.getDataViewer(), simWindow);
childWindow.pack();
childWindow.setIsCenteredOnParent();
childWindow.show();
}
setFinalWindow(hashTable, childWindow);
simWindow.setLocalState(localState);
} else {
// wire it up the viewer
Hashtable<VCSimulationIdentifier, DataViewerController> dataViewerControllers = (Hashtable<VCSimulationIdentifier, DataViewerController>) hashTable.get(H_DATA_VIEWER_CONTROLLERS);
DataViewerController viewerController = dataViewerControllers.get(vcSimulationIdentifier);
Throwable ex = (failures == null ? null : failures.get(sim));
if (viewerController != null && ex == null) {
// no failure
DataViewer viewer = viewerController.createViewer();
getSimWorkspace().getSimulationOwner().getOutputFunctionContext().addPropertyChangeListener(viewerController);
documentWindowManager.addExportListener(viewer);
// For data related activities such as calculating statistics
documentWindowManager.addDataJobListener(viewer);
viewer.setSimulationModelInfo(new SimulationWorkspaceModelInfo(getSimWorkspace().getSimulationOwner(), sim.getName()));
viewer.setDataViewerManager(documentWindowManager);
SimulationWindow newWindow = new SimulationWindow(vcSimulationIdentifier, sim, getSimWorkspace().getSimulationOwner(), viewer);
BeanUtils.addCloseWindowKeyboardAction(newWindow.getDataViewer());
documentWindowManager.addResultsFrame(newWindow);
setFinalWindow(hashTable, viewer);
newWindow.setLocalState(localState);
}
}
}
StringBuffer failMessage = new StringBuffer();
if (failures != null) {
if (!failures.isEmpty()) {
failMessage.append("Error, " + failures.size() + " of " + simsToShow.length + " sim results failed to display:\n");
Enumeration<Simulation> en = failures.keys();
while (en.hasMoreElements()) {
Simulation sim = en.nextElement();
Throwable exc = (Throwable) failures.get(sim);
failMessage.append("'" + sim.getName() + "' - " + exc.getMessage());
}
}
}
if (failMessage.length() > 0) {
PopupGenerator.showErrorDialog(ClientSimManager.this.getDocumentWindowManager(), failMessage.toString());
}
}
};
if (viewerType == ViewerType.NativeViewer_only) {
taskList.add(displayResultsTask);
}
// Dispatch the tasks using the ClientTaskDispatcher.
AsynchClientTask[] taskArray = new AsynchClientTask[taskList.size()];
taskList.toArray(taskArray);
return taskArray;
}
use of cbit.vcell.solver.VCSimulationIdentifier in project vcell by virtualcell.
the class DocumentWindowManager method exportMessage.
/**
* Insert the method's description here.
* Creation date: (6/15/2004 2:55:34 AM)
* @param exportEvent cbit.rmi.event.ExportEvent
*/
public void exportMessage(ExportEvent exportEvent) {
//
// may not come from a simulation, but we'll create a VCSimulationIdentifer to match with the window just in case
// if it is not a match, no harm.
//
VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(exportEvent.getDataKey(), exportEvent.getUser());
if (haveSimulationWindow(vcSimID) == null) {
// && exportEvent.getEventTypeID() != ExportEvent.EXPORT_COMPLETE) {
return;
}
// just pass them along...
fireExportMessage(exportEvent);
}
use of cbit.vcell.solver.VCSimulationIdentifier in project vcell by virtualcell.
the class ClientTopicMessageCollector method onTopicMessage.
/**
* Insert the method's description here.
* Creation date: (10/23/2001 3:58:52 PM)
* @param message javax.jms.Message
* @throws VCMessagingException
*/
public void onTopicMessage(VCMessage message, VCMessageSession session) {
if (message == null) {
return;
}
try {
// Check if it's a broadcast message
if (message instanceof VCMessageJms) {
VCMessageJms vcMessageJms = (VCMessageJms) message;
javax.jms.Message myMessage = vcMessageJms.getJmsMessage();
if (myMessage instanceof ActiveMQTextMessage) {
ActiveMQTextMessage myAMQ = (ActiveMQTextMessage) myMessage;
if (myAMQ.getType().equalsIgnoreCase(MessageConstants.MESSAGE_TYPE_BROADCASTMESSAGE_VALUE)) {
fireMessageEvent(new VCellMessageEvent(this, System.currentTimeMillis() + "", new MessageData(myAMQ.getText()), VCellMessageEvent.VCELL_MESSAGEEVENT_TYPE_BROADCAST, null));
return;
}
}
}
if (message.getObjectContent() == null) {
throw new Exception(this.getClass().getName() + ".onTopicMessage: unimplemented message class " + message.show());
}
setTimeSinceLastMessage(System.currentTimeMillis());
String msgType = message.getStringProperty(VCMessagingConstants.MESSAGE_TYPE_PROPERTY);
if (msgType == null) {
throw new Exception(this.getClass().getName() + ".onTopicMessage: message type NULL for message " + message);
}
if (msgType.equals(MessageConstants.MESSAGE_TYPE_SIMSTATUS_VALUE)) {
String messageUserName = message.getStringProperty(VCMessagingConstants.USERNAME_PROPERTY);
StatusMessage statusMessage = new StatusMessage(message);
String userName = VCMessagingConstants.USERNAME_PROPERTY_VALUE_ALL;
if (message.propertyExists(VCMessagingConstants.USERNAME_PROPERTY)) {
userName = message.getStringProperty(VCMessagingConstants.USERNAME_PROPERTY);
}
SimulationJobStatus newJobStatus = statusMessage.getJobStatus();
if (newJobStatus == null) {
return;
}
VCSimulationIdentifier vcSimID = newJobStatus.getVCSimulationIdentifier();
Double progress = statusMessage.getProgress();
Double timePoint = statusMessage.getTimePoint();
fireSimulationJobStatusEvent(new SimulationJobStatusEvent(this, vcSimID.getID(), newJobStatus, progress, timePoint, messageUserName));
} else if (msgType.equals(MessageConstants.MESSAGE_TYPE_EXPORT_EVENT_VALUE)) {
String messageUserName = message.getStringProperty(VCMessagingConstants.USERNAME_PROPERTY);
ExportEvent event = (ExportEvent) message.getObjectContent();
fireExportEvent(event);
} else if (msgType.equals(MessageConstants.MESSAGE_TYPE_DATA_EVENT_VALUE)) {
String messageUserName = message.getStringProperty(VCMessagingConstants.USERNAME_PROPERTY);
DataJobEvent event = (DataJobEvent) message.getObjectContent();
fireMessageEvent(event);
} else if (msgType.equals(MessageConstants.MESSAGE_TYPE_BROADCASTMESSAGE_VALUE)) {
String messageUserName = message.getStringProperty(VCMessagingConstants.USERNAME_PROPERTY);
fireMessageEvent(new VCellMessageEvent(this, System.currentTimeMillis() + "", new MessageData((BigString) message.getObjectContent()), VCellMessageEvent.VCELL_MESSAGEEVENT_TYPE_BROADCAST, messageUserName));
} else {
throw new Exception(this.getClass().getName() + ".onControlTopicMessage: Unimplemented message " + message.show());
}
} catch (Exception e) {
e.printStackTrace();
lg.error(e.getMessage(), e);
}
}
Aggregations