Search in sources :

Example 1 with SimulationJobStatusEvent

use of cbit.rmi.event.SimulationJobStatusEvent in project vcell by virtualcell.

the class RestEventService method newEventMessage.

private void newEventMessage(MessageEvent event) {
    if (lg.isTraceEnabled())
        lg.trace("newEventMessage(" + event.getClass().getSimpleName() + ": " + event);
    if (event instanceof ExportEvent) {
        ExportEvent exportEvent = (ExportEvent) event;
        try {
            ExportEventRepresentation exportEventRep = exportEvent.toJsonRep();
            ExportEvent event2 = ExportEvent.fromJsonRep(this, exportEventRep);
            if (!Compare.isEqual(event2.getFormat(), exportEvent.getFormat())) {
                throw new RuntimeException("Export event round-trip failed");
            }
            if (!Compare.isEqual(event2.getJobID(), exportEvent.getJobID())) {
                throw new RuntimeException("Export event round-trip failed");
            }
            Gson gson = new Gson();
            String eventJSON = gson.toJson(exportEventRep);
            insert(exportEventRep.username, EventType.ExportEvent, eventJSON);
        } catch (Exception e) {
            lg.error(e.getMessage(), e);
        }
    } else if (event instanceof SimulationJobStatusEvent) {
        SimulationJobStatusEvent simJobEvent = (SimulationJobStatusEvent) event;
        try {
            SimulationJobStatusEventRepresentation simJobEventRep = simJobEvent.toJsonRep();
            SimulationJobStatusEvent event2 = SimulationJobStatusEvent.fromJsonRep(this, simJobEventRep);
            if (!Compare.isEqual(event2.getJobStatus(), simJobEvent.getJobStatus())) {
                throw new RuntimeException("SimulationJobStatus event round-trip failed");
            }
            if (!Compare.isEqual(event2.getProgress(), simJobEvent.getProgress())) {
                throw new RuntimeException("SimulationJobStatus <PROGRESS> event round-trip failed");
            }
            Gson gson = new Gson();
            String eventJSON = gson.toJson(simJobEventRep);
            insert(simJobEventRep.username, EventType.SimJob, eventJSON);
        } catch (Exception e) {
            lg.error(e.getMessage(), e);
        }
    } else if (event instanceof VCellMessageEvent) {
        VCellMessageEvent vcellMessageEvent = (VCellMessageEvent) event;
        if (vcellMessageEvent.getEventTypeID() == VCellMessageEvent.VCELL_MESSAGEEVENT_TYPE_BROADCAST) {
            // Remove any existing broadcast message
            Iterator<EventWrapper> iter = events.iterator();
            while (iter.hasNext()) {
                EventWrapper eventWrapper = iter.next();
                if (eventWrapper.eventType.equals(EventWrapper.EventType.Broadcast)) {
                    iter.remove();
                }
            }
            BroadcastEventRepresentation broadcastEventRepresentation = new BroadcastEventRepresentation(vcellMessageEvent.getMessageData().getData().toString());
            // If 'clear' then don't add new broadcast message
            if (broadcastEventRepresentation.message.trim().equalsIgnoreCase("clear")) {
                return;
            }
            // Add new broadcast message
            Gson gson = new Gson();
            String eventJSON = gson.toJson(broadcastEventRepresentation);
            insert(null, EventType.Broadcast, eventJSON);
        } else {
            lg.error("event of type VCellMessageEvent:" + vcellMessageEvent.getEventTypeID() + " not supported");
        }
    } else if (event instanceof WorkerEvent) {
        lg.error("event of type WorkerEvent not supported");
        WorkerEvent workerEvent = (WorkerEvent) event;
    } else if (event instanceof PerformanceMonitorEvent) {
        lg.error("event of type PerformanceMonitorEvent not supported");
        PerformanceMonitorEvent performanceMonitorEvent = (PerformanceMonitorEvent) event;
    } else if (event instanceof DataJobEvent) {
        DataJobEvent dataJobEvent = (DataJobEvent) event;
        try {
            DataJobEventRepresentation dataJobEventRep = dataJobEvent.toJsonRep();
            DataJobEvent event2 = DataJobEvent.fromJsonRep(this, dataJobEventRep);
            if (!Compare.isEqual(event2.getDataIdString(), dataJobEvent.getDataIdString())) {
                throw new RuntimeException("DataJob event round-trip failed");
            }
            if (!Compare.isEqual(event2.getProgress(), dataJobEvent.getProgress())) {
                throw new RuntimeException("DataJob <PROGRESS> event round-trip failed");
            }
            Gson gson = new Gson();
            String eventJSON = gson.toJson(dataJobEventRep);
            insert(dataJobEventRep.username, EventType.DataJob, eventJSON);
        } catch (Exception e) {
            lg.error(e.getMessage(), e);
        }
    }
}
Also used : ExportEventRepresentation(org.vcell.api.common.events.ExportEventRepresentation) ExportEvent(cbit.rmi.event.ExportEvent) SimulationJobStatusEventRepresentation(org.vcell.api.common.events.SimulationJobStatusEventRepresentation) Gson(com.google.gson.Gson) SimulationJobStatusEvent(cbit.rmi.event.SimulationJobStatusEvent) BroadcastEventRepresentation(org.vcell.api.common.events.BroadcastEventRepresentation) DataJobEvent(cbit.rmi.event.DataJobEvent) DataJobEventRepresentation(org.vcell.api.common.events.DataJobEventRepresentation) WorkerEvent(cbit.rmi.event.WorkerEvent) VCellMessageEvent(cbit.rmi.event.VCellMessageEvent) PerformanceMonitorEvent(cbit.rmi.event.PerformanceMonitorEvent) EventWrapper(org.vcell.api.common.events.EventWrapper)

