Search in sources :

Example 46 with EventObject

use of java.util.EventObject in project vcell by virtualcell.

the class ClientSimManager method runSmoldynParticleView.

public void runSmoldynParticleView(final Simulation originalSimulation) {
    SimulationOwner simulationOwner = simWorkspace.getSimulationOwner();
    Collection<AsynchClientTask> tasks;
    if (simulationOwner instanceof SimulationContext) {
        tasks = ClientRequestManager.updateMath(documentWindowManager.getComponent(), (SimulationContext) simulationOwner, false, NetworkGenerationRequirements.ComputeFullStandardTimeout);
    } else {
        tasks = new ArrayList<>();
    }
    AsynchClientTask pv = new AsynchClientTask("starting particle view", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            File[] exes = SolverUtilities.getExes(SolverDescription.Smoldyn);
            assert exes.length == 1 : "one and only one smoldyn solver expected";
            File smoldynExe = exes[0];
            Simulation simulation = new TempSimulation(originalSimulation, false);
            SimulationTask simTask = new SimulationTask(new SimulationJob(simulation, 0, null), 0);
            File inputFile = new File(ResourceUtil.getLocalSimDir(User.tempUser.getName()), simTask.getSimulationJobID() + SimDataConstants.SMOLDYN_INPUT_FILE_EXTENSION);
            inputFile.deleteOnExit();
            PrintWriter pw = new PrintWriter(inputFile);
            SmoldynFileWriter smf = new SmoldynFileWriter(pw, true, null, simTask, false);
            smf.write();
            pw.close();
            String[] cmd = new String[] { smoldynExe.getAbsolutePath(), inputFile.getAbsolutePath() };
            StringBuilder commandLine = new StringBuilder();
            for (int i = 0; i < cmd.length; i++) {
                if (i > 0) {
                    commandLine.append(" ");
                }
                commandLine.append(TokenMangler.getEscapedPathName(cmd[i]));
            }
            System.out.println(commandLine);
            char[] charArrayOut = new char[10000];
            char[] charArrayErr = new char[10000];
            ProcessBuilder processBuilder = new ProcessBuilder(cmd);
            final Process process = processBuilder.start();
            getClientTaskStatusSupport().addProgressDialogListener(new ProgressDialogListener() {

                public void cancelButton_actionPerformed(EventObject newEvent) {
                    process.destroy();
                }
            });
            InputStream errorStream = process.getErrorStream();
            InputStreamReader errisr = new InputStreamReader(errorStream);
            InputStream outputStream = process.getInputStream();
            InputStreamReader outisr = new InputStreamReader(outputStream);
            StringBuilder sb = new StringBuilder();
            boolean running = true;
            while (running) {
                try {
                    process.exitValue();
                    running = false;
                } catch (IllegalThreadStateException e) {
                // process didn't exit yet, do nothing
                }
                if (outputStream.available() > 0) {
                    outisr.read(charArrayOut, 0, charArrayOut.length);
                }
                if (errorStream.available() > 0) {
                    errisr.read(charArrayErr, 0, charArrayErr.length);
                    sb.append(new String(charArrayErr));
                }
            }
            if (sb.length() > 0) {
                throw new RuntimeException(sb.toString());
            }
        }
    };
    tasks.add(pv);
    ClientTaskDispatcher.dispatchColl(documentWindowManager.getComponent(), new Hashtable<String, Object>(), tasks, false, true, null);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) SimulationTask(cbit.vcell.messaging.server.SimulationTask) SmoldynFileWriter(org.vcell.solver.smoldyn.SmoldynFileWriter) SimulationOwner(cbit.vcell.solver.SimulationOwner) ProgressDialogListener(org.vcell.util.ProgressDialogListener) SimulationJob(cbit.vcell.solver.SimulationJob) PrintWriter(java.io.PrintWriter) InputStreamReader(java.io.InputStreamReader) Hashtable(java.util.Hashtable) InputStream(java.io.InputStream) TempSimulation(cbit.vcell.solver.TempSimulation) SimulationContext(cbit.vcell.mapping.SimulationContext) EventObject(java.util.EventObject) Simulation(cbit.vcell.solver.Simulation) TempSimulation(cbit.vcell.solver.TempSimulation) EventObject(java.util.EventObject) File(java.io.File)

Example 47 with EventObject

use of java.util.EventObject in project vcell by virtualcell.

the class VCDocumentDbTreePanel method search.

