Package com.google.common.util.concurrent

Examples of com.google.common.util.concurrent.ListeningExecutorService.submit()


      try {

         for (BlobDetail blobDetail: blobDetails) {
            BlobUploader blobUploader = new BlobUploader(container, blobDetail);
            ListenableFuture<BlobDetail> blobDetailFuture = executor.submit(blobUploader);
            blobUploaderFutures.add(blobDetailFuture);

            Futures.addCallback(blobDetailFuture, blobUploaderCallback);
         }
View Full Code Here


        try {
            List<ListenableFuture<?>> futures = new ArrayList<ListenableFuture<?>>();

            synchronized (this) {
                for (HttpDownloadJob job : queue) {
                    futures.add(executor.submit(job));
                }
            }

            try {
                Futures.allAsList(futures).get();
View Full Code Here

   public void testAwaitCompletionTimeout() throws Exception {
      final long timeoutMs = 1000;
      ListeningExecutorService userExecutor = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor());
      Map<Void, ListenableFuture<?>> responses = newHashMap();
      try {
         responses.put(null, userExecutor.submit(new Runnable() {
            @Override
            public void run() {
               try {
                  Thread.sleep(2 * timeoutMs);
               } catch (InterruptedException ie) {
View Full Code Here

      try {
         // this is sensitive to formatting as we are looking for the stack traces to match. if you wrap the below
         // line again, you'll need to change incrementInitialElement to 3 line numbers instead of 2.
         submission = getStackTraceAsString(incrementInitialElement(new RuntimeException(), 2)).replaceFirst(format(".*%s", LINE_SEPARATOR),
               "");
         exec.submit(runnableThrowsRTE()).get();
      } catch (ExecutionException e) {
         assertTraceHasSubmission(getStackTraceAsString(e), submission);
         assertTraceHasSubmission(getStackTraceAsString(e.getCause()), submission);
      }
   }
View Full Code Here

      DeleteAllKeysInList testDeleter = createMockBuilder(
            DeleteAllKeysInList.class).withConstructor(executorService,
            blobstore, retryHandler, maxParallelDeletes).createMock();
      // Fail the first future that is created for deleting blobs.
      EasyMock.<ListenableFuture<?>> expect(
                  executorService.submit(isA(Callable.class)))
            .andReturn(
                  Futures.<Void> immediateFailedFuture(new RuntimeException()))
            .once();
      // There should be at least another 3333 calls to executorService.submit
      // since there are 3333 blobs.
View Full Code Here

      DeleteAllKeysInList testDeleter = createMockBuilder(
            DeleteAllKeysInList.class).withConstructor(executorService,
            blobstore, retryHandler, maxParallelDeletes).createMock();
      // Fail the first future that is created for deleting blobs.
      EasyMock.<ListenableFuture<?>> expect(
                  executorService.submit(isA(Callable.class)))
            .andReturn(
                  Futures.<Void> immediateFailedFuture(new RuntimeException()))
            .once();
      EasyMock.expectLastCall().andReturn(Futures.<Void> immediateFuture(null))
            .anyTimes();
View Full Code Here

         // Allow the first semaphore acquire to succeed.
         EasyMock.expect(semaphore.tryAcquire(Long.MAX_VALUE,
               TimeUnit.MILLISECONDS)).andReturn(true).once();
         EasyMock.<ListenableFuture<?>> expect(
                  executorService.submit(isA(Callable.class)))
            .andReturn(blobDelFuture).once();

         // Fail the second semaphore acquire.
         EasyMock.expect(semaphore.tryAcquire(Long.MAX_VALUE,
               TimeUnit.MILLISECONDS))
View Full Code Here

      final SshClient client = setupClient();
      ListeningExecutorService userExecutor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(10));
      List<ListenableFuture<ExecResponse>> futures = Lists.newArrayList();
      try {
         for (int i = 0; i < 100; i++) {
            futures.add(userExecutor.submit(new Callable<ExecResponse>() {
               @Override
               public ExecResponse call() {
                  ExecResponse response = client.exec("hostname");
                  //System.out.println("completed (concurrently) " + count.incrementAndGet());
                  return response;
View Full Code Here

            final int groupNum = i;
            final String group = "twin" + groupNum;
            groups.add(group);
            template = buildTemplate(client.templateBuilder());
            template.getOptions().inboundPorts(22, 8080).blockOnPort(22, 300 + groupNum);
            ListenableFuture<NodeMetadata> future = userExecutor.submit(new Callable<NodeMetadata>() {
               public NodeMetadata call() throws Exception {
                  NodeMetadata node = getOnlyElement(client.createNodesInGroup(group, 1, template));
                  getAnonymousLogger().info("Started node " + node.getId());
                  return node;
               }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.