/** * {@inheritDoc} * * @see org.modeshape.graph.request.processor.RequestProcessor#close() */ @Override public void close() { super.close(); for (CompositeRequestChannel channel : channelBySourceName.values()) { channel.close(); } }
/** * Cancel this forked channel, stopping work as soon as possible. If the channel has not yet been started, this method * * @param mayInterruptIfRunning true if the channel is still being worked on, and the thread on which its being worked on may * be interrupted, or false if the channel should be allowed to finish if it is already in work. */ public void cancel( boolean mayInterruptIfRunning ) { if (this.future == null || this.future.isDone() || this.future.isCancelled()) return; // Mark the composite as cancelled first, so that the next composed request will be marked as // cancelled. this.composite.cancel(); // Now mark the channel as being done ... close(); // Now, mark the channel as being cancelled (do allow interrupting the worker thread) ... this.future.cancel(mayInterruptIfRunning); }
/** * Close this indexer and release all resources. This method has no effect if it is called when this indexer is alread closed. * * @see #isClosed() */ public void close() { if (closed) return; closed = true; // Close the channel ... try { channel.close(); } finally { // And shut down the executor service ... try { service.shutdown(); service.awaitTermination(5, TimeUnit.SECONDS); } catch (InterruptedException e) { // Log this ... I18n msg = GraphI18n.errorShuttingDownExecutorServiceInSearchEngineIndexer; Logger.getLogger(getClass()).error(msg, sourceName); // Clear the interrupted status of the thread ... Thread.interrupted(); } finally { // Close the search engine processor ... processor.close(); } } }
public void run() { while (requests.hasNext()) { try { Thread.sleep(intervalInMillis); } catch (InterruptedException err) { fail(err.getMessage()); } channel.add(requests.next()); } // Call done ... channel.close(); } }
@Test public void shouldCreateEmptyIteratorIfDoneCalledBeforeObtainingIterator() { channel.close(); Iterator<Request> iter = channel.createIterator(); assertThat(iter.hasNext(), is(false)); }
@Test public void shouldCreateEmptyIteratorIfDoneCalledAfterObtainingIterator() { Iterator<Request> iter = channel.createIterator(); channel.close(); assertThat(iter.hasNext(), is(false)); }
@Test public void shouldCreateIteratorOverRequestsAddedToChannelAfterObtainingIterator() { Iterator<Request> iter = channel.createIterator(); // Add the requests ... for (Request request : requests) { channel.add(request); } // Call done ... channel.close(); // Start iterating ... for (Request expected : requests) { assertThat(iter.hasNext(), is(true)); assertThat(iter.next(), is(sameInstance(expected))); } assertThat(iter.hasNext(), is(false)); }
@Test public void shouldSubmitBlockedRequestsToConnection() throws Exception { // Start the channel ... channel.start(executor, context, connectionFactory); // Submit the requests to the channel ... List<CountDownLatch> latches = new ArrayList<CountDownLatch>(); for (Request request : requests) { CountDownLatch latch = new CountDownLatch(1); latches.add(latch); channel.add(request, latch); } // Mark the channel as done ... channel.close(); // Wait until the channel has completed ... channel.await(); // Verify that all of the latches were decremented ... for (CountDownLatch latch : latches) { latch.await(); assertThat(latch.getCount(), is(0L)); } // Verify that all the requests to the channel were processed ... Iterator<Request> iter = executedRequests.iterator(); for (Request expected : requests) { assertThat(iter.hasNext(), is(true)); assertThat(iter.next(), is(sameInstance(expected))); } assertThat(iter.hasNext(), is(false)); }
@Test public void shouldSubmitRequestsToConnection() throws Exception { // Start the channel ... channel.start(executor, context, connectionFactory); // Submit the requests to the channel ... for (Request request : requests) { channel.add(request); } // Mark the channel as done ... channel.close(); // Wait until the channel has completed ... channel.await(); // Verify that all the requests to the channel were processed ... Iterator<Request> iter = executedRequests.iterator(); for (Request expected : requests) { assertThat(iter.hasNext(), is(true)); assertThat(iter.next(), is(sameInstance(expected))); } assertThat(iter.hasNext(), is(false)); }
if (channel != null) { try { channel.close(); } finally { try {