Example 2 with SimulationJobStatusEvent

use of cbit.rmi.event.SimulationJobStatusEvent 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);
    }
}
Also used : VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) VCMessageJms(cbit.vcell.message.jms.VCMessageJms) MessageData(cbit.rmi.event.MessageData) ExportEvent(cbit.rmi.event.ExportEvent) BigString(org.vcell.util.BigString) SimulationJobStatusEvent(cbit.rmi.event.SimulationJobStatusEvent) BigString(org.vcell.util.BigString) VCMessagingException(cbit.vcell.message.VCMessagingException) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) StatusMessage(cbit.vcell.message.messages.StatusMessage) DataJobEvent(cbit.rmi.event.DataJobEvent) VCellMessageEvent(cbit.rmi.event.VCellMessageEvent) SimulationJobStatus(cbit.vcell.server.SimulationJobStatus)

Example 3 with SimulationJobStatusEvent

use of cbit.rmi.event.SimulationJobStatusEvent in project vcell by virtualcell.

the class VCMongoMessage method sendClientMessageEventQueued.

public static void sendClientMessageEventQueued(MessageEvent messageEvent) {
    if (!enabled || !(messageEvent instanceof SimulationJobStatusEvent)) {
        return;
    }
    try {
        Document dbObject = new Document();
        addHeader(dbObject, MongoMessage_msgtype_clientSimStatusQueued);
        addObject(dbObject, (SimulationJobStatusEvent) messageEvent);
        VCMongoDbDriver.getInstance().addMessage(new VCMongoMessage(dbObject));
    } catch (Exception e) {
        lg.error(e.getMessage(), e);
    }
}
Also used : Document(org.bson.Document) SimulationJobStatusEvent(cbit.rmi.event.SimulationJobStatusEvent) UnknownHostException(java.net.UnknownHostException)

Example 4 with SimulationJobStatusEvent

use of cbit.rmi.event.SimulationJobStatusEvent in project vcell by virtualcell.

the class SimulationControllerImpl method onClientStatusTopic_SimulationJobStatus.

private void onClientStatusTopic_SimulationJobStatus(VCMessage simJobStatusMessage) {
    Double progress = null;
    if (simJobStatusMessage.propertyExists(MessageConstants.SIMULATION_STATUS_PROGRESS_PROPERTY)) {
        progress = simJobStatusMessage.getDoubleProperty(MessageConstants.SIMULATION_STATUS_PROGRESS_PROPERTY);
    }
    Double timepoint = null;
    if (simJobStatusMessage.propertyExists(MessageConstants.SIMULATION_STATUS_TIMEPOINT_PROPERTY)) {
        timepoint = simJobStatusMessage.getDoubleProperty(MessageConstants.SIMULATION_STATUS_TIMEPOINT_PROPERTY);
    }
    SimulationJobStatus simJobStatus = (SimulationJobStatus) simJobStatusMessage.getObjectContent();
    SimulationJobStatusEvent simulationJobStatusEvent = new SimulationJobStatusEvent(SimulationControllerImpl.this, simJobStatus.getVCSimulationIdentifier().getID(), simJobStatus, progress, timepoint, simJobStatus.getVCSimulationIdentifier().getOwner().getName());
    fireSimulationJobStatusEvent(simulationJobStatusEvent);
}
Also used : SimulationJobStatus(cbit.vcell.server.SimulationJobStatus) SimulationJobStatusEvent(cbit.rmi.event.SimulationJobStatusEvent)

