Guava ListeningExecutorService - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Guava ListeningExecutorService class.

This code example shows how to use the following methods:shutdownNow
         this.service = service;
      } 
 
      @Override 
      public void close() throws IOException {
         List<Runnable> runnables = service.shutdownNow();
         if (!runnables.isEmpty())
            logger.warn("when shutting down executor %s, runnables outstanding: %s", service, runnables);
      } 
   } 
 
   final ListeningExecutorService userExecutorFromConstructor;
 
   public ExecutorServiceModule() { 
      this.userExecutorFromConstructor = null;
   } 
 
   /** 
    * @deprecated {@code ioExecutor} is no longer used. This constructor will be removed in jclouds v2. 
    * Use {@link #ExecutorServiceModule(ExecutorService)} instead. 
6
CodeRank
This code example shows how to use the following methods:awaitTermination, shutdown
    ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor());
 
    // create dummy log/index files, and load the reader from them 
    final File logFile = new File("reloadabletest.spl");
    create(Sparkey.getIndexFile(logFile));
    final ReloadableSparkeyReader reader = ReloadableSparkeyReader.fromLogFile(logFile, executorService).get();
 
    // should be ignored (same file) 
    reader.load(logFile);
 
    // should load from second file now 
    final File logFile2 = new File("reloadabletest2.spl");
    create(Sparkey.getIndexFile(logFile2));
    reader.load(logFile2);
 
    reader.close();
    executorService.shutdown();
    executorService.awaitTermination(10, TimeUnit.SECONDS);
 
    Sparkey.getIndexFile(logFile).delete();

6
CodeRank
This code example shows how to use the following methods:shutdown
   protected void tearDown() { 
      api.deleteNode(prefix); 
      api.deleteNode(prefix + 1); 
 
      this.testExecutorService.shutdown();
      this.testListeningExecutorService.shutdown();
 
      super.tearDown(); 
   } 
 
   @Test
   public void testExecute() { 
      assertTrue(size(strategy.execute()) > 0, "Expected one or more elements");
   } 
 
   public void testExecuteConcurrentlyWithExecutorService() { 
      assertTrue(size(strategy.execute(testExecutorService)) > 0, "Expected one or more elements");
   } 
 
   public void testExecuteConcurrentlyWithListeningExecutorService() { 
5
CodeRank
This code example shows how to use the following methods:shutdown
   protected void tearDown() { 
      api.deleteNode(prefix); 
      api.deleteNode(prefix + 1); 
 
      this.testExecutorService.shutdown();
      this.testListeningExecutorService.shutdown();
 
      super.tearDown(); 
   } 
 
   @Test
   public void testExecute() { 
      assertTrue(size(strategy.execute("_default")) > 0, "Expected one or more elements");
   } 
 
   @Test
   public void testExecuteConcurrentlyWithExecutorService() { 
      assertTrue(size(strategy.execute(testExecutorService, "_default")) > 0,
            "Expected one or more elements"); 
   } 
5
CodeRank
This code example shows how to use the following methods:shutdown
      api.deleteCookbook(PREFIX, "1.0.0");
      api.deleteCookbook(PREFIX + 1, "0.0.0");
      api.deleteCookbook(PREFIX + 1, "1.0.0");
 
      this.testExecutorService.shutdown();
      this.testListeningExecutorService.shutdown();
 
      super.tearDown(); 
   } 
 
   @Test
   public void testExecute() { 
      assertTrue(size(strategy.execute("_default")) > 0, "Expected one or more elements");
   } 
 
   @Test
   public void testExecuteConcurrentlyWithExecutorService() { 
      assertTrue(size(strategy.execute(testExecutorService, "_default")) > 0,
            "Expected one or more elements"); 
   } 
5
CodeRank
This code example shows how to use the following methods:submit
        futureParts.put(part, futureETag);
    } 
 
    @Override 
    public ListenableFuture<String> execute(final String container, final Blob blob, final PutOptions options, final BlobToObject blob2Object) {
        return ioExecutor.submit(new Callable<String>() {
                    @Override 
                    public String call() throws Exception {
                        String key = blob.getMetadata().getName();
                        Payload payload = blob.getPayload();
                        MultipartUploadSlicingAlgorithm algorithm = new MultipartUploadSlicingAlgorithm();
                        algorithm.calculateChunkSize(payload.getContentMetadata()
                                .getContentLength()); 
                        int parts = algorithm.getParts();
                        long chunkSize = algorithm.getChunkSize();
                        long remaining = algorithm.getRemaining();
                        if (parts > 0) {
                            CommonSwiftClient client = ablobstore.getContext().unwrap(SwiftApiMetadata.CONTEXT_TOKEN).getApi();
                            final Map<Integer, ListenableFuture<String>> futureParts =
                                    new ConcurrentHashMap<Integer, ListenableFuture<String>>();
5
CodeRank
This code example shows how to use the following methods:submit
  public void close() { 
    underlyingExecutor.shutdown();
  } 
 
  public <T> Response<T> submit(RequestCallable<T> requestCallable) {
    return new Response<T>(callExecutor.submit(requestCallable));
  } 
} 
4
CodeRank
This code example shows how to use the following methods:submit
			XEventPump.LOG.error(errorMsg);
			throw new Error(errorMsg);
		} 
 
		// pass x event from x-event-pump thread to x-executor thread. 
		this.xExecutor.submit(new Callable<Void>() {
			@Override 
			public Void call() {
				XEventPump.this.xEventBus.post(xcb_generic_event);
				xcb_generic_event.delete();
				return null; 
			} 
		}); 
 
		// schedule next event retrieval 
		this.xEventPumpExecutor.submit(this);
		return null; 
	} 
 
	public void start() { 
4
CodeRank
This code example shows how to use the following methods:submit
 
    Preconditions.checkNotNull(emailAddress, "'emailAddress' must be present");
 
    final String cleanEmailAddress = emailAddress.toLowerCase().trim();
 
    return gravatarExecutorService.submit(new Callable<Optional<BufferedImage>>() {
 
      @Override 
      public Optional<BufferedImage> call() throws Exception {
        return cache.get(cleanEmailAddress);
      } 
    }); 
 
  } 
 
  /** 
   * @param emailAddress The cleaned email address to use as an MD5 lookup 
   * 
   * @return The buffered image if present 
   */ 
