Esempio n. 1
0
  /**
   * Initiates an orderly shutdown similar to {@link
   * #shutdown(com.linkedin.common.callback.Callback)}. However, in the case that some clients fail
   * to shutdown, the factory shutdown will still complete after the specified timeout.
   *
   * @param callback invoked after all clients shutdown (or the timeout expires) and the factory has
   *     shut down
   * @param timeout the timeout
   * @param timeoutUnit the timeout unit
   */
  public void shutdown(Callback<None> callback, long timeout, TimeUnit timeoutUnit) {
    // Schedule a timeout in case shutdown does not happen normally
    _shutdownTimeoutTask =
        _executor.schedule(
            new Runnable() {
              @Override
              public void run() {
                LOG.warn("Shutdown timeout exceeded, proceeding with shutdown");
                finishShutdown();
              }
            },
            timeout,
            timeoutUnit);

    // Initiate orderly shutdown
    shutdown(callback);
  }
  /**
   * This is a stand-alone app to demo the use of client-side Pegasus API. To run in,
   * com.linkedin.restli.example.RestLiExamplesServer has to be running.
   *
   * <p>The only argument is the path to the resource on the photo server, e.g. /photos/1
   */
  public static void main(String[] args) throws Exception {
    // create HTTP Netty client with default properties
    final HttpClientFactory http = new HttpClientFactory();
    final TransportClient transportClient = http.getClient(Collections.<String, String>emptyMap());
    // create an abstraction layer over the actual client, which supports both REST and RPC
    final Client r2Client = new TransportClientAdapter(transportClient);
    // REST client wrapper that simplifies the interface
    final StringBuilder serverUrlBuilder =
        new StringBuilder("http://")
            .append(SERVER_HOSTNAME)
            .append(":")
            .append(SERVER_PORT)
            .append("/");
    final RestClient restClient = new RestClient(r2Client, serverUrlBuilder.toString());
    final RestLiExampleBasicClient photoClient = new RestLiExampleBasicClient(restClient);

    photoClient.sendRequest(args[0], new PrintWriter(System.out));
    photoClient.shutdown();
    http.shutdown(new FutureCallback<None>());
  }