com.google.common.util.concurrent.ListeningExecutorService Java Examples

The following examples show how to use com.google.common.util.concurrent.ListeningExecutorService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MoreFuturesTest.java    From buck with Apache License 2.0 6 votes vote down vote up
@Test
public void combineFuturesFailWhenOneFails() throws InterruptedException {
  SettableFuture<String> firstFuture = SettableFuture.create();
  SettableFuture<Integer> secondFuture = SettableFuture.create();

  ListeningExecutorService executor = MoreExecutors.newDirectExecutorService();

  ListenableFuture<Pair<String, Integer>> combinedFuture =
      MoreFutures.combinedFutures(firstFuture, secondFuture, executor);

  assertFalse(combinedFuture.isDone());

  executor.submit(() -> firstFuture.setException(new Exception()));

  assertTrue(combinedFuture.isDone());
  assertFalse(MoreFutures.isSuccess(combinedFuture));
}
 
Example #2
Source File: JobLimiter.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Adds a new task to the queue. JobLimiter uses the provided service only for invoking the
 * callable itself.
 */
public <V> ListenableFuture<V> schedule(
    ListeningExecutorService service, ThrowingSupplier<ListenableFuture<V>, Exception> callable) {
  // To help prevent stack overflows either this callable needs to be forced to be async, or the
  // release() call when it's finished needs to be. It's easier to do it here.
  ThrowingSupplier<ListenableFuture<V>, Exception> safeCallable =
      () -> Futures.submitAsync(callable::get, service);

  if (semaphore.tryAcquire()) {
    return send(safeCallable);
  }
  ListenableFuture<V> enqueued = enqueue(safeCallable);

  // It's possible that all running jobs finished after we failed to acquire the semaphore and
  // before we enqueued the callable. To not get stuck in the queue forever, try again.
  if (semaphore.tryAcquire()) {
    release();
  }
  return enqueued;
}
 
Example #3
Source File: GetPlacesGraph.java    From curiostack with MIT License 6 votes vote down vote up
@Produces
static ListenableFuture<List<Place>> fetchPlaces(
    S2LatLngRect viewport, DSLContext db, @ForDatabase ListeningExecutorService dbExecutor) {
  var coverer = new S2RegionCoverer();
  var coveredCells = coverer.getCovering(viewport);

  Condition locationCondition =
      DSL.or(
          Streams.stream(coveredCells)
              .map(
                  cell ->
                      PLACE
                          .S2_CELL
                          .ge(ULong.valueOf(cell.rangeMin().id()))
                          .and(PLACE.S2_CELL.le(ULong.valueOf(cell.rangeMax().id()))))
              .collect(toImmutableList()));

  return dbExecutor.submit(
      () -> db.selectFrom(PLACE).where(DSL.or(locationCondition)).fetchInto(Place.class));
}
 
Example #4
Source File: RollupService.java    From glowroot with Apache License 2.0 6 votes vote down vote up
private List<Future<?>> checkAggregateAndGaugeAndHeartbeatAlertsAsync(AgentRollup agentRollup,
        ListeningExecutorService workerExecutor) {
    List<Future<?>> futures = new ArrayList<>();
    for (AgentRollup childAgentRollup : agentRollup.children()) {
        futures.addAll(checkAggregateAndGaugeAndHeartbeatAlertsAsync(childAgentRollup,
                workerExecutor));
    }
    futures.add(workerExecutor.submit(new Runnable() {
        @Override
        public void run() {
            try {
                centralAlertingService.checkAggregateAndGaugeAndHeartbeatAlertsAsync(
                        agentRollup.id(), agentRollup.display(), clock.currentTimeMillis());
            } catch (InterruptedException e) {
                // probably shutdown requested (see close method above)
            } catch (Throwable t) {
                logger.error("{} - {}", agentRollup.id(), t.getMessage(), t);
            }
        }
    }));
    return futures;
}
 