3
CodeRank
This code example shows how to use the following methods:shutdown
        executor = listeningDecorator(newCachedThreadPool());
    } 
 
    @After 
    public void tearDown() { 
        executor.shutdown();
    } 
 
    @Test(expected = IllegalStateException.class)
    public void notStarted() throws ExecutionException, InterruptedException {
        ManagementOperation<Integer> op = ManagementOperation.done("test", 42);
        assertTrue(op.isDone());
        assertEquals(42, (int) op.get());
        sameThreadExecutor().execute(op);
    } 
 
    @Test
    public void succeeded() throws InterruptedException, ExecutionException, TimeoutException {
        ManagementOperation<Long> op = newManagementOperation("test", new Callable<Long>() {
            @Override 
4
CodeRank
This code example shows how to use the following methods:submit
 
    @Override 
    public final ListenableFuture<V> reload(final K key, V oldValue)
            throws Exception
    { 
        return executor.submit(new Callable<V>()
        { 
            @Override 
            public V call() 
                    throws Exception
            { 
                return load(key);
            } 
        }); 
    } 
} 
4
CodeRank
This code example shows how to use the following methods:submit
        return Optional.fromNullable(inputSlot);
    } 
 
    @Override 
    public ListenableFuture<Void> fire() {
        return modelExecutor.submit(new Callable<Void>() {
            @Override 
            public Void call() throws Exception {
                final Object viewModel = dataContextValueByView.get(view); 
                final Optional<Method> optionalInputSlot = findSlot(viewModel.getClass(),
                        inputSlotName);
                if (optionalInputSlot.isPresent()) {
                    final Method method = optionalInputSlot.get();
                    method.setAccessible(true);
                    method.invoke(viewModel);
                } 
                return null; 
            } 
        }); 
    } 
4
CodeRank
This code example shows how to use the following methods:submit
		final xcb_get_property_cookie_t get_wm_hints_cookie = xcb_icccm_get_wm_hints(	this.xConnection
																								.getConnectionReference() 
																								.get(), 
																						winId.intValue());
 
		return this.displayExecutor.submit(new Callable<Optional<xcb_icccm_wm_hints_t>>() {
			@Override 
			public Optional<xcb_icccm_wm_hints_t> call() throws Exception {
				final xcb_icccm_wm_hints_t hints = new xcb_icccm_wm_hints_t();
				final xcb_generic_error_t e = new xcb_generic_error_t();
 
				final short stat = xcb_icccm_get_wm_hints_reply(WmHints.this.xConnection.getConnectionReference().get(),
																get_wm_hints_cookie,
																hints,
																e);
				if (xcb_generic_error_t.getCPtr(e) != 0) {
					final String errorString = XcbErrorUtil.toString(e);
					LOG.error(errorString);
					return Optional.absent();
				} 
4
CodeRank
This code example shows how to use the following methods:submit
		final xcb_get_property_cookie_t get_property_cookie = xcb_icccm_get_wm_protocols(	this.xConnection
																									.getConnectionReference() 
																									.get(), 
																							window,
																							getProtocolAtomId()); 
		return this.displayExecutor.submit(new Callable<Optional<xcb_icccm_get_wm_protocols_reply_t>>() {
			@Override 
			public Optional<xcb_icccm_get_wm_protocols_reply_t> call() {
 
				final xcb_generic_error_t e = new xcb_generic_error_t();
				final xcb_icccm_get_wm_protocols_reply_t wm_protocols = new xcb_icccm_get_wm_protocols_reply_t();
				final short stat = xcb_icccm_get_wm_protocols_reply(WmProtocols.this.xConnection
																			.getConnectionReference().get(), 
																	get_property_cookie,
																	wm_protocols,
																	e);
				if ((stat == 0) || (xcb_generic_error_t.getCPtr(e) != 0)) {
					LOG.error(	"Failed to get wm_protocols property from window={}", 
								window);
					return Optional.absent();
4
CodeRank
This code example shows how to use the following methods:submit
																							.get(), 
																					window);
		final xcb_generic_error_t e = new xcb_generic_error_t();
		final xcb_icccm_get_text_property_reply_t prop = new xcb_icccm_get_text_property_reply_t();
 
		return this.displayExecutor.submit(new Callable<Optional<xcb_icccm_get_text_property_reply_t>>() {
			@Override 
			public Optional<xcb_icccm_get_text_property_reply_t> call() throws Exception {
 
				final short stat = xcb_icccm_get_wm_name_reply(	WmName.this.xConnection.getConnectionReference().get(),
																get_property_cookie,
																prop,
																e);
				if (stat == 0) {
					LOG.error(	"Error retrieving wm_name reply from client={}", 
								window);
					return Optional.absent();
				} 
 
				return Optional.of(prop);
4
CodeRank
This code example shows how to use the following methods:shutdown
    this.service = service;
  } 
 
  @Override 
  public void shutdown() { 
    service.shutdown();
  } 
 
  @Override 
  public List<Runnable> shutdownNow() {
    return service.shutdownNow();
  } 
 
  @Override 
  public boolean isShutdown() { 
    return service.isShutdown();
  } 
 
  @Override 
  public boolean isTerminated() { 
4
CodeRank
This code example shows how to use the following methods:shutdownNow
        timer.stop();
        client0.stop();
        client1.stop();
        serverChannelFactory.releaseExternalResources();
        clientChannelFactory.releaseExternalResources();
        nonIoExecutorService.shutdownNow();
    } 
 
    @Test
    public void shouldProduceAndConsumeRequestVote() throws RPCException { 
        client0.requestVote(ClusterMembersFixture.RAFT_MEMBER_1.getId(), 10, 20, 9);
 
        verifyNoMoreInteractions(client0RPCReceiver);
        verify(client1RPCReceiver).onRequestVote(ClusterMembersFixture.RAFT_MEMBER_0.getId(), 10, 20, 9);
    } 
 
    @Test
    public void shouldProduceAndConsumeRequestVoteReply() throws RPCException { 
        client0.requestVoteReply(ClusterMembersFixture.RAFT_MEMBER_1.getId(), 10, false);
 
3
CodeRank
This code example shows how to use the following methods:shutdownNow
This code example shows how to use the following methods:awaitTermination, shutdown
 
    if (scheduler != null) {
      scheduler.stopAndWait();
    } 
    if (solverExecutorService != null) {
      solverExecutorService.shutdown();
      try { 
        solverExecutorService.awaitTermination(100, TimeUnit.SECONDS);
      } catch (InterruptedException e) {
        LOG.error("Got Exception: ", e);
      } 
    } 
    if (callbackExecutorService != null) {
      callbackExecutorService.shutdown();
      try { 
        callbackExecutorService.awaitTermination(100, TimeUnit.SECONDS);
      } catch (InterruptedException e) {
        LOG.error("Got Exception: ", e);
      } 
    } 
4
CodeRank
This code example shows how to use the following methods:shutdownNow
    @After 
    public void tearDown() { 
        raftNetworkClient.stop();
        serverChannelFactory.releaseExternalResources();
        clientChannelFactory.releaseExternalResources();
        nonIoExecutorService.shutdownNow();
        timer.stop();
    } 
 
    @Test(expected = NullPointerException.class)
    public void shouldFailIfStartedWithoutRPCReceiverBeingSet() { 
        raftNetworkClient.start();
    } 
 
    @Test
    public void shouldStartSuccessfully() { 
        RPCReceiver receiver = Mockito.mock(RPCReceiver.class);
        raftNetworkClient.initialize(nonIoExecutorService, serverChannelFactory, clientChannelFactory, receiver);
        raftNetworkClient.start();
        raftNetworkClient.stop();
3
CodeRank