class ClientRuntime extends java.lang.Object implements JerseyClient.ShutdownHook
Modifier and Type | Field and Description |
---|---|
private LazyValue<java.util.concurrent.ExecutorService> |
asyncRequestExecutor |
private java.util.concurrent.atomic.AtomicBoolean |
closed |
private ClientConfig |
config |
private Connector |
connector |
private java.lang.Iterable<ClientLifecycleListener> |
lifecycleListeners |
private org.glassfish.hk2.api.ServiceLocator |
locator |
private static java.util.logging.Logger |
LOG |
private Stage<ClientRequest> |
requestProcessingRoot |
private RequestScope |
requestScope |
private Stage<ClientResponse> |
responseProcessingRoot |
Constructor and Description |
---|
ClientRuntime(ClientConfig config,
Connector connector,
org.glassfish.hk2.api.ServiceLocator locator)
Create new client request processing runtime.
|
Modifier and Type | Method and Description |
---|---|
private ClientRequest |
addUserAgent(ClientRequest clientRequest,
java.lang.String connectorName) |
private void |
close() |
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.
|
RequestScope |
getRequestScope()
Get the request scope instance configured for the runtime.
|
(package private) org.glassfish.hk2.api.ServiceLocator |
getServiceLocator()
Get service locator.
|
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) |
void |
submit(ClientRequest request,
ResponseCallback callback)
Submit a
client request for asynchronous processing. |
private java.util.concurrent.Future<?> |
submit(java.util.concurrent.ExecutorService executor,
java.lang.Runnable 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 org.glassfish.hk2.api.ServiceLocator locator
private final java.lang.Iterable<ClientLifecycleListener> lifecycleListeners
private final java.util.concurrent.atomic.AtomicBoolean closed
public ClientRuntime(ClientConfig config, Connector connector, org.glassfish.hk2.api.ServiceLocator locator)
config
- client runtime configuration.connector
- client transport connector.locator
- HK2 service locator.public void submit(ClientRequest request, ResponseCallback callback)
client request
for asynchronous processing.
Both, the request processing as well as response callback invocation will be executed
in a context of an active request scope instance
.
request
- client request to be sent.callback
- asynchronous response callback.private 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 scope instance
. 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()
org.glassfish.hk2.api.ServiceLocator getServiceLocator()