public void search(final boolean bShowAll) {
    final Object[] status = new Object[] { null };
    class SearchCancel implements ProgressDialogListener {

        public void cancelButton_actionPerformed(EventObject newEvent) {
            status[0] = UserCancelException.CANCEL_GENERIC;
        }
    }
    final SearchCancel searchCancel = new SearchCancel();
    final ArrayList<SearchCriterion> searchCriterionListFinal = new ArrayList<DatabaseSearchPanel.SearchCriterion>();
    AsynchClientTask searchCriteriaTask = new AsynchClientTask("Creating search criteria...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING, true) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            if (bShowAll) {
                return;
            }
            new Thread(new Runnable() {

                public void run() {
                    try {
                        ArrayList<SearchCriterion> searchCriterionList = getDatabaseSearchPanel().getSearchCriterionList(getDocumentManager());
                        if (status[0] == null) {
                            // update status only if no one else has
                            if (searchCriterionList != null && searchCriterionList.size() > 0) {
                                searchCriterionListFinal.addAll(searchCriterionList);
                            }
                            status[0] = "OK";
                            return;
                        } else {
                            return;
                        }
                    } catch (Exception e) {
                        status[0] = e;
                    }
                }
            }).start();
            long startTime = System.currentTimeMillis();
            while ((System.currentTimeMillis() - startTime) < 60000) {
                if (status[0] != null) {
                    if (status[0] instanceof Exception) {
                        // User cancelled or there was an exception in search criteria thread
                        throw (Exception) status[0];
                    }
                    // search criteria thread completed with 'OK'
                    return;
                }
                try {
                    Thread.sleep(100);
                } catch (InterruptedException ie) {
                // ignore
                }
            }
            throw new Exception("getSearchCriterionList timed out");
        }
    };
    AsynchClientTask refreshTask = new AsynchClientTask("Refreshing tree...", AsynchClientTask.TASKTYPE_SWING_BLOCKING, false) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            if (searchCriterionListFinal.size() > 0) {
                // show with search criteria
                refresh(searchCriterionListFinal);
            } else {
                // show all
                refresh(null);
            }
        }
    };
    Hashtable<String, Object> hashTable = new Hashtable<String, Object>();
    if (!bShowAll && getDatabaseSearchPanel().hasRemoteDatabaseSearchDefined()) {
        ClientTaskDispatcher.dispatch(this, hashTable, new AsynchClientTask[] { searchCriteriaTask, refreshTask }, true, false, true, searchCancel, true);
    } else {
        try {
            searchCriteriaTask.run(hashTable);
            refreshTask.run(hashTable);
        } catch (Exception e) {
            e.printStackTrace();
            DialogUtils.showErrorDialog(this, e.getMessage());
        }
    }
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) DatabaseSearchPanel(cbit.vcell.client.desktop.DatabaseSearchPanel) EventObject(java.util.EventObject) DataAccessException(org.vcell.util.DataAccessException) UserCancelException(org.vcell.util.UserCancelException) ProgressDialogListener(org.vcell.util.ProgressDialogListener) SearchCriterion(cbit.vcell.client.desktop.DatabaseSearchPanel.SearchCriterion) EventObject(java.util.EventObject)

Example 48 with EventObject

use of java.util.EventObject in project vcell by virtualcell.

the class BNGWindowManager method runBioNetGen.

/**
 * Gets the bngOutputPanel property (cbit.vcell.client.bionetgen.BNGOutputPanel) value.
 * @return The bngOutputPanel property value.
 */
