Search in sources :

Example 1 with BroadcastEventRepresentation

use of org.vcell.api.common.events.BroadcastEventRepresentation 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)

Aggregations

DataJobEvent (cbit.rmi.event.DataJobEvent)1 ExportEvent (cbit.rmi.event.ExportEvent)1 PerformanceMonitorEvent (cbit.rmi.event.PerformanceMonitorEvent)1 SimulationJobStatusEvent (cbit.rmi.event.SimulationJobStatusEvent)1 VCellMessageEvent (cbit.rmi.event.VCellMessageEvent)1 WorkerEvent (cbit.rmi.event.WorkerEvent)1 Gson (com.google.gson.Gson)1 BroadcastEventRepresentation (org.vcell.api.common.events.BroadcastEventRepresentation)1 DataJobEventRepresentation (org.vcell.api.common.events.DataJobEventRepresentation)1 EventWrapper (org.vcell.api.common.events.EventWrapper)1 ExportEventRepresentation (org.vcell.api.common.events.ExportEventRepresentation)1 SimulationJobStatusEventRepresentation (org.vcell.api.common.events.SimulationJobStatusEventRepresentation)1