Class ClientRuntime

java.lang.Object
org.glassfish.jersey.client.ClientRuntime
All Implemented Interfaces:
ClientExecutor, JerseyClient.ShutdownHook

class ClientRuntime extends Object implements JerseyClient.ShutdownHook, ClientExecutor
Client-side request processing runtime.
  • Field Details

  • Constructor Details

    • ClientRuntime

      public ClientRuntime(ClientConfig config, Connector connector, InjectionManager injectionManager, BootstrapBag bootstrapBag)
      Create new client request processing runtime.
      Parameters:
      config - client runtime configuration.
      connector - client transport connector.
      injectionManager - injection manager.
  • Method Details

    • createRunnableForAsyncProcessing

      Runnable createRunnableForAsyncProcessing(ClientRequest request, ResponseCallback callback)
      Prepare a Runnable to be used to submit a client request for asynchronous processing.

      Parameters:
      request - client request to be sent.
      callback - asynchronous response callback.
      Returns:
      Runnable to be submitted for async processing using submit(Runnable).
    • submit

      public <T> Future<T> submit(Callable<T> task)
      Description copied from interface: ClientExecutor
      Submits a value-returning task for execution and returns a Future representing the pending results of the task. The Future's get() method will return the task's result upon successful completion.
      Specified by:
      submit in interface ClientExecutor
      Type Parameters:
      T - task's return type
      Parameters:
      task - task to submit
      Returns:
      a Future representing pending completion of the task
    • submit

      public Future<?> submit(Runnable task)
      Description copied from interface: ClientExecutor
      Submits a Runnable task for execution and returns a Future representing that task. The Future's get() method will return the given result upon successful completion.
      Specified by:
      submit in interface ClientExecutor
      Parameters:
      task - the task to submit
      Returns:
      a Future representing pending completion of the task
    • submit

      public <T> Future<T> submit(Runnable task, T result)
      Description copied from interface: ClientExecutor
      Submits a Runnable task for execution and returns a Future representing that task. The Future's get() method will return the given result upon successful completion.
      Specified by:
      submit in interface ClientExecutor
      Type Parameters:
      T - result type
      Parameters:
      task - the task to submit
      result - the result to return
      Returns:
      a Future representing pending completion of the task
    • schedule

      public <T> ScheduledFuture<T> schedule(Callable<T> callable, long delay, TimeUnit unit)
      Description copied from interface: ClientExecutor
      Creates and executes a ScheduledFuture that becomes enabled after the given delay.
      Specified by:
      schedule in interface ClientExecutor
      Type Parameters:
      T - return type of the function
      Parameters:
      callable - the function to execute
      delay - the time from now to delay execution
      unit - the time unit of the delay parameter
      Returns:
      a ScheduledFuture that can be used to extract result or cancel
    • schedule

      public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit)
      Description copied from interface: ClientExecutor
      Creates and executes a one-shot action that becomes enabled after the given delay.
      Specified by:
      schedule in interface ClientExecutor
      Parameters:
      command - the task to execute
      delay - the time from now to delay execution
      unit - the time unit of the daly parameter
      Returns:
      a scheduledFuture representing pending completion of the task and whose get() method will return null upon completion
    • processResponse

      private void processResponse(ClientResponse response, ResponseCallback callback)
    • processFailure

      private void processFailure(Throwable failure, ResponseCallback callback)
    • submit

      private Future<?> submit(ExecutorService executor, Runnable task)
    • addUserAgent

      private ClientRequest addUserAgent(ClientRequest clientRequest, String connectorName)
    • invoke

      public ClientResponse invoke(ClientRequest request)
      Invoke a request processing synchronously in the context of the caller's thread.

      NOTE: the method does not explicitly start a new request scope context. Instead it is assumed that the method is invoked from within a context of a proper, running request context. A caller may use the getRequestScope() method to retrieve the request scope instance and use it to initialize the proper request scope context prior the method invocation.

      Parameters:
      request - client request to be invoked.
      Returns:
      client response.
      Throws:
      javax.ws.rs.ProcessingException - in case of an invocation failure.
    • getRequestScope

      public RequestScope getRequestScope()
      Get the request scope instance configured for the runtime.
      Returns:
      request scope instance.
    • getConfig

      public ClientConfig getConfig()
      Get runtime configuration.
      Returns:
      runtime configuration.
    • finalize

      protected void finalize() throws Throwable
      This will be used as the last resort to clean things up in the case that this instance gets garbage collected before the client itself gets released.

      Close will be invoked either via finalizer or via JerseyClient onShutdown hook, whatever comes first.

      Overrides:
      finalize in class Object
      Throws:
      Throwable
    • onShutdown

      public void onShutdown()
      Description copied from interface: JerseyClient.ShutdownHook
      Invoked when the client instance is closed.
      Specified by:
      onShutdown in interface JerseyClient.ShutdownHook
    • close

      private void close()
    • preInitialize

      public void preInitialize()
      Pre-initialize the client runtime.
    • getConnector

      public Connector getConnector()
      Runtime connector.
      Returns:
      runtime connector.
    • getInjectionManager

      InjectionManager getInjectionManager()
      Get injection manager.
      Returns:
      injection manager.