public void collectQueueStats(
      final Azure azure,
      final String namespaceName,
      Set<String> queueNames,
      Set<String> queueStats,
      int queueThreads)
      throws TaskExecutionException {

    final Map<String, String> valueMap = createValueMap(azure, namespaceName, QUEUES, queueStats);

    ListeningExecutorService queueService =
        MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(queueThreads));
    final CountDownLatch countDownLatch = new CountDownLatch(queueNames.size());

    try {
      for (final String queueName : queueNames) {
        try {
          ListenableFuture getQueueNames =
              queueService.submit(
                  new Runnable() {
                    public void run() {
                      getStatsFromAzure(azure, namespaceName, valueMap, queueName, QUEUES);
                    }
                  });

          Futures.addCallback(
              getQueueNames,
              new FutureCallback<Void>() {
                public void onSuccess(Void nothing) {
                  countDownLatch.countDown();
                }

                public void onFailure(Throwable thrown) {
                  countDownLatch.countDown();
                  logger.error(
                      "Unable to get stats for queue ["
                          + queueName
                          + "] in namespace ["
                          + namespaceName
                          + "]",
                      thrown);
                }
              });

        } catch (Exception e) {
          logger.error(
              "Error getting stats for queue [" + namespaceName + "/" + queueName + "]", e);
          throw new TaskExecutionException(
              "Error getting stats for queue [" + namespaceName + "/" + queueName + "]", e);
        }
      }
    } finally {
      queueService.shutdown();
    }
    try {
      countDownLatch.await();
    } catch (InterruptedException e) {
      logger.error("Unable to wait till getting the queue stats", e);
    }
  }
コード例 #2
0
  @Test
  public void testNotificationExecutor() throws Exception {
    ListeningExecutorService executor = SingletonHolder.getDefaultNotificationExecutor();
    ThreadPoolExecutor tpExecutor =
        (ThreadPoolExecutor)
            setAccessible(executor.getClass().getDeclaredField("delegate")).get(executor);
    BlockingQueue<Runnable> queue = tpExecutor.getQueue();

    for (int idx = 0; idx < 100; idx++) {
      final int idx2 = idx;
      logger.info("Adding {}\t{}\t{}", idx, queue.size(), tpExecutor.getActiveCount());
      executor.execute(
          new Runnable() {

            @Override
            public void run() {
              logger.info("in  {}", idx2);
              try {
                Thread.sleep(1000);
              } catch (InterruptedException e) {
                e.printStackTrace();
              }
              logger.info("out {}", idx2);
            }
          });
    }
    executor.shutdown();
    executor.awaitTermination(10, TimeUnit.SECONDS);
  }
コード例 #3
0
  public void run() throws IOException {
    Preconditions.checkState(inputManager != null, "InputManager must be configured");

    ListenableFuture<Void> runShuffleFuture = schedulerExecutor.submit(schedulerCallable);
    Futures.addCallback(runShuffleFuture, new SchedulerFutureCallback());
    // Shutdown this executor once this task, and the callback complete.
    schedulerExecutor.shutdown();
  }
コード例 #4
0
 @Override
 public void close() {
   source.close();
   cachedAuths.invalidateAll();
   executorService.shutdown();
   try {
     executorService.awaitTermination(5, TimeUnit.SECONDS);
   } catch (InterruptedException e) {
     ConsoleLogger.writeStackTrace(e);
   }
 }
コード例 #5
0
ファイル: MockVoltDB.java プロジェクト: victori/voltdb
 @Override
 public boolean shutdown(Thread mainSiteThread) throws InterruptedException {
   if (m_faultDistributor != null) {
     m_faultDistributor.shutDown();
   }
   VoltDB.wasCrashCalled = false;
   VoltDB.crashMessage = null;
   m_snapshotCompletionMonitor.shutdown();
   m_es.shutdown();
   m_es.awaitTermination(1, TimeUnit.DAYS);
   m_statsAgent.shutdown();
   m_hostMessenger.shutdown();
   return true;
 }
    @AfterClass
    public void tearDownClass() throws Throwable {
      listeningExecutorService.shutdown();
      FileUtils.deleteDirectory(storageDirectory);

      if (sourceCloudStore != null) {
        sourceCloudStore.stop();
        sourceCloudStore = null;
      }

      if (destinationCloudStore != null) {
        destinationCloudStore.stop();
        destinationCloudStore = null;
      }
    }
コード例 #7
0
ファイル: BlockingHttpEndpoint.java プロジェクト: sagiru/buck
 /**
  * Attempt to complete submitted requests on close so that as much information is recorded as
  * possible. This aids debugging when close is called during exception processing.
  */
 @Override
 public void close() {
   requestService.shutdown();
   try {
     if (!requestService.awaitTermination(timeoutMillis, TimeUnit.MILLISECONDS)) {
       LOG.warn(
           Joiner.on(System.lineSeparator())
               .join(
                   "A BlockingHttpEndpoint failed to shut down within the standard timeout.",
                   "Your build might have succeeded, but some requests made to ",
                   this.url + " were probably lost.",
                   "Here's some debugging information:",
                   requestService.toString()));
     }
   } catch (InterruptedException e) {
     Thread.currentThread().interrupt();
   }
 }
コード例 #8
0
 @After
 public void cleanUp() {
   executor.shutdown();
 }
コード例 #9
0
 @Override
 public void shutdown() {
   delegate.shutdown();
 }
コード例 #10
0
ファイル: DefaultPentoStore.java プロジェクト: seanp33/pento
 public void close() throws Exception {
   ioExecutor.shutdown();
 }
コード例 #11
0
ファイル: TargetsCommandTest.java プロジェクト: Nethesh/buck
 @After
 public void tearDown() {
   executor.shutdown();
 }