Example 5 with SimulationJobStatusEvent

use of cbit.rmi.event.SimulationJobStatusEvent in project vcell by virtualcell.

the class SimulationControllerImpl method onSimJobQueue_SimulationTask.

private void onSimJobQueue_SimulationTask(VCMessage vcMessage) {
    SimulationTask simTask = null;
    try {
        SimulationTaskMessage simTaskMessage = new SimulationTaskMessage(vcMessage);
        simTask = simTaskMessage.getSimulationTask();
        LocalSolverController solverController = getOrCreateSolverController(simTask);
        // can only start after updating the database is done
        solverController.startSimulationJob();
    } catch (Exception e) {
        lg.error(e.getMessage(), e);
        KeyValue simKey = simTask.getSimKey();
        VCSimulationIdentifier vcSimID = simTask.getSimulationJob().getVCDataIdentifier().getVcSimID();
        int jobIndex = simTask.getSimulationJob().getJobIndex();
        int taskID = simTask.getTaskID();
        SimulationJobStatus newJobStatus = new SimulationJobStatus(VCellServerID.getSystemServerID(), vcSimID, jobIndex, null, SchedulerStatus.FAILED, taskID, SimulationMessage.jobFailed(e.getMessage()), null, null);
        SimulationJobStatusEvent event = new SimulationJobStatusEvent(this, Simulation.createSimulationID(simKey), newJobStatus, null, null, vcSimID.getOwner().getName());
        fireSimulationJobStatusEvent(event);
    }
}
Also used : LocalSolverController(cbit.vcell.solvers.LocalSolverController) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) SimulationTask(cbit.vcell.messaging.server.SimulationTask) KeyValue(org.vcell.util.document.KeyValue) SimulationJobStatus(cbit.vcell.server.SimulationJobStatus) SimulationJobStatusEvent(cbit.rmi.event.SimulationJobStatusEvent) SimulationTaskMessage(cbit.vcell.message.messages.SimulationTaskMessage) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) SQLException(java.sql.SQLException) VCMessagingException(cbit.vcell.message.VCMessagingException) SolverException(cbit.vcell.solver.SolverException) AuthenticationException(org.vcell.util.AuthenticationException) DataAccessException(org.vcell.util.DataAccessException) JMSException(javax.jms.JMSException) FileNotFoundException(java.io.FileNotFoundException) RemoteException(java.rmi.RemoteException) ConfigurationException(org.vcell.util.ConfigurationException)

Aggregations

SimulationJobStatusEvent (cbit.rmi.event.SimulationJobStatusEvent)8 SimulationJobStatus (cbit.vcell.server.SimulationJobStatus)5 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)4 VCMessagingException (cbit.vcell.message.VCMessagingException)3 KeyValue (org.vcell.util.document.KeyValue)3 DataJobEvent (cbit.rmi.event.DataJobEvent)2 ExportEvent (cbit.rmi.event.ExportEvent)2 MessageEvent (cbit.rmi.event.MessageEvent)2 VCellMessageEvent (cbit.rmi.event.VCellMessageEvent)2 SolverException (cbit.vcell.solver.SolverException)2 LocalSolverController (cbit.vcell.solvers.LocalSolverController)2 FileNotFoundException (java.io.FileNotFoundException)2 UnknownHostException (java.net.UnknownHostException)2 RemoteException (java.rmi.RemoteException)2 SQLException (java.sql.SQLException)2 JMSException (javax.jms.JMSException)2 Document (org.bson.Document)2 AuthenticationException (org.vcell.util.AuthenticationException)2 BigString (org.vcell.util.BigString)2 ConfigurationException (org.vcell.util.ConfigurationException)2