Example #5
Source File: ArtifactCaches.java    From buck with Apache License 2.0 6 votes vote down vote up
private static void initializeDirCaches(
    ArtifactCacheEntries artifactCacheEntries,
    BuckEventBus buckEventBus,
    Function<String, UnconfiguredBuildTarget> unconfiguredBuildTargetFactory,
    TargetConfigurationSerializer targetConfigurationSerializer,
    ProjectFilesystem projectFilesystem,
    ImmutableList.Builder<ArtifactCache> builder,
    ListeningExecutorService storeExecutorService) {
  for (DirCacheEntry cacheEntry : artifactCacheEntries.getDirCacheEntries()) {
    builder.add(
        createDirArtifactCache(
            Optional.ofNullable(buckEventBus),
            cacheEntry,
            unconfiguredBuildTargetFactory,
            targetConfigurationSerializer,
            projectFilesystem,
            storeExecutorService));
  }
}
 
Example #6
Source File: ViewInteraction.java    From android-test with Apache License 2.0 6 votes vote down vote up
@Inject
ViewInteraction(
    UiController uiController,
    ViewFinder viewFinder,
    @MainThread Executor mainThreadExecutor,
    FailureHandler failureHandler,
    Matcher<View> viewMatcher,
    AtomicReference<Matcher<Root>> rootMatcherRef,
    AtomicReference<Boolean> needsActivity,
    RemoteInteraction remoteInteraction,
    ListeningExecutorService remoteExecutor,
    ControlledLooper controlledLooper) {
  this.viewFinder = checkNotNull(viewFinder);
  this.uiController = (InterruptableUiController) checkNotNull(uiController);
  this.failureHandler = checkNotNull(failureHandler);
  this.mainThreadExecutor = checkNotNull(mainThreadExecutor);
  this.viewMatcher = checkNotNull(viewMatcher);
  this.rootMatcherRef = checkNotNull(rootMatcherRef);
  this.needsActivity = checkNotNull(needsActivity);
  this.remoteInteraction = checkNotNull(remoteInteraction);
  this.remoteExecutor = checkNotNull(remoteExecutor);
  this.controlledLooper = checkNotNull(controlledLooper);
}
 
Example #7
Source File: TargetPattern.java    From bazel with Apache License 2.0 6 votes vote down vote up
@Override
public <T, E extends Exception> ListenableFuture<Void> evalAsync(
    TargetPatternResolver<T> resolver,
    ImmutableSet<PathFragment> ignoredSubdirectories,
    ImmutableSet<PathFragment> excludedSubdirectories,
    BatchCallback<T, E> callback,
    Class<E> exceptionClass,
    ListeningExecutorService executor) {
  return resolver.findTargetsBeneathDirectoryAsync(
      directory.getRepository(),
      getOriginalPattern(),
      directory.getPackageFragment().getPathString(),
      rulesOnly,
      ignoredSubdirectories,
      excludedSubdirectories,
      callback,
      exceptionClass,
      executor);
}
 
Example #8
Source File: StateProviderImplTest.java    From bgpcep with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected AbstractDataBrokerTestCustomizer createDataBrokerTestCustomizer() {
    return new ConcurrentDataBrokerTestCustomizer(true) {
        @Override
        public DOMStore createOperationalDatastore() {
            realOperStore = new InMemoryDOMDataStore("OPER", getDataTreeChangeListenerExecutor());
            spiedOperStore = spy(realOperStore);
            getSchemaService().registerSchemaContextListener(spiedOperStore);
            return spiedOperStore;
        }

        @Override
        public ListeningExecutorService getCommitCoordinatorExecutor() {
            return MoreExecutors.newDirectExecutorService();
        }
    };
}
 
Example #9
Source File: RingBufferInputStreamTest.java    From bazel-buildfarm with Apache License 2.0 6 votes vote down vote up
@Test
public void readUnblocksWrite() throws ExecutionException, IOException, InterruptedException {
  ListeningExecutorService service = listeningDecorator(newSingleThreadExecutor());
  AtomicInteger counter = new AtomicInteger();

  RingBufferInputStream buffer = new RingBufferInputStream(1);
  byte[] content = new byte[1];
  content[0] = 42;
  buffer.write(content); // buffer is now full
  ListenableFuture<Void> writeFuture =
      service.submit(
          () -> {
            counter.getAndIncrement();
            buffer.write(content);
            return null;
          });
  while (counter.get() != 1) {
    MICROSECONDS.sleep(10);
  }
  assertThat(writeFuture.isDone()).isFalse();
  buffer.read();
  assertThat(writeFuture.get()).isEqualTo(null);
  service.shutdown();
  service.awaitTermination(10, MICROSECONDS);
}
 
