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();
  }
 @Override
 public void close() {
   source.close();
   cachedAuths.invalidateAll();
   executorService.shutdown();
   try {
     executorService.awaitTermination(5, TimeUnit.SECONDS);
   } catch (InterruptedException e) {
     ConsoleLogger.writeStackTrace(e);
   }
 }
예제 #5
0
 @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
 /**
  * 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();
 }
 @Override
 public void shutdown() {
   delegate.shutdown();
 }
예제 #10
0
 public void close() throws Exception {
   ioExecutor.shutdown();
 }
예제 #11
0
 @After
 public void tearDown() {
   executor.shutdown();
 }