Search in sources :

Example 6 with DataJobEvent

use of cbit.rmi.event.DataJobEvent 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 {
        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 : DataJobEvent(cbit.rmi.event.DataJobEvent) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) ExportEvent(cbit.rmi.event.ExportEvent) MessageData(cbit.rmi.event.MessageData) SimulationJobStatus(cbit.vcell.server.SimulationJobStatus) VCellMessageEvent(cbit.rmi.event.VCellMessageEvent) BigString(org.vcell.util.BigString) SimulationJobStatusEvent(cbit.rmi.event.SimulationJobStatusEvent) BigString(org.vcell.util.BigString) VCMessagingException(cbit.vcell.message.VCMessagingException) StatusMessage(cbit.vcell.message.messages.StatusMessage)

Example 7 with DataJobEvent

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

the class FieldDataWindowManager method viewData.

public void viewData(final ExternalDataIdentifier eDI) {
    ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(getComponent());
    if (eDI != null && eDI.equals(currentlyViewedEDI) && childWindowManager != null && childWindowManager.getChildWindowFromContext(eDI) != null) {
        childWindowManager.getChildWindowFromContext(eDI).show();
    } else {
        if (currentlyViewedOutputFunctionViewer != null) {
            if (getLocalRequestManager() != null && getLocalRequestManager().getAsynchMessageManager() != null) {
                getLocalRequestManager().getAsynchMessageManager().removeDataJobListener(currentlyViewedOutputFunctionViewer.getPDEDataViewer());
            }
            if (currentlyViewedOutputFunctionViewer != null) {
                currentlyViewedOutputFunctionViewer.getPDEDataViewer().getPdeDataContext().removePropertyChangeListener(this);
            }
        }
        if (currentlyViewedOutputFunctionViewer != null) {
            ChildWindow childWindow = childWindowManager.getChildWindowFromContext(eDI);
            if (childWindow != null) {
                childWindow.close();
            }
        }
        currentlyViewedEDI = null;
        currentlyViewedOutputFunctionViewer = null;
        if (eDI == null) {
            return;
        }
        AsynchClientTask task1 = new AsynchClientTask("retrieve data", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

            @Override
            public void run(Hashtable<String, Object> hashTable) throws Exception {
                ClientPDEDataContext newPDEDataContext = getPDEDataContext(eDI, new OutputContext(new AnnotatedFunction[0]));
                hashTable.put("newPDEDataContext", newPDEDataContext);
            }
        };
        AsynchClientTask task2 = new AsynchClientTask("show data", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

            @Override
            public void run(Hashtable<String, Object> hashTable) throws Exception {
                try {
                    PDEDataViewer currentlyViewedPDEDV = new PDEDataViewer();
                    ClientPDEDataContext newPDEDataContext = (ClientPDEDataContext) hashTable.get("newPDEDataContext");
                    currentlyViewedPDEDV.setPdeDataContext(newPDEDataContext);
                    newPDEDataContext.addPropertyChangeListener(FieldDataWindowManager.this);
                    getLocalRequestManager().getAsynchMessageManager().addDataJobListener(currentlyViewedPDEDV);
                    currentlyViewedOutputFunctionViewer = new OutputFunctionViewer(currentlyViewedPDEDV, FieldDataWindowManager.this, eDI);
                    DataViewerManager dvm = new DataViewerManager() {

                        public void dataJobMessage(DataJobEvent event) {
                        }

                        public void exportMessage(ExportEvent event) {
                        }

                        public void addDataListener(DataListener newListener) {
                        }

                        public UserPreferences getUserPreferences() {
                            return getRequestManager().getUserPreferences();
                        }

                        public void removeDataListener(DataListener newListener) {
                        }

                        public void startExport(Component requester, OutputContext outputContext, ExportSpecs exportSpecs) {
                            getLocalRequestManager().startExport(outputContext, requester, exportSpecs);
                        }

                        public void simStatusChanged(SimStatusEvent simStatusEvent) {
                        }

                        public User getUser() {
                            return getRequestManager().getDocumentManager().getUser();
                        }

                        public RequestManager getRequestManager() {
                            return FieldDataWindowManager.this.getRequestManager();
                        }
                    };
                    try {
                        currentlyViewedPDEDV.setDataViewerManager(dvm);
                    } catch (PropertyVetoException e) {
                        e.printStackTrace();
                    }
                    ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(getComponent());
                    currentlyViewedEDI = eDI;
                    ChildWindow childWindow = childWindowManager.addChildWindow(currentlyViewedOutputFunctionViewer, currentlyViewedEDI, "Field Data Viewer (" + eDI.getName() + ")");
                    childWindow.setSize(600, 500);
                    childWindow.setIsCenteredOnParent();
                    childWindow.show();
                } catch (Exception e) {
                    if (currentlyViewedOutputFunctionViewer != null) {
                        if (getLocalRequestManager() != null && getLocalRequestManager().getAsynchMessageManager() != null) {
                            getLocalRequestManager().getAsynchMessageManager().removeDataJobListener(currentlyViewedOutputFunctionViewer.getPDEDataViewer());
                        }
                        if (currentlyViewedOutputFunctionViewer != null) {
                            currentlyViewedOutputFunctionViewer.getPDEDataViewer().getPdeDataContext().removePropertyChangeListener(FieldDataWindowManager.this);
                        }
                    }
                    throw e;
                }
            }
        };
        ClientTaskDispatcher.dispatch(this.getComponent(), new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 }, false);
    }
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) ExportEvent(cbit.rmi.event.ExportEvent) ExportSpecs(cbit.vcell.export.server.ExportSpecs) ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow) OutputContext(cbit.vcell.simdata.OutputContext) PropertyVetoException(java.beans.PropertyVetoException) DataAccessException(org.vcell.util.DataAccessException) UserCancelException(org.vcell.util.UserCancelException) PropertyVetoException(java.beans.PropertyVetoException) DataJobEvent(cbit.rmi.event.DataJobEvent) SimStatusEvent(cbit.vcell.client.server.SimStatusEvent) ClientPDEDataContext(cbit.vcell.simdata.ClientPDEDataContext) DataListener(cbit.vcell.simdata.DataListener) Component(java.awt.Component) PDEDataViewer(cbit.vcell.client.data.PDEDataViewer) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

