List of usage examples for java.lang IllegalThreadStateException printStackTrace
public void printStackTrace()
From source file:org.kalypso.optimize.SceJob.java
private void startSCEOptimization(final SceIOHandler sceIO, final ISimulationMonitor monitor) throws SimulationException { InputStreamReader inStream = null; InputStreamReader errStream = null; // FIXME: too much copy/paste from ProcessHelper; we can probably use process helper instead! ProcessControlThread procCtrlThread = null; try {/*from w w w . j a va2s . co m*/ final String[] commands = new String[] { m_sceExe.getAbsolutePath() }; final Process process = Runtime.getRuntime().exec(commands, null, m_sceDir); final long lTimeOut = 1000l * 60l * 15l;// 15 minutes procCtrlThread = new ProcessControlThread(process, lTimeOut); procCtrlThread.start(); final StringBuffer outBuffer = new StringBuffer(); final StringBuffer errBuffer = new StringBuffer(); final Writer inputWriter = new PrintWriter(process.getOutputStream(), false); inStream = new InputStreamReader(process.getInputStream()); errStream = new InputStreamReader(process.getErrorStream()); final int stepMax = m_autoCalibration.getOptParameter().getMaxN(); while (true) { final int step = sceIO.getStep(); monitor.setProgress(100 * step / (stepMax + 1)); if (step > stepMax) { final String monitorMsg = String.format( "Optimierungsrechnung abgeschlossen, Ergebnisauswertung", step + 1, stepMax + 1); monitor.setMessage(monitorMsg); } else { final String monitorMsg = String.format("Optimierungsrechnung %d von %d", step + 1, stepMax + 1); monitor.setMessage(monitorMsg); } if (inStream.ready()) { final char buffer[] = new char[100]; final int bufferC = inStream.read(buffer); outBuffer.append(buffer, 0, bufferC); } if (errStream.ready()) { final char buffer[] = new char[100]; final int bufferC = errStream.read(buffer); errBuffer.append(buffer, 0, bufferC); } if (monitor.isCanceled()) { process.destroy(); procCtrlThread.endProcessControl(); return; } try { process.exitValue(); break; } catch (final IllegalThreadStateException e) { final OptimizeMonitor subMonitor = new OptimizeMonitor(monitor); sceIO.handleStreams(outBuffer, errBuffer, inputWriter, subMonitor); } Thread.sleep(100); } procCtrlThread.endProcessControl(); } catch (final IOException e) { e.printStackTrace(); throw new SimulationException("Fehler beim Ausfuehren", e); } catch (final InterruptedException e) { e.printStackTrace(); throw new SimulationException("beim Ausfuehren unterbrochen", e); } finally { IOUtils.closeQuietly(inStream); IOUtils.closeQuietly(errStream); if (procCtrlThread != null && procCtrlThread.procDestroyed()) { throw new SimulationException("beim Ausfuehren unterbrochen", new ProcessTimeoutException("Timeout bei der Abarbeitung der Optimierung")); } } }
From source file:org.kalypso.commons.java.lang.ProcessHelper.java
/** * startet Prozess (sCmd, envp, fleExeDir), schreibt Ausgaben nach wLog, wErr, beendet den Prozess automatisch nach * iTOut ms (iTOut = 0 bedeutet, dass der Prozess nicht abgebrochen wird), die Abarbeitung des Prozesses beachtet auch * den Cancel-Status von cancelable//w w w . j a va 2s . c o m * * @throws IOException * @throws ProcessTimeoutException */ public int start() throws IOException, ProcessTimeoutException { try { m_process = createProcess(); if (m_timeOut > 0) { m_procCtrlThread = new ProcessControlThread(m_process, m_timeOut); m_procCtrlThread.start(); } new StreamStreamer(m_process.getInputStream(), m_outStream); new StreamStreamer(m_process.getErrorStream(), m_errStream); new StreamStreamer(m_inStream, m_process.getOutputStream()); // TODO: separate creation of process from waiting for process while (true) { try { m_returnValue = m_process.exitValue(); break; } catch (final IllegalThreadStateException e) { // Prozess noch nicht fertig, weiterlaufen lassen } if (checkForCancel()) return m_returnValue; runIdle(); Thread.sleep(m_sleepTime); } if (m_procCtrlThread != null) m_procCtrlThread.endProcessControl(); } catch (final InterruptedException e) { // kann aber eigentlich gar nicht passieren // (wird geworfen von Thread.sleep( 100 )) e.printStackTrace(); } if (m_procCtrlThread != null && m_procCtrlThread.procDestroyed()) { final String command = m_commands == null ? m_commandLine : StringUtils.join(m_commands); throw new ProcessTimeoutException( Messages.getString("org.kalypso.commons.java.lang.ProcessHelper.1", command)); //$NON-NLS-1$ } return m_returnValue; }
From source file:pl.robakowski.repository.Repository.java
@Override public List<JSONObject> getNextResults(final IProgressMonitor monitor) { moreResults = false;//w w w . j a va 2 s. co m List<JSONObject> list = new ArrayList<JSONObject>(30); if (!checkRuntime()) { sync.asyncExec(new Runnable() { @Override public void run() { MessageDialog dialog = new MessageDialog(shell, "Wrong paths", null, "Invalid path to PHP or composer.phar", MessageDialog.ERROR, new String[] { "OK" }, 0); dialog.setBlockOnOpen(true); dialog.open(); Map<String, String> params = new HashMap<String, String>(); params.put("preferencePageId", "pl.robakowski.composer.plugin.page1"); ParameterizedCommand command = commandService.createCommand("org.eclipse.ui.window.preferences", params); handlerService.executeHandler(command); } }); return list; } writeJson(json); try { final Process exec = new ProcessBuilder().command(phpPath, composerPath, "search", query).start(); Thread killer = new Thread() { private boolean terminated(Process exec) { try { exec.exitValue(); return true; } catch (IllegalThreadStateException e) { return false; } } @Override public void run() { while (!terminated(exec)) { if (monitor.isCanceled()) { exec.destroy(); } try { Thread.sleep(50); } catch (InterruptedException e) { } } }; }; killer.start(); BufferedReader reader = new BufferedReader(new InputStreamReader(exec.getInputStream())); String line; while ((line = reader.readLine()) != null) { int space = line.indexOf(' '); String name = line.substring(0, space); String repository = line.substring(space + 1); JSONObject obj = new JSONObject(); obj.put("name", name); obj.put("description", repository); list.add(obj); } exec.waitFor(); } catch (Exception e) { e.printStackTrace(); } return list; }
From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java
public String UnInstallApp(String sApp, OutputStream out, boolean reboot) { String sRet = ""; try {//www.j a va2s. co m if (reboot == true) { pProc = Runtime.getRuntime().exec(this.getSuArgs("pm uninstall " + sApp + ";reboot;exit")); } else { pProc = Runtime.getRuntime().exec(this.getSuArgs("pm uninstall " + sApp + ";exit")); } RedirOutputThread outThrd = new RedirOutputThread(pProc, out); outThrd.start(); try { outThrd.joinAndStopRedirect(60000); int nRet = pProc.exitValue(); sRet = "\nuninst complete [" + nRet + "]"; } catch (IllegalThreadStateException itse) { itse.printStackTrace(); sRet = "\nuninst command timed out"; } } catch (IOException e) { sRet = e.getMessage(); e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } return (sRet); }
From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java
public String InstallApp(String sApp, OutputStream out) { String sRet = ""; File srcFile = new File(sApp); try {/*from w ww. j a va 2 s . c o m*/ // on android 4.2 and above, we want to pass the "-d" argument to pm so that version // downgrades are allowed... (option unsupported in earlier versions) String sPmCmd; if (android.os.Build.VERSION.SDK_INT >= 17) { // JELLY_BEAN_MR1 sPmCmd = "pm install -r -d " + sApp + " Cleanup;exit"; } else { sPmCmd = "pm install -r " + sApp + " Cleanup;exit"; } pProc = Runtime.getRuntime().exec(this.getSuArgs(sPmCmd)); RedirOutputThread outThrd3 = new RedirOutputThread(pProc, out); outThrd3.start(); try { outThrd3.joinAndStopRedirect(60000); int nRet3 = pProc.exitValue(); if (nRet3 == 0) { sRet = "\ninstallation complete [0]\n"; } else { sRet = "\nFailure pm install [" + nRet3 + "]\n"; } } catch (IllegalThreadStateException itse) { itse.printStackTrace(); sRet = "\nFailure pm install command timed out\n"; } try { out.write(sRet.getBytes()); out.flush(); } catch (IOException e1) { e1.printStackTrace(); } } catch (IOException e) { sRet = e.getMessage(); e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } return (sRet); }