@SuppressWarnings("javadoc") @Test public void starting_after_closed() throws Exception { try ( PipedInputStream pis = new PipedInputStream(15); PipedOutputStream pos = new PipedOutputStream(pis); CloseableWorkerThread<PipedInputStream> cwt = new CloseableWorkerThread<PipedInputStream>("y", pis, false) { @Override protected void do_cycle_operation( PipedInputStream closeable) throws Exception { if (closeable.read() == -1) { throw new EOFException(); } } }) { cwt.start(); assertEquals(WtState.RUNNING, cwt.state()); Thread.sleep(250); assertEquals(WtState.RUNNING, cwt.state()); cwt.close(); Thread.sleep(250); assertEquals(WtState.ABORTED, cwt.state()); cwt.start(); assertEquals(WtState.RUNNING, cwt.state()); Thread.sleep(250); assertEquals(WtState.RUNNING, cwt.state()); cwt.stop(); assertEquals(WtState.STOPPED, cwt.state()); } }
@Override public synchronized void close() throws IOException { if (m_closeable == null) { return; } T t = m_closeable; m_closeable = null; if (state() == WtState.RUNNING) { thread().interrupt(); } try { t.close(); } finally { m_dispatcher.dispatch(new DispatcherOp<CloseableListener>() { @Override public void dispatch(CloseableListener l) { l.closed(null); } }); } }
CloseableWorkerThread extends WorkerThread implements Closeable { @Override public synchronized void close() throws IOException { if (m_closeable == null) { return; } T t = m_closeable; m_closeable = null; if (state() == WtState.RUNNING) { thread().interrupt(); } try { t.close(); } finally { m_dispatcher.dispatch(new DispatcherOp<CloseableListener>() { @Override public void dispatch(CloseableListener l) { l.closed(null); } }); } } }
CloseableWorkerThread extends WorkerThread implements Closeable { @Override public synchronized void close() throws IOException { if (m_closeable == null) { return; } T t = m_closeable; m_closeable = null; if (state() == WtState.RUNNING) { thread().interrupt(); } try { t.close(); } finally { m_dispatcher.dispatch(new DispatcherOp<CloseableListener>() { @Override public void dispatch(CloseableListener l) { l.closed(null); } }); } } CloseableWorkerThread(String name, T closeable,
			boolean close_on_abort); }
CloseableWorkerThread extends WorkerThread implements Closeable { @Override public synchronized void close() throws IOException { if (m_closeable == null) { return; } T t = m_closeable; m_closeable = null; if (state() == WtState.RUNNING) { thread().interrupt(); } try { t.close(); } finally { m_dispatcher.dispatch(new DispatcherOp<CloseableListener>() { @Override public void dispatch(CloseableListener l) { l.closed(null); } }); } } CloseableWorkerThread(String name, T closeable,
			boolean close_on_abort); synchronized void add_listener(CloseableListener l); synchronized void remove_listener(CloseableListener l); @Override synchronized void close(); synchronized boolean closed(); }
CloseableWorkerThread extends WorkerThread implements Closeable { @Override public synchronized void close() throws IOException { if (m_closeable == null) { return; } T t = m_closeable; m_closeable = null; if (state() == WtState.RUNNING) { thread().interrupt(); } try { t.close(); } finally { m_dispatcher.dispatch(new DispatcherOp<CloseableListener>() { @Override public void dispatch(CloseableListener l) { l.closed(null); } }); } } CloseableWorkerThread(String name, T closeable,
			boolean close_on_abort); synchronized void add_listener(CloseableListener l); synchronized void remove_listener(CloseableListener l); @Override synchronized void close(); synchronized boolean closed();  }