Example 8 with DataJobEvent

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

the class ImportRawTimeSeriesFrom2DVCellConcentrationsOp method importRawTimeSeries.

private static ImageDataset importRawTimeSeries(File vcellSimLogFile, String fluorFunctionName, Double maxIntensity, boolean bNoise, final ClientTaskStatusSupport progressListener) throws Exception {
    VCSimulationIdentifier vcSimulationIdentifier = VCellSimReader.getVCSimulationIdentifierFromVCellSimulationData(vcellSimLogFile);
    VCSimulationDataIdentifier vcSimulationDataIdentifier = new VCSimulationDataIdentifier(vcSimulationIdentifier, 0);
    DataSetControllerImpl dataSetControllerImpl = VCellSimReader.getDataSetControllerImplFromVCellSimulationData(vcellSimLogFile);
    final DataJobEvent[] bStatus = new DataJobEvent[] { null };
    DataJobListener dataJobListener = new DataJobListener() {

        public void dataJobMessage(DataJobEvent event) {
            bStatus[0] = event;
            if (progressListener != null) {
                progressListener.setProgress((int) (event.getProgress() / 100.0 * .75));
            }
        }
    };
    dataSetControllerImpl.addDataJobListener(dataJobListener);
    DataIdentifier[] dataIdentifiers = VCellSimReader.getDataIdentiferListFromVCellSimulationData(vcellSimLogFile, 0);
    DataIdentifier variableNameDataIdentifier = null;
    for (int i = 0; i < dataIdentifiers.length; i++) {
        if (dataIdentifiers[i].getName().equals(fluorFunctionName)) {
            variableNameDataIdentifier = dataIdentifiers[i];
            break;
        }
    }
    if (variableNameDataIdentifier == null) {
        throw new IllegalArgumentException("Variable " + fluorFunctionName + " not found.");
    }
    if (!variableNameDataIdentifier.getVariableType().equals(VariableType.VOLUME)) {
        throw new IllegalArgumentException("Variable " + fluorFunctionName + " is not VOLUME type.");
    }
    double[] times = dataSetControllerImpl.getDataSetTimes(vcSimulationDataIdentifier);
    CartesianMesh cartesianMesh = dataSetControllerImpl.getMesh(vcSimulationDataIdentifier);
    BitSet allBitset = new BitSet(cartesianMesh.getNumVolumeElements());
    allBitset.set(0, cartesianMesh.getNumVolumeElements() - 1);
    TimeSeriesJobSpec timeSeriesJobSpec = new TimeSeriesJobSpec(new String[] { fluorFunctionName }, new BitSet[] { allBitset }, times[0], 1, times[times.length - 1], true, false, VCDataJobID.createVCDataJobID(VCellSimReader.getDotUser(), true));
    TSJobResultsSpaceStats tsJobResultsSpaceStats = (TSJobResultsSpaceStats) dataSetControllerImpl.getTimeSeriesValues(null, vcSimulationDataIdentifier, timeSeriesJobSpec);
    // wait for job to finish
    while (bStatus[0] == null || bStatus[0].getEventTypeID() != DataJobEvent.DATA_COMPLETE) {
        Thread.sleep(100);
    }
    double allTimesMin = tsJobResultsSpaceStats.getMinimums()[0][0];
    double allTimesMax = allTimesMin;
    for (int i = 0; i < times.length; i++) {
        allTimesMin = Math.min(allTimesMin, tsJobResultsSpaceStats.getMinimums()[0][i]);
        allTimesMax = Math.max(allTimesMax, tsJobResultsSpaceStats.getMaximums()[0][i]);
    }
    // double SCALE_MAX = maxIntensity.doubleValue();/*Math.pow(2,16)-1;*///Scale to 16 bits
    double linearScaleFactor = 1;
    if (maxIntensity != null) {
        linearScaleFactor = maxIntensity.doubleValue() / allTimesMax;
    }
    System.out.println("alltimesMin=" + allTimesMin + " allTimesMax=" + allTimesMax + " linearScaleFactor=" + linearScaleFactor);
    UShortImage[] scaledDataImages = new UShortImage[times.length];
    Random rnd = new Random();
    int shortMax = 65535;
    // set messge to load variable
    if (progressListener != null) {
        progressListener.setMessage("Loading variable " + fluorFunctionName + "...");
    }
    for (int i = 0; i < times.length; i++) {
        double[] rawData = dataSetControllerImpl.getSimDataBlock(null, vcSimulationDataIdentifier, fluorFunctionName, times[i]).getData();
        short[] scaledDataShort = new short[rawData.length];
        for (int j = 0; j < scaledDataShort.length; j++) {
            double scaledRawDataJ = rawData[j] * linearScaleFactor;
            if (bNoise) {
                double ran = rnd.nextGaussian();
                double scaledRawDataJ_withNoise = Math.max(0, (scaledRawDataJ + ran * Math.sqrt(scaledRawDataJ)));
                scaledRawDataJ_withNoise = Math.min(shortMax, scaledRawDataJ_withNoise);
                int scaledValue = (int) (scaledRawDataJ_withNoise);
                scaledDataShort[j] &= 0x0000;
                scaledDataShort[j] |= 0x0000FFFF & scaledValue;
            } else {
                int scaledValue = (int) (scaledRawDataJ);
                scaledDataShort[j] &= 0x0000;
                scaledDataShort[j] |= 0x0000FFFF & scaledValue;
            }
        }
        scaledDataImages[i] = new UShortImage(scaledDataShort, cartesianMesh.getOrigin(), cartesianMesh.getExtent(), cartesianMesh.getSizeX(), cartesianMesh.getSizeY(), cartesianMesh.getSizeZ());
        if (progressListener != null) {
            int progress = (int) (((i + 1) * 1.0 / times.length) * 100);
            progressListener.setProgress(progress);
        }
    }
    ImageDataset rawImageDataSet = new ImageDataset(scaledDataImages, times, cartesianMesh.getSizeZ());
    return rawImageDataSet;
}
Also used : VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) DataIdentifier(cbit.vcell.simdata.DataIdentifier) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) TimeSeriesJobSpec(org.vcell.util.document.TimeSeriesJobSpec) ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) BitSet(java.util.BitSet) TSJobResultsSpaceStats(org.vcell.util.document.TSJobResultsSpaceStats) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) DataJobEvent(cbit.rmi.event.DataJobEvent) CartesianMesh(cbit.vcell.solvers.CartesianMesh) Random(java.util.Random) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) DataJobListener(cbit.rmi.event.DataJobListener)