Example #10
Source File: ShellToolAbstractTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
protected void runExecBigConcurrentCommand(int numCommands, long staggeredDelayBeforeStart) throws Exception {
    ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
    List<ListenableFuture<?>> futures = new ArrayList<ListenableFuture<?>>();
    try {
        for (int i = 0; i < numCommands; i++) {
            long delay = (long) (Math.random() * staggeredDelayBeforeStart);
            if (i > 0) Time.sleep(delay);
            
            futures.add(executor.submit(new Runnable() {
                    @Override
                    public void run() {
                        String bigstring = Strings.repeat("abcdefghij", 1000); // 10KB
                        String out = execCommands("echo "+bigstring);
                        assertEquals(out, bigstring+"\n", "actualSize="+out.length()+"; expectedSize="+bigstring.length());
                    }}));
        }
        Futures.allAsList(futures).get();
    } finally {
        executor.shutdownNow();
    }
}
 
Example #11
Source File: RingBufferInputStreamTest.java    From bazel-buildfarm with Apache License 2.0 6 votes vote down vote up
@Test
public void writesUnblockReads() throws ExecutionException, InterruptedException {
  ListeningExecutorService service = listeningDecorator(newSingleThreadExecutor());
  AtomicInteger counter = new AtomicInteger();

  RingBufferInputStream buffer = new RingBufferInputStream(1);
  ListenableFuture<Integer> readFuture =
      service.submit(
          () -> {
            counter.getAndIncrement();
            return buffer.read();
          });
  byte[] content = new byte[1];
  content[0] = 42;
  while (counter.get() != 1) {
    MICROSECONDS.sleep(10);
  }
  assertThat(readFuture.isDone()).isFalse();
  buffer.write(content);
  assertThat(readFuture.get()).isEqualTo(content[0]);
  service.shutdown();
  service.awaitTermination(10, MICROSECONDS);
}
 
Example #12
Source File: PackageParser.java    From intellij with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
Map<ArtifactLocation, String> parsePackageStrings(List<ArtifactLocation> sources)
    throws Exception {

  ListeningExecutorService executorService =
      MoreExecutors.listeningDecorator(
          Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()));

  Map<ArtifactLocation, ListenableFuture<String>> futures = Maps.newHashMap();
  for (final ArtifactLocation source : sources) {
    futures.put(source, executorService.submit(() -> getDeclaredPackageOfJavaFile(source)));
  }
  Map<ArtifactLocation, String> map = Maps.newHashMap();
  for (Entry<ArtifactLocation, ListenableFuture<String>> entry : futures.entrySet()) {
    String value = entry.getValue().get();
    if (value != null) {
      map.put(entry.getKey(), value);
    }
  }
  return map;
}
 
Example #13
Source File: DirArtifactCache.java    From buck with Apache License 2.0 6 votes vote down vote up
public DirArtifactCache(
    String name,
    ProjectFilesystem filesystem,
    Path cacheDir,
    CacheReadMode cacheReadMode,
    Optional<Long> maxCacheSizeBytes,
    ListeningExecutorService storeExecutorService)
    throws IOException {
  this.name = name;
  this.filesystem = filesystem;
  this.cacheDir = cacheDir;
  this.maxCacheSizeBytes = maxCacheSizeBytes;
  this.cacheReadMode = cacheReadMode;
  this.storeExecutorService = storeExecutorService;
  this.bytesSinceLastDeleteOldFiles = 0L;

  // Check first, as mkdirs will fail if the path is a symlink.
  if (!filesystem.isDirectory(cacheDir)) {
    filesystem.mkdirs(cacheDir);
  }
}
 
