Ejemplo n.º 1
0
  @Override
  public void close() {
    for (R2Store store : this.rawStoreList) {
      store.close();
    }
    // shutdown the transportclient in the case when no r2store is created
    if (this.transportClient != null) {
      final FutureCallback<None> clientShutdownCallback = new FutureCallback<None>();
      this.transportClient.shutdown(clientShutdownCallback);
      try {
        clientShutdownCallback.get();
      } catch (InterruptedException e) {
        logger.error("Interrupted while shutting down the TransportClient: " + e.getMessage(), e);
      } catch (ExecutionException e) {
        logger.error(
            "Execution exception occurred while shutting down the TransportClient: "
                + e.getMessage(),
            e);
      }
    }

    final FutureCallback<None> factoryShutdownCallback = new FutureCallback<None>();
    this._clientFactory.shutdown(factoryShutdownCallback);
    try {
      factoryShutdownCallback.get();
    } catch (InterruptedException e) {
      logger.error("Interrupted while shutting down the HttpClientFactory: " + e.getMessage(), e);
    } catch (ExecutionException e) {
      logger.error(
          "Execution exception occurred while shutting down the HttpClientFactory: "
              + e.getMessage(),
          e);
    }
  }
Ejemplo n.º 2
0
  public void writeConfig() throws ExecutionException, TimeoutException, InterruptedException {
    long startTime = System.currentTimeMillis();

    FutureCallback<None> callback = new FutureCallback<None>();
    _store.start(callback);
    callback.get(_timeout, _timeoutUnit);

    final Semaphore outstandingPutSemaphore = new Semaphore(_maxOutstandingWrites);

    for (final String key : _source.keySet()) {

      Map<String, Object> map = merge(_source.get(key), _defaultMap);

      T properties = _builder.fromMap(map);
      Callback<None> putCallback =
          new Callback<None>() {
            @Override
            public void onSuccess(None none) {
              outstandingPutSemaphore.release();
            }

            @Override
            public void onError(Throwable e) {
              _log.error("Put failed for {}", key, e);
              outstandingPutSemaphore.release();
            }
          };

      if (!outstandingPutSemaphore.tryAcquire(_timeout, _timeoutUnit)) {
        _log.error("Put timed out for {}", key);
        throw new TimeoutException();
      }
      _store.put(key, properties, putCallback);
    }

    // Wait until all puts are finished.
    if (!outstandingPutSemaphore.tryAcquire(_maxOutstandingWrites, _timeout, _timeoutUnit)) {
      _log.error(
          "Put timed out with {} outstanding writes",
          _maxOutstandingWrites - outstandingPutSemaphore.availablePermits());
      throw new TimeoutException();
    }

    FutureCallback<None> shutdownCallback = new FutureCallback<None>();
    _store.shutdown(shutdownCallback);
    shutdownCallback.get(_timeout, _timeoutUnit);

    long elapsedTime = System.currentTimeMillis() - startTime;
    _log.info(
        "A total of {}.{}s elapsed to write configs to store.",
        elapsedTime / 1000,
        elapsedTime % 1000);
  }