class ClientRuntime extends java.lang.Object implements JerseyClient.ShutdownHook, ClientExecutor
Modifier and Type | Field and Description |
---|---|
private LazyValue<java.util.concurrent.ExecutorService> |
asyncRequestExecutor |
private LazyValue<java.util.concurrent.ScheduledExecutorService> |
backgroundScheduler |
private java.util.concurrent.atomic.AtomicBoolean |
closed |
private ClientConfig |
config |
private Connector |
connector |
private InjectionManager |
injectionManager |
private java.lang.Iterable<ClientLifecycleListener> |
lifecycleListeners |
private static java.util.logging.Logger |
LOG |
private ManagedObjectsFinalizer |
managedObjectsFinalizer |
private Stage<ClientRequest> |
requestProcessingRoot |
private RequestScope |
requestScope |
private Stage<ClientResponse> |
responseProcessingRoot |
Constructor and Description |
---|
ClientRuntime(ClientConfig config,
Connector connector,
InjectionManager injectionManager,
BootstrapBag bootstrapBag)
Create new client request processing runtime.
|
Modifier and Type | Method and Description |
---|---|
private ClientRequest |
addUserAgent(ClientRequest clientRequest,
java.lang.String connectorName) |
private void |
close() |
(package private) java.lang.Runnable |
createRunnableForAsyncProcessing(ClientRequest request,
ResponseCallback callback)
Prepare a
Runnable to be used to submit a client request for asynchronous processing. |
protected void |
finalize()
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.
|
ClientConfig |
getConfig()
Get runtime configuration.
|
Connector |
getConnector()
Runtime connector.
|
(package private) InjectionManager |
getInjectionManager()
Get injection manager.
|
RequestScope |
getRequestScope()
Get the request scope instance configured for the runtime.
|
ClientResponse |
invoke(ClientRequest request)
Invoke a request processing synchronously in the context of the caller's thread.
|
void |
onShutdown()
Invoked when the client instance is closed.
|
void |
preInitialize()
Pre-initialize the client runtime.
|
private void |
processFailure(java.lang.Throwable failure,
ResponseCallback callback) |
private void |
processResponse(ClientResponse response,
ResponseCallback callback) |
<T> java.util.concurrent.ScheduledFuture<T> |
schedule(java.util.concurrent.Callable<T> callable,
long delay,
java.util.concurrent.TimeUnit unit)
Creates and executes a
ScheduledFuture that becomes enabled after the given delay. |
java.util.concurrent.ScheduledFuture<?> |
schedule(java.lang.Runnable command,
long delay,
java.util.concurrent.TimeUnit unit)
Creates and executes a one-shot action that becomes enabled after the given delay.
|
<T> java.util.concurrent.Future<T> |
submit(java.util.concurrent.Callable<T> task)
Submits a value-returning task for execution and returns a
Future representing the pending results of the task. |
private java.util.concurrent.Future<?> |
submit(java.util.concurrent.ExecutorService executor,
java.lang.Runnable task) |
java.util.concurrent.Future<?> |
submit(java.lang.Runnable task)
Submits a
Runnable task for execution and returns a Future representing that task. |
<T> java.util.concurrent.Future<T> |
submit(java.lang.Runnable task,
T result)
Submits a
Runnable task for execution and returns a Future representing that task. |
private static final java.util.logging.Logger LOG
private final Stage<ClientRequest> requestProcessingRoot
private final Stage<ClientResponse> responseProcessingRoot
private final Connector connector
private final ClientConfig config
private final RequestScope requestScope
private final LazyValue<java.util.concurrent.ExecutorService> asyncRequestExecutor
private final LazyValue<java.util.concurrent.ScheduledExecutorService> backgroundScheduler
private final java.lang.Iterable<ClientLifecycleListener> lifecycleListeners
private final java.util.concurrent.atomic.AtomicBoolean closed
private final ManagedObjectsFinalizer managedObjectsFinalizer
private final InjectionManager injectionManager
public ClientRuntime(ClientConfig config, Connector connector, InjectionManager injectionManager, BootstrapBag bootstrapBag)
config
- client runtime configuration.connector
- client transport connector.injectionManager
- injection manager.java.lang.Runnable createRunnableForAsyncProcessing(ClientRequest request, ResponseCallback callback)
Runnable
to be used to submit a client request
for asynchronous processing.
request
- client request to be sent.callback
- asynchronous response callback.Runnable
to be submitted for async processing using submit(Runnable)
.public <T> java.util.concurrent.Future<T> submit(java.util.concurrent.Callable<T> task)
ClientExecutor
Future
representing the pending results of the task.
The Future's get()
method will return the task's result upon successful completion.submit
in interface ClientExecutor
T
- task's return typetask
- task to submitFuture
representing pending completion of the taskpublic java.util.concurrent.Future<?> submit(java.lang.Runnable task)
ClientExecutor
Runnable
task for execution and returns a Future
representing that task. The Future's get()
method will return the given result upon successful completion.submit
in interface ClientExecutor
task
- the task to submitFuture
representing pending completion of the taskpublic <T> java.util.concurrent.Future<T> submit(java.lang.Runnable task, T result)
ClientExecutor
Runnable
task for execution and returns a Future
representing that task. The Future's get()
method will return the given result upon successful completion.submit
in interface ClientExecutor
T
- result typetask
- the task to submitresult
- the result to returnFuture
representing pending completion of the taskpublic <T> java.util.concurrent.ScheduledFuture<T> schedule(java.util.concurrent.Callable<T> callable, long delay, java.util.concurrent.TimeUnit unit)
ClientExecutor
ScheduledFuture
that becomes enabled after the given delay.schedule
in interface ClientExecutor
T
- return type of the functioncallable
- the function to executedelay
- the time from now to delay executionunit
- the time unit of the delay parameterScheduledFuture
that can be used to extract result or cancelpublic java.util.concurrent.ScheduledFuture<?> schedule(java.lang.Runnable command, long delay, java.util.concurrent.TimeUnit unit)
ClientExecutor
schedule
in interface ClientExecutor
command
- the task to executedelay
- the time from now to delay executionunit
- the time unit of the daly parameterget()
method will return null
upon completionprivate void processResponse(ClientResponse response, ResponseCallback callback)
private void processFailure(java.lang.Throwable failure, ResponseCallback callback)
private java.util.concurrent.Future<?> submit(java.util.concurrent.ExecutorService executor, java.lang.Runnable task)
private ClientRequest addUserAgent(ClientRequest clientRequest, java.lang.String connectorName)
public ClientResponse invoke(ClientRequest request)
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.
request
- client request to be invoked.javax.ws.rs.ProcessingException
- in case of an invocation failure.public RequestScope getRequestScope()
public ClientConfig getConfig()
protected void finalize() throws java.lang.Throwable
Close will be invoked either via finalizer or via JerseyClient onShutdown hook, whatever comes first.
finalize
in class java.lang.Object
java.lang.Throwable
public void onShutdown()
JerseyClient.ShutdownHook
onShutdown
in interface JerseyClient.ShutdownHook
private void close()
public void preInitialize()
public Connector getConnector()
InjectionManager getInjectionManager()