Example #14
Source File: CachingBuildRuleBuilder.java    From buck with Apache License 2.0 6 votes vote down vote up
private ListenableFuture<Optional<BuildResult>> transformBuildResultIfNotPresent(
    ListenableFuture<Optional<BuildResult>> future,
    Callable<Optional<BuildResult>> function,
    ListeningExecutorService executor) {
  return transformBuildResultAsyncIfNotPresent(
      future,
      () ->
          executor.submit(
              () -> {
                if (!shouldKeepGoing()) {
                  return Optional.of(canceled(firstFailure));
                }
                try (Scope ignored = buildRuleScope()) {
                  return function.call();
                }
              }));
}
 
Example #15
Source File: DatabaseModule.java    From curiostack with MIT License 5 votes vote down vote up
@Provides
@ForDatabase
@Singleton
static ListeningExecutorService dbExecutor() {
  return new CurrentRequestContextForwardingExecutorService(
      Executors.newFixedThreadPool(
          20, new ThreadFactoryBuilder().setNameFormat("dbio-%d").setDaemon(true).build()));
}
 
Example #16
Source File: ProgrammingServiceImpl.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
ProgrammingServiceImpl(final DataBroker dataProvider, final NotificationPublishService notifs,
        final ListeningExecutorService executor, final RpcProviderService rpcProviderRegistry,
        final ClusterSingletonServiceProvider cssp, final Timer timer, final String instructionId) {
    this.dataProvider = requireNonNull(dataProvider);
    this.instructionId = requireNonNull(instructionId);
    this.notifs = requireNonNull(notifs);
    this.executor = requireNonNull(executor);
    this.rpcProviderRegistry = requireNonNull(rpcProviderRegistry);
    this.timer = requireNonNull(timer);
    this.qid = KeyedInstanceIdentifier.builder(InstructionsQueue.class,
            new InstructionsQueueKey(this.instructionId)).build();
    this.sgi = ServiceGroupIdentifier.create(this.instructionId + "-service-group");
    LOG.info("Creating Programming Service {}.", this.sgi.getName());
    this.csspReg = cssp.registerClusterSingletonService(this);
}
 
Example #17
Source File: TestTaskExecution2.java    From tez with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 5000)
public void testFailedTaskTezException() throws IOException, InterruptedException, TezException,
    ExecutionException {

  ListeningExecutorService executor = null;
  try {
    ExecutorService rawExecutor = Executors.newFixedThreadPool(1);
    executor = MoreExecutors.listeningDecorator(rawExecutor);
    ApplicationId appId = ApplicationId.newInstance(10000, 1);
    TaskExecutionTestHelpers.TezTaskUmbilicalForTest
        umbilical = new TaskExecutionTestHelpers.TezTaskUmbilicalForTest();
    TaskReporter taskReporter = createTaskReporter(appId, umbilical);

    TezTaskRunner2 taskRunner = createTaskRunner(appId, umbilical, taskReporter, executor,
        TestProcessor.CONF_THROW_TEZ_EXCEPTION);
    // Setup the executor
    Future<TaskRunner2Result> taskRunnerFuture =
        taskExecutor.submit(new TaskRunnerCallable2ForTest(taskRunner));
    // Signal the processor to go through
    TestProcessor.awaitStart();
    TestProcessor.signal();
    TaskRunner2Result result = taskRunnerFuture.get();
    verifyTaskRunnerResult(result, EndReason.TASK_ERROR, createProcessorTezException(), false, TaskFailureType.NON_FATAL);

    assertNull(taskReporter.currentCallable);
    umbilical.verifyTaskFailedEvent(
        FAILURE_START_STRING,
        TezException.class.getName() + ": " + TezException.class.getSimpleName());
    // Failure detected as a result of fall off from the run method. abort isn't required.
    assertFalse(TestProcessor.wasAborted());
    assertTrue(taskRunner.task.getCounters().countCounters() != 0);
  } finally {
    executor.shutdownNow();
  }
}
 