public void runBioNetGen(BNGInput bngInput) {
    // Create a hash and put in the details required to run the ClientTaskDispatcher
    Hashtable<String, Object> hash = new Hashtable<String, Object>();
    hash.put(BNG_OUTPUT_PANEL, getBngOutputPanel());
    final BNGExecutorService bngService = BNGExecutorService.getInstance(bngInput, NetworkGenerationRequirements.NoTimeoutMS);
    // Create the AsynchClientTasks : in this case, running the BioNetGen (non-swing) and then displaying the output (swing) tasks.
    AsynchClientTask[] tasksArray = new AsynchClientTask[2];
    tasksArray[0] = new RunBioNetGen(bngService);
    tasksArray[1] = new DisplayBNGOutput();
    // Dispatch the tasks using the ClientTaskDispatcher.
    ClientTaskDispatcher.dispatch(getBngOutputPanel(), hash, tasksArray, false, true, new ProgressDialogListener() {

        public void cancelButton_actionPerformed(EventObject newEvent) {
            try {
                bngService.stopBNG();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) ProgressDialogListener(org.vcell.util.ProgressDialogListener) Hashtable(java.util.Hashtable) DisplayBNGOutput(cbit.vcell.client.task.DisplayBNGOutput) EventObject(java.util.EventObject) BNGExecutorService(cbit.vcell.server.bionetgen.BNGExecutorService) RunBioNetGen(cbit.vcell.client.task.RunBioNetGen) EventObject(java.util.EventObject) IOException(java.io.IOException) UserCancelException(org.vcell.util.UserCancelException)

Example 49 with EventObject

use of java.util.EventObject in project vcell by virtualcell.

the class DocumentWindow method startVCellVisIt.

private void startVCellVisIt() {
    AsynchClientTask findVisitTask = new AsynchClientTask("Searching for VisIt...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            try {
                VisitSupport.launchVisTool(VCellConfiguration.getFileProperty(PropertyLoader.visitExe));
            } catch (Exception e) {
                e.printStackTrace();
                OperatingSystemInfo osi = OperatingSystemInfo.getInstance();
                String executableName = ResourceUtil.getExecutableName(VisitSupport.VISIT_EXEC_NAME, false, osi);
                File executableLocation = new ExecutableFinderDialog(DocumentWindow.this, "If VisIt is installed (from " + "https://wci.llnl.gov/codes/visit/" + ") but not in the system path, then press press '" + ExecutableFinderDialog.FIND + "' and navigate to '" + executableName + "'.\nElse please install VisIt, restart VCell, and try again").find(executableName);
                VisitSupport.launchVisTool(executableLocation);
            }
        }
    };
    ProgressDialogListener progressDialogListener = new ProgressDialogListener() {

        @Override
        public void cancelButton_actionPerformed(EventObject newEvent) {
            System.out.println(newEvent);
        }
    };
    // ClientTaskDispatcher.dispatch(requester,           hash,              tasks,                                  customDialog, bShowProgressPopup, bKnowProgress, cancelable, progressDialogListener, bInputBlocking);
    ClientTaskDispatcher.dispatch(DocumentWindow.this, new Hashtable<>(), new AsynchClientTask[] { findVisitTask }, null, true, false, true, progressDialogListener, false);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) ProgressDialogListener(org.vcell.util.ProgressDialogListener) ExecutableFinderDialog(org.vcell.util.gui.ExecutableFinderDialog) Hashtable(java.util.Hashtable) OperatingSystemInfo(cbit.vcell.resource.OperatingSystemInfo) File(java.io.File) UtilCancelException(org.vcell.util.UtilCancelException) EventObject(java.util.EventObject)

Example 50 with EventObject

use of java.util.EventObject in project Payara by payara.

the class CheckMgr method fireTestFinishedEvent.

// call once per test, when r is complete
protected void fireTestFinishedEvent(Result r) {
    Object[] listeners;
    synchronized (listenerList) {
        listeners = listenerList.toArray();
    }
    if (listeners == null)
        return;
    // those that are interested in this event
    for (int i = 0; i < listeners.length; i++) {
        if (listeners[i] instanceof VerifierEventsListener) {
            // create the event:
            EventObject event = new EventObject(r);
            ((VerifierEventsListener) listeners[i]).testFinished(event);
        }
    }
}
Also used : EventObject(java.util.EventObject) EventObject(java.util.EventObject)

Aggregations

EventObject (java.util.EventObject)111 EventFactory (org.apache.camel.spi.EventFactory)25 EventNotifier (org.apache.camel.spi.EventNotifier)25 ManagementStrategy (org.apache.camel.spi.ManagementStrategy)25 AlertHandler (edu.cmu.cs.hcii.cogtool.util.AlertHandler)21 EventNotifierSupport (org.apache.camel.support.EventNotifierSupport)15 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)10 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)9 Hashtable (java.util.Hashtable)8 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)7 ProgressDialogListener (org.vcell.util.ProgressDialogListener)7 Test (org.junit.Test)6 MouseEvent (java.awt.event.MouseEvent)4 File (java.io.File)4 ExchangeCompletedEvent (org.apache.camel.management.event.ExchangeCompletedEvent)4 ClientConfig (com.hazelcast.client.config.ClientConfig)3 Design (edu.cmu.cs.hcii.cogtool.model.Design)3 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)3 DesignEditorFrame (edu.cmu.cs.hcii.cogtool.uimodel.DesignEditorFrame)3 PreferencesHandler (jmri.plaf.macosx.PreferencesHandler)3