List of usage examples for java.lang InterruptedException toString
public String toString()
From source file:org.smartfrog.avalanche.client.sf.exec.simple.StartComponent.java
public void stopApplication() throws IOException, InterruptedException { readOutput();//from www. j ava 2 s .co m try { proc.destroy(); proc.waitFor(); log.debug("Destroyed Process " + command + " forcibly"); stdInput.close(); stdError.close(); log.info(componentName + " : Process exited with return value " + proc.exitValue()); } catch (IOException ioe) { log.error("Unable to close InputStream and ErrorStream for " + command, ioe); throw new IOException(ioe.toString()); } catch (IllegalThreadStateException ite) { log.error("Unable to kill the process " + command, ite); throw new IllegalStateException(ite.toString()); } catch (InterruptedException ie) { log.error("Interrupted. Waiting for process " + command + " to die", ie); throw new InterruptedException(ie.toString()); } }
From source file:org.j4me.collections.CubbyHole.java
/** * Tests that a cubby hole stores exactly one object. Thread synchronization * is not covered by this test case. */// w ww. j a va 2 s . c o m public void testBasics() { try { CubbyHole cubby = new CubbyHole(); // Very there is nothing in the empty cubby hole. boolean isEmpty = cubby.empty(); assertTrue("The cubby hole is empty.", isEmpty); Object peek = cubby.peek(); assertNull("Nothing comes from peaking into an empty cubby hole.", peek); // Put something into the cubby hole. Integer i = new Integer(13); cubby.set(i); isEmpty = cubby.empty(); assertFalse("The cubby hole has something in it.", isEmpty); peek = cubby.peek(); assertSame("The cubby hole correctly stored our object.", i, peek); Object get = cubby.get(); assertSame("Got the object stored in the cubby.", i, get); // The cubby hole should once again be empty. isEmpty = cubby.empty(); assertTrue("The cubby hole is empty again.", isEmpty); peek = cubby.peek(); assertNull("Nothing comes from peaking into the empty again cubby hole.", peek); // Put several objects into the cubby hole before taking one out. Integer i1 = new Integer(1); Integer i2 = new Integer(2); Integer i3 = new Integer(3); get = cubby.set(i1); assertNull("Nothing returned from empty cubby hole.", get); get = cubby.set(i2); assertSame("Old data i1 returned from cubby hole.", i1, get); get = cubby.set(i3); assertSame("Old data i2 returned from cubby hole.", i2, get); get = cubby.get(); assertSame("Newest data is in cubby hole.", i3, get); } catch (InterruptedException e) { fail(e.toString()); } }
From source file:com.mdsh.test.media.encoding.process.AbstractProcess.java
/** * Waits for the given thread to end./*ww w . jav a2s . c om*/ * <p>Note: InterruptedExceptions are caught and logged, * but otherwise ignored. * @param thread */ protected void waitForThread(final Thread thread) { try { thread.join(); } catch (final InterruptedException e) { getLogger().debug("waiting for thread was interrupted: {}", e.toString(), e); } }
From source file:uk.co.modularaudio.util.atomicio.unix.UnixAtomicFileUtilities.java
/** * <P>/*from w w w . j a v a 2 s . co m*/ * Use mv to move the file to its new name. On Unix MV is guaranteed to be * atomic (on the same partition). * </P> * <P> * <B>All paths should be ABSOLUTE, and must be on the same partition - and * working that out is left to the calling code.</B> * </P> * * @see uk.co.modularaudio.util.atomicio.AtomicFileUtilities#moveFile(String, * String) */ @Override public boolean moveFile(final String fromPath, final String toPath) throws IOException { boolean retVal = false; final File fromFile = new File(fromPath); final File toFile = new File(toPath); if (fromFile.getParentFile().getPath().equals(toFile.getParentFile().getPath())) { // Do java rename which is atomic if parent dirs are the same retVal = fromFile.renameTo(toFile); } else { if (fromPath == null || fromPath.equals("")) { final String msg = "AtomicFileUtilities does not support a NULL fromPath for copy."; log.error(msg); throw new IOException(msg); } if (toPath == null || toPath.equals("")) { final String msg = "AtomicFileUtilities does not support a NULL toPath for copy."; log.error(msg); throw new IOException(msg); } final String cmdArray[] = new String[3]; cmdArray[0] = mvLocation; cmdArray[1] = fromPath; cmdArray[2] = toPath; // Simple system call. Or at least it would be simple, if we knew // where // the binary lives _all_ the time. final Runtime runtime = Runtime.getRuntime(); final Process executor = runtime.exec(cmdArray); try { executor.waitFor(); final int exitValue = executor.exitValue(); if (exitValue != 0) { throw new IOException("Bad return value from UNIX " + mvLocation + ": " + exitValue); } else { retVal = true; } } catch (final InterruptedException ie) { final String errMsg = "Error waiting for mv child process to complete: " + ie.toString(); log.error(errMsg); throw new IOException(errMsg); } } return retVal; }
From source file:uk.co.modularaudio.util.pooling.forkexec.ChildProcessExecutor.java
public void close() throws IOException { boolean finished = false; boolean wasError = false; while (!finished) { try {/*from w w w. j a va2 s .c o m*/ // Check for the exit value exitValue = this.process.exitValue(); if (exitValue != 0) { wasError = true; } finished = true; } catch (final IllegalThreadStateException itse) { try { Thread.sleep(WAIT_FOR_DEATH_SLEEP_MILLIS); } catch (final InterruptedException ie) { final String msg = "Caught interruption in waiting for sub-process death: " + ie.toString(); log.warn(msg, ie); } } } try { inputStream.close(); } catch (final Exception e) { } ; try { outputStream.close(); } catch (final Exception e) { } ; try { errorStream.close(); } catch (final Exception e) { } ; try { process.destroy(); } catch (final Exception e) { throw new IOException("Error destroying child process: " + e.toString()); } inputStream = null; outputStream = null; errorStream = null; if (wasError) { throw new IOException("Bad return code from exit() of the sub-process: " + exitValue); } }
From source file:com.mdsh.test.media.encoding.process.AbstractProcess.java
/** * Waits for the given process to end.//from w w w . j a v a 2 s . c o m * <p>Warning: will throw an IOException if an InterruptedException * is caught. * @param process * @throws IOException when the process exit value is non-zero or when * the current thread is interrupted before the process has ended. */ protected void waitForProcess(final Process process) throws IOException { try { process.waitFor(); } catch (final InterruptedException e) { throw new IOException("interrupted while waiting for process: " + e.toString(), e); } final int ret = process.exitValue(); if (0 != ret) throw new IOException("precess exit value was: " + ret); }
From source file:org.apache.sqoop.mapreduce.mainframe.TestMainframeDatasetFTPRecordReader.java
@Test public void testReadPartOfData() { try {//from w w w . jav a 2 s . co m mfDFTPRR.initialize(mfDIS, context); Assert.assertTrue("Retrieve of dataset", mfDFTPRR.nextKeyValue()); Assert.assertEquals("Key should increase by records", 1, mfDFTPRR.getCurrentKey().get()); Assert.assertEquals("Read value by line and by dataset", "123", mfDFTPRR.getCurrentValue().toString()); Assert.assertEquals("Get progress according to left dataset", mfDFTPRR.getProgress(), (float) 0.5, 0.02); } catch (IOException ioe) { fail("Got IOException: " + ioe.toString()); } catch (InterruptedException ie) { fail("Got InterruptedException: " + ie.toString()); } }
From source file:org.apache.sqoop.mapreduce.mainframe.TestMainframeDatasetFTPRecordReader.java
@Test public void testFTPNotComplete() { try {//from w w w . j a v a 2 s . c o m mfDIS = new MainframeDatasetInputSplit(); mfDIS.addDataset("NotComplete"); mfDFTPRR.initialize(mfDIS, context); Assert.assertTrue("Retrieve of dataset", mfDFTPRR.nextKeyValue()); when(mockFTPClient.completePendingCommand()).thenReturn(false); mfDFTPRR.nextKeyValue(); } catch (IOException ioe) { Assert.assertEquals("java.io.IOException: IOException during data transfer: " + "java.io.IOException: Failed to complete ftp command.", ioe.toString()); } catch (InterruptedException ie) { fail("Got InterruptedException: " + ie.toString()); } }
From source file:net.lightbody.bmp.proxy.jetty.http.nio.ByteBufferInputStream.java
private synchronized boolean waitForContent() throws InterruptedIOException { if (_buffer != null) { if (_buffer.hasRemaining()) return true; // recycle buffer recycle(_buffer);/*from w ww. j a v a 2s .c om*/ _buffer = null; } while (!_closed && LazyList.size(_buffers) == 0) { try { this.wait(_timeout); } catch (InterruptedException e) { log.debug(e); throw new InterruptedIOException(e.toString()); } } if (_closed) return false; if (LazyList.size(_buffers) == 0) throw new SocketTimeoutException(); _buffer = (ByteBuffer) LazyList.get(_buffers, 0); _buffers = LazyList.remove(_buffers, 0); return true; }
From source file:es.emergya.bbdd.dao.test.UsuarioHomeTest.java
@Test public void testMuchosThreadsALaVezYCruzaLosDedos() { Hilo hilo1 = new Hilo(); hilo1.start();/*ww w. ja v a 2s. co m*/ Hilo hilo2 = new Hilo(); hilo2.start(); Hilo hilo3 = new Hilo(); hilo3.start(); Hilo hilo4 = new Hilo(); hilo4.start(); Random r = new Random(); for (int i = 0; i < 20; i++) { System.out.println("Vuelta numero " + i + " con " + getTotal() + " usuarios."); try { Thread.sleep((int) (500)); } catch (InterruptedException e) { fail(e.toString()); } synchronized (total) { List<Usuario> usuarios = usuarioHome.getAll(); for (Usuario u : usuarios) if (r.nextBoolean()) if (!u.getNombreUsuario().equals("emergya")) usuarioHome.delete(u); for (int j = 0; j < 3; j++) { Usuario u = new Usuario(); u.setNombre("usuario " + System.currentTimeMillis()); u.setNombreUsuario("nombre " + System.currentTimeMillis()); u.setApellidos("apellidos"); u.setHabilitado(r.nextBoolean()); u.setAdministrador(r.nextBoolean()); usuarioHome.saveOrUpdate(u); } total = usuarioHome.getTotal(); } } if (error) fail("error en la concurrencia"); System.out.println(contador + " comprobaciones."); }