Example #18
Source File: HybridThriftOverHttpServiceImplArgs.java    From buck with Apache License 2.0 5 votes vote down vote up
public static HybridThriftOverHttpServiceImplArgs of(
    HttpService service,
    ListeningExecutorService executor,
    ThriftProtocol thriftProtocol,
    String hybridThriftPath) {
  return ImmutableHybridThriftOverHttpServiceImplArgs.of(
      service, executor, thriftProtocol, hybridThriftPath);
}
 
Example #19
Source File: RollupService.java    From glowroot with Apache License 2.0 5 votes vote down vote up
@Instrumentation.Transaction(transactionType = "Background",
        transactionName = "Outer rollup loop", traceHeadline = "Outer rollup loop",
        timer = "outer rollup loop")
private void runInternal(List<AgentRollup> agentRollups,
        ListeningExecutorService workerExecutor) throws Exception {
    List<Future<?>> futures = new ArrayList<>();
    // randomize order so that multiple central collector nodes will be less likely to perform
    // duplicative work
    for (AgentRollup agentRollup : shuffle(agentRollups)) {
        futures.addAll(rollupAggregates(agentRollup, workerExecutor));
        futures.add(rollupGauges(agentRollup, workerExecutor));
        futures.addAll(rollupSyntheticMonitors(agentRollup, workerExecutor));
        // checking aggregate and gauge alerts after rollup since their calculation can depend
        // on rollups depending on time period length (and alerts on rollups are not checked
        // anywhere else)
        //
        // agent (not rollup) alerts are also checked right after receiving the respective data
        // (aggregate/gauge/heartbeat) from the agent, but need to also check these once a
        // minute in case no data has been received from the agent recently
        futures.addAll(
                checkAggregateAndGaugeAndHeartbeatAlertsAsync(agentRollup, workerExecutor));
    }
    // none of the futures should fail since they all catch and log exception at the end
    MoreFutures.waitForAll(futures);
    try {
        // FIXME keep this here as fallback, but also resolve alerts immediately when they are
        // deleted (or when their condition is updated)
        centralAlertingService.checkForAllDeletedAlerts();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
}
 
Example #20
Source File: Utilities.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
public static ListeningExecutorService getSingleThreadExecutor(String name) {
    final ThreadFactory threadFactory = new ThreadFactoryBuilder()
            .setNameFormat(name)
            .setDaemon(true)
            .build();
    return MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor(threadFactory));
}
 
Example #21
Source File: GitBlazeVcsHandler.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
public ListenableFuture<String> getUpstreamContent(
    Project project,
    BlazeContext context,
    WorkspaceRoot workspaceRoot,
    WorkspacePath path,
    ListeningExecutorService executor) {
  return executor.submit(() -> getGitUpstreamContent(workspaceRoot, path));
}
 
Example #22
Source File: AbstractContainerCommand.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<BuckEventListener> getEventListeners(
    Map<ExecutorPool, ListeningExecutorService> executorPool,
    ScheduledExecutorService scheduledExecutorService) {
  if (!getSubcommand().isPresent()) {
    return ImmutableList.of();
  }
  return getSubcommand().get().getEventListeners(executorPool, scheduledExecutorService);
}
 
Example #23
Source File: ParserWithConfigurableAttributesTest.java    From buck with Apache License 2.0 5 votes vote down vote up
/** Helper to construct a PerBuildState and use it to get nodes. */
private static void getRawTargetNodes(
    Parser parser,
    TypeCoercerFactory typeCoercerFactory,
    BuckEventBus eventBus,
    Cell cell,
    KnownRuleTypesProvider knownRuleTypesProvider,
    boolean enableProfiling,
    ListeningExecutorService executor,
    ExecutableFinder executableFinder,
    Path buildFile)
    throws BuildFileParseException {
  try (PerBuildState state =
      new PerBuildStateFactory(
              typeCoercerFactory,
              new DefaultConstructorArgMarshaller(),
              knownRuleTypesProvider,
              new ParserPythonInterpreterProvider(cell.getBuckConfig(), executableFinder),
              WatchmanFactory.NULL_WATCHMAN,
              eventBus,
              new ParsingUnconfiguredBuildTargetViewFactory(),
              UnconfiguredTargetConfiguration.INSTANCE)
          .create(
              ParsingContext.builder(cell, executor).setProfilingEnabled(enableProfiling).build(),
              parser.getPermState())) {
    AbstractParser.getTargetNodeRawAttributes(state, cell, AbsPath.of(buildFile)).getTargets();
  }
}
 
