@JsonIgnore
 public boolean setupStream(AmazonKinesis kinesis, String streamName) {
   boolean setup = false;
   Preconditions.checkState(!Strings.isNullOrEmpty(streamName), "streamName was not specified");
   try {
     DescribeStreamResult result;
     if (getRetryPeriod() != null) {
       Integer retryAttempts = getMaxAttempts();
       while (retryAttempts == null || retryAttempts > 0) {
         try {
           result = kinesis.describeStream(streamName);
           if ("active".equalsIgnoreCase(result.getStreamDescription().getStreamStatus())) {
             LOG.info("stream {} is active", streamName);
             setup = true;
             break;
           }
         } catch (NullPointerException | ResourceNotFoundException e) {
           createStream(kinesis, streamName);
         }
         Thread.sleep(retryPeriod.toMilliseconds());
         if (retryAttempts != null) {
           retryAttempts--;
         }
       }
     }
   } catch (InterruptedException e) {
     LOG.error(
         "Needed to create stream {} but was interrupted, nothing is guaranteed now", streamName);
   }
   return setup;
 }
예제 #2
0
 protected Server buildServer(LifecycleEnvironment lifecycle, ThreadPool threadPool) {
   final Server server = new Server(threadPool);
   server.addLifeCycleListener(buildSetUIDListener());
   lifecycle.attach(server);
   final ErrorHandler errorHandler = new ErrorHandler();
   errorHandler.setServer(server);
   errorHandler.setShowStacks(false);
   server.addBean(errorHandler);
   server.setStopAtShutdown(true);
   server.setStopTimeout(shutdownGracePeriod.toMilliseconds());
   return server;
 }
예제 #3
0
 protected ThreadPool createThreadPool(MetricRegistry metricRegistry) {
   final BlockingQueue<Runnable> queue =
       new BlockingArrayQueue<>(minThreads, maxThreads, maxQueuedRequests);
   final InstrumentedQueuedThreadPool threadPool =
       new InstrumentedQueuedThreadPool(
           metricRegistry,
           maxThreads,
           minThreads,
           (int) idleThreadTimeout.toMilliseconds(),
           queue);
   threadPool.setName("dw");
   return threadPool;
 }
  /**
   * Return a new Curator connection to the ensemble. It is the caller's responsibility to start and
   * close the connection.
   */
  public CuratorFramework newCurator() {
    // Make all of the curator threads daemon threads so they don't block the JVM from terminating.
    // Also label them
    // with the ensemble they're connecting to, in case someone is trying to sort through a thread
    // dump.
    ThreadFactory threadFactory =
        new ThreadFactoryBuilder()
            .setNameFormat("CuratorFramework[" + _connectString.or(DEFAULT_CONNECT_STRING) + "]-%d")
            .setDaemon(true)
            .build();

    org.apache.curator.RetryPolicy retry =
        _setterRetryPolicy.or(
            (_configRetryPolicy != null) ? _configRetryPolicy : DEFAULT_RETRY_POLICY);
    return CuratorFrameworkFactory.builder()
        .ensembleProvider(new ResolvingEnsembleProvider(_connectString.or(DEFAULT_CONNECT_STRING)))
        .retryPolicy(retry)
        .sessionTimeoutMs(Ints.checkedCast(_sessionTimeout.toMilliseconds()))
        .connectionTimeoutMs(Ints.checkedCast(_connectionTimeout.toMilliseconds()))
        .namespace(_namespace.orNull())
        .threadFactory(threadFactory)
        .build();
  }