List of usage examples for java.util.concurrent Future cancel
boolean cancel(boolean mayInterruptIfRunning);
From source file:disko.flow.analyzers.FullRelexAnalyzer.java
public void process(AnalysisContext<TextDocument> ctx, Ports ports) throws InterruptedException { if (pool == null) init();/* www. j a v a 2s.c om*/ final InputPort<EntityMaintainer> inputPort = ports.getInput(EntityAnalyzer.ENTITY_CHANNEL); final OutputPort<RelexTaskResult> outputPort = ports.getOutput(PARSE_CHANNEL); final LinkedBlockingQueue<Future<RelexTaskResult>> futureResults = new LinkedBlockingQueue<Future<RelexTaskResult>>( outputPort.getChannel().getCapacity()); log.debug("Starting LinkGrammarAnalyzer..."); exec.submit(new Callable<Integer>() { public Integer call() throws Exception { try { log.debug("LinkGrammarAnalyzer from channel + " + inputPort.getChannel()); for (EntityMaintainer em = inputPort.take(); !inputPort.isEOS(em); em = inputPort.take()) submitTask(em, futureResults); } catch (Throwable t) { log.error("Unable to submit parsing task.", t); } finally { futureResults.put(new FutureRelexTaskResultEOS()); } return (futureResults.size() - 1); } }); try { while (true) { try { Future<RelexTaskResult> futureResult = futureResults.take(); RelexTaskResult relexTaskResult; relexTaskResult = futureResult.get(); if (relexTaskResult == null) break; log.debug("LinkGrammarAnalyzer received " + relexTaskResult.index + ": " + relexTaskResult.result.getParses().size() + " parses of sentences " + relexTaskResult.sentence); relexTaskResult.result.setSentence(relexTaskResult.entityMaintainer.getOriginalSentence()); outputPort.put(relexTaskResult); } catch (InterruptedException e) { for (Future<RelexTaskResult> future : futureResults) { try { future.cancel(true); } catch (Throwable t) { log.error(t); } } break; } } for (Future<RelexTaskResult> future : futureResults) { future.cancel(true); } } catch (ExecutionException e) { throw new RuntimeException(e); } finally { outputPort.close(); /* * exec.shutdown(); for (RelexContext context: pool){ * context.getLinkParserClient().close(); } */ destroy(); } }
From source file:com.polyvi.xface.http.XHttpWorker.java
/** * ?/*w w w . j a v a2 s .c o m*/ * * @param mayInterruptIfRunning */ public void cancelRequest(boolean mayInterruptIfRunning) { for (WeakReference<Future<?>> requestRef : mRequestList) { Future<?> request = requestRef.get(); if (request != null) { request.cancel(mayInterruptIfRunning); } } }
From source file:org.apache.http.impl.conn.PoolingClientConnectionManager.java
public ClientConnectionRequest requestConnection(final HttpRoute route, final Object state) { Args.notNull(route, "HTTP route"); if (this.log.isDebugEnabled()) { this.log.debug("Connection request: " + format(route, state) + formatStats(route)); }// ww w . ja v a 2 s . c o m final Future<HttpPoolEntry> future = this.pool.lease(route, state); return new ClientConnectionRequest() { public void abortRequest() { future.cancel(true); } public ManagedClientConnection getConnection(final long timeout, final TimeUnit tunit) throws InterruptedException, ConnectionPoolTimeoutException { return leaseConnection(future, timeout, tunit); } }; }
From source file:com.nps.micro.UsbService.java
@Override public void onDestroy() { closeMicrocontrollers();//w w w.j a va 2 s . co m statusThread.finalize(); executorService.shutdown(); for (@SuppressWarnings("rawtypes") Future future : futures) { if (!future.isDone()) { future.cancel(false); } } try { executorService.awaitTermination(10, TimeUnit.MINUTES); } catch (InterruptedException e) { Log.e(TAG, "Couldn't finalize tasks cause: " + e.getMessage()); } notificationManager.cancel(NOTIFICATION); isRunning = false; super.onDestroy(); }
From source file:org.apache.http.impl.conn.FixedPoolingClientConnectionManager.java
public ClientConnectionRequest requestConnection(final HttpRoute route, final Object state) { if (route == null) { throw new IllegalArgumentException("HTTP route may not be null"); }/* w w w. ja va2s. co m*/ if (this.log.isDebugEnabled()) { this.log.debug("Connection request: " + format(route, state) + formatStats(route)); } final Future<HttpPoolEntry> future = this.pool.lease(route, state); return new ClientConnectionRequest() { public void abortRequest() { future.cancel(true); } public ManagedClientConnection getConnection(final long timeout, final TimeUnit tunit) throws InterruptedException, ConnectionPoolTimeoutException { return leaseConnection(future, timeout, tunit); } }; }
From source file:com.kurento.kmf.content.internal.base.AbstractHttpContentSession.java
/** * Release Streaming proxy.//from w ww . j a v a2 s.co m */ @Override protected synchronized void destroy() { super.destroy(); if (repositoryHttpEndpoint != null) { repositoryHttpEndpoint.stop(); repositoryHttpEndpoint = null; } Future<?> localTunnelingProxyFuture = tunnellingProxyFuture; if (localTunnelingProxyFuture != null) { localTunnelingProxyFuture.cancel(true); tunnellingProxyFuture = null; } }
From source file:org.pentaho.reporting.platform.plugin.async.PentahoAsyncExecutor.java
@Override public void shutdown() { // attempt to stop all for (final Future<IFixedSizeStreamingContent> entry : futures.values()) { entry.cancel(true); }//w w w .j a va2s . c o m // forget all this.futures.clear(); this.tasks.clear(); this.writeToJcrListeners.clear(); this.executorService.shutdown(); try { this.schedulingLocationListener.lock(); this.schedulingLocationListener.shutdown(); } finally { this.schedulingLocationListener.unlock(); } AsyncJobFileStagingHandler.cleanStagingDir(); }
From source file:com.jbrisbin.vcloud.cache.RabbitMQAsyncCacheProvider.java
@Override public void stop(boolean waitForThreadsToComplete) { active.set(false);//www . j a va 2 s . c om for (Future<?> f : activeTasks) { f.cancel(!waitForThreadsToComplete); } if (waitForThreadsToComplete) { workerPool.shutdown(); } else { workerPool.shutdownNow(); } }
From source file:org.apache.solr.handler.component.HttpShardHandler.java
@Override public void cancelAll() { for (Future<ShardResponse> future : pending) { future.cancel(false); } }
From source file:org.jaqpot.core.service.client.jpdi.JPDIClientImpl.java
@Override public boolean cancel(String taskId) { Future future = futureMap.get(taskId); if (future != null && !future.isCancelled() && !future.isDone()) { future.cancel(true); return true; }/*from w w w.ja v a2 s . c o m*/ return false; }