Example #24
Source File: ECKeyTest.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void sValue() throws Exception {
    // Check that we never generate an S value that is larger than half the curve order. This avoids a malleability
    // issue that can allow someone to change a transaction [hash] without invalidating the signature.
    final int ITERATIONS = 10;
    ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(ITERATIONS));
    List<ListenableFuture<ECKey.ECDSASignature>> sigFutures = Lists.newArrayList();
    final ECKey key = new ECKey();
    for (byte i = 0; i < ITERATIONS; i++) {
        final Sha256Hash hash = Sha256Hash.of(new byte[]{i});
        sigFutures.add(executor.submit(new Callable<ECKey.ECDSASignature>() {
            @Override
            public ECKey.ECDSASignature call() throws Exception {
                return key.sign(hash);
            }
        }));
    }
    List<ECKey.ECDSASignature> sigs = Futures.allAsList(sigFutures).get();
    for (ECKey.ECDSASignature signature : sigs) {
        assertTrue(signature.isCanonical());
    }
    final ECDSASignature first = sigs.get(0);
    final ECKey.ECDSASignature duplicate = new ECKey.ECDSASignature(first.r, first.s);
    assertEquals(first, duplicate);
    assertEquals(first.hashCode(), duplicate.hashCode());

    final ECKey.ECDSASignature highS = new ECKey.ECDSASignature(first.r, ECKey.CURVE.getN().subtract(first.s));
    assertFalse(highS.isCanonical());
}
 
Example #25
Source File: ArtifactCaches.java    From buck with Apache License 2.0 5 votes vote down vote up
private static ArtifactCache createDirArtifactCache(
    Optional<BuckEventBus> buckEventBus,
    DirCacheEntry dirCacheConfig,
    Function<String, UnconfiguredBuildTarget> unconfiguredBuildTargetFactory,
    TargetConfigurationSerializer targetConfigurationSerializer,
    ProjectFilesystem projectFilesystem,
    ListeningExecutorService storeExecutorService) {
  Path cacheDir = dirCacheConfig.getCacheDir();
  try {
    DirArtifactCache dirArtifactCache =
        new DirArtifactCache(
            "dir",
            projectFilesystem,
            cacheDir,
            dirCacheConfig.getCacheReadMode(),
            dirCacheConfig.getMaxSizeBytes(),
            storeExecutorService);

    if (!buckEventBus.isPresent()) {
      return dirArtifactCache;
    }

    return new LoggingArtifactCacheDecorator(
        buckEventBus.get(),
        dirArtifactCache,
        new DirArtifactCacheEvent.DirArtifactCacheEventFactory(
            unconfiguredBuildTargetFactory, targetConfigurationSerializer));

  } catch (IOException e) {
    throw new HumanReadableException(
        e, "Failure initializing artifact cache directory: %s", cacheDir);
  }
}
 
Example #26
Source File: ArtifactCaches.java    From buck with Apache License 2.0 5 votes vote down vote up
private static ArtifactCache createRetryingArtifactCache(
    HttpCacheEntry cacheDescription,
    String hostToReportToRemote,
    BuckEventBus buckEventBus,
    Function<String, UnconfiguredBuildTarget> unconfiguredBuildTargetFactory,
    TargetConfigurationSerializer targetConfigurationSerializer,
    ProjectFilesystem projectFilesystem,
    ListeningExecutorService httpWriteExecutorService,
    ListeningExecutorService httpFetchExecutorService,
    ArtifactCacheBuckConfig config,
    NetworkCacheFactory factory,
    ArtifactCacheMode cacheMode,
    Optional<ClientCertificateHandler> clientCertificateHandler) {
  ArtifactCache cache =
      createHttpArtifactCache(
          cacheDescription,
          hostToReportToRemote,
          buckEventBus,
          unconfiguredBuildTargetFactory,
          targetConfigurationSerializer,
          projectFilesystem,
          httpWriteExecutorService,
          httpFetchExecutorService,
          config,
          factory,
          cacheMode,
          clientCertificateHandler);
  return new RetryingCacheDecorator(cacheMode, cache, config.getMaxFetchRetries(), buckEventBus);
}
 
