Class JettyClient

java.lang.Object
org.attribyte.api.http.impl.jetty.JettyClient
All Implemented Interfaces:
AsyncClient, Client

public class JettyClient extends Object implements AsyncClient
  • Constructor Details

    • JettyClient

      public JettyClient()
      Creates an uninitialized client.
    • JettyClient

      public JettyClient(ClientOptions options) throws org.attribyte.api.InitializationException
      Creates a client with specified options.
      Parameters:
      options - The options.
      Throws:
      org.attribyte.api.InitializationException - if options are invalid or other initialization error.
  • Method Details

    • jettyClientFromOptions

      public static org.eclipse.jetty.client.HttpClient jettyClientFromOptions(ClientOptions options)
      Creates and initializes a new Jetty client from HTTP client options.
      Parameters:
      options - The options.
      Returns:
      The initialized (but not started) client.
    • init

      public void init(String prefix, Properties props, org.attribyte.api.Logger logger) throws org.attribyte.api.InitializationException
      Description copied from interface: Client
      Initializes the client. Must be called before first use.
      Specified by:
      init in interface Client
      Parameters:
      prefix - A prefix applied to all property names.
      props - A properties file.
      logger - A logger for messages.
      Throws:
      org.attribyte.api.InitializationException - on initialization error.
    • send

      public Response send(Request request) throws IOException
      Description copied from interface: Client
      Sends a request with default options.
      Specified by:
      send in interface Client
      Parameters:
      request - The request.
      Returns:
      The response.
      Throws:
      IOException - on I/O error.
    • send

      public Response send(Request request, RequestOptions options) throws IOException
      Description copied from interface: Client
      Sends a request with specified options.
      Specified by:
      send in interface Client
      Parameters:
      request - The request.
      options - The request options.
      Returns:
      The response.
      Throws:
      IOException - on I/O error.
    • asyncSend

      public com.google.common.util.concurrent.ListenableFuture<Response> asyncSend(Request request)
      Description copied from interface: AsyncClient
      Sends a request with default options that completes with a ListenableFuture.
      Specified by:
      asyncSend in interface AsyncClient
      Parameters:
      request - The request.
      Returns:
      The (listenable) response future.
    • asyncSend

      public com.google.common.util.concurrent.ListenableFuture<Response> asyncSend(Request request, RequestOptions options)
      Description copied from interface: AsyncClient
      Sends a request with specified options that completes with a ListenableFuture.
      Specified by:
      asyncSend in interface AsyncClient
      Parameters:
      request - The request.
      options - The request options.
      Returns:
      The (listenable) response future.
    • completableSend

      public CompletableFuture<Response> completableSend(Request request)
      Description copied from interface: AsyncClient
      Sends a request with default options that completes with a CompletableFuture.
      Specified by:
      completableSend in interface AsyncClient
      Parameters:
      request - The request.
      Returns:
      The (completable) response future.
    • completableSend

      public CompletableFuture<Response> completableSend(Request request, RequestOptions options)
      Description copied from interface: AsyncClient
      Sends a request with specified options that completes with a CompletableFuture.
      Specified by:
      completableSend in interface AsyncClient
      Parameters:
      request - The request.
      options - The request options.
      Returns:
      The (completable) response future.
    • test

      public CompletableFuture<Response> test(Request request, RequestOptions options)
      Run a test, hashing the content and accumulating the length, but not buffering.
      Parameters:
      request - The request.
      options - The request options.
      Returns:
      The response.
    • stream

      public StreamedResponse stream(Request request, long timeout, TimeUnit timeoutUnits) throws TimeoutException, InterruptedException, ExecutionException
      Sends a request and allows the response to be streamed when it is available.
      Parameters:
      request - The request.
      timeout - The time to wait for the response to return status and headers.
      timeoutUnits - The timeout units.
      Returns:
      The streamed response.
      Throws:
      TimeoutException - on timeout.
      InterruptedException - on interrupted.
      ExecutionException - on send exception.
    • shutdown

      public void shutdown() throws Exception
      Description copied from interface: Client
      Releases resources, interrupts threads, etc. Called when application using the client is terminated.
      Specified by:
      shutdown in interface Client
      Throws:
      Exception - on shutdown exception.