Aggregations

DataJobEvent (cbit.rmi.event.DataJobEvent)8 ExportEvent (cbit.rmi.event.ExportEvent)4 ExportSpecs (cbit.vcell.export.server.ExportSpecs)3 DataIdentifier (cbit.vcell.simdata.DataIdentifier)3 OutputContext (cbit.vcell.simdata.OutputContext)3 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)3 CartesianMesh (cbit.vcell.solvers.CartesianMesh)3 TimeSeriesJobSpec (org.vcell.util.document.TimeSeriesJobSpec)3 DataJobListener (cbit.rmi.event.DataJobListener)2 SimulationJobStatusEvent (cbit.rmi.event.SimulationJobStatusEvent)2 VCellMessageEvent (cbit.rmi.event.VCellMessageEvent)2 ImageDataset (cbit.vcell.VirtualMicroscopy.ImageDataset)2 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)2 PDEDataViewer (cbit.vcell.client.data.PDEDataViewer)2 SimStatusEvent (cbit.vcell.client.server.SimStatusEvent)2 DataSetControllerProvider (cbit.vcell.server.DataSetControllerProvider)2 ClientPDEDataContext (cbit.vcell.simdata.ClientPDEDataContext)2 DataListener (cbit.vcell.simdata.DataListener)2 DataSetControllerImpl (cbit.vcell.simdata.DataSetControllerImpl)2 VCDataIdentifier (org.vcell.util.document.VCDataIdentifier)2