Example #27
Source File: PublicAnnouncementManager.java    From buck with Apache License 2.0 5 votes vote down vote up
public PublicAnnouncementManager(
    Clock clock,
    BuckEventBus eventBus,
    AbstractConsoleEventBusListener consoleEventBusListener,
    RemoteLogBuckConfig logConfig,
    ListeningExecutorService service) {
  this.clock = clock;
  this.consoleEventBusListener = consoleEventBusListener;
  this.eventBus = eventBus;
  this.logConfig = logConfig;
  this.service = service;
}
 
Example #28
Source File: MoreExecutorsUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenExecutingRunnableInListeningExecutor_shouldLogThreadExecution() throws Exception {
    ConcurrentHashMap<String, Boolean> threadExecutions = new ConcurrentHashMap<>();

    Runnable logThreadRun = () -> threadExecutions.put(Thread.currentThread().getName(), true);

    ListeningExecutorService executor = MoreExecutors.newDirectExecutorService();
    executor.execute(logThreadRun);

    Assert.assertTrue(threadExecutions.get("main"));
}
 
Example #29
Source File: TezTaskRunner.java    From incubator-tez with Apache License 2.0 5 votes vote down vote up
TezTaskRunner(Configuration tezConf, UserGroupInformation ugi, String[] localDirs,
    TaskSpec taskSpec, TezTaskUmbilicalProtocol umbilical, int appAttemptNumber,
    Map<String, ByteBuffer> serviceConsumerMetadata, Multimap<String, String> startedInputsMap,
    TaskReporter taskReporter, ListeningExecutorService executor) throws IOException {
  this.tezConf = tezConf;
  this.ugi = ugi;
  this.taskReporter = taskReporter;
  this.executor = executor;
  task = new LogicalIOProcessorRuntimeTask(taskSpec, appAttemptNumber, tezConf, localDirs, this,
      serviceConsumerMetadata, startedInputsMap);
  taskReporter.registerTask(task, this);
  taskRunning = new AtomicBoolean(true);

}
 
Example #30
Source File: MemoryAsyncLogDataStoreTest.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
@BeforeMethod
public void setUp() throws Exception {
  ExecutorService executorService =
    Executors.newSingleThreadExecutor(r -> new Thread(r, TEST_THREAD_POOL_NAME));
  ListeningExecutorService service = MoreExecutors.listeningDecorator(executorService);
  final MemoryLogDataStore memorylogDataStore = new MemoryLogDataStore();
  LogDataStore logDataStore = (LogDataStore) Proxy.newProxyInstance(memorylogDataStore.getClass().getClassLoader(),
    new Class[]{LogDataStore.class}, (proxy, method, args) -> {
      String logStoreThreadName = Thread.currentThread().getName();
      AssertJUnit.assertEquals("Async operation was performed out of designed thread pool", "TestThreadPoolName", logStoreThreadName);
      return method.invoke(memorylogDataStore, args);
    });


  store = new MemoryAsyncLogDataStore(service, logDataStore);
  for (int i = 0; i < LOG_EVENT_COUNT; i++) {
    LogDataBuilder builder = new LogDataBuilder();
    builder.withDate(new Date(i * 1000 * 60 * 60l));
    builder.withLevel(Level.INFO);
    builder.withClass(classes[i % classes.length]);
    builder.withMessage("My message " + i);
    builder.withThread(threads[i % threads.length]);
    builder.withId(i);
    builder.withNote(new Note("Note" + i));
    if (i % 10 == 0) {
      builder.withMarked(true).withMarkerColors(MarkerColors.Aqua);
    }
    store.add(builder.build());
  }

}