Package org.glassfish.jersey.client
Class ClientRuntime
- java.lang.Object
-
- org.glassfish.jersey.client.ClientRuntime
-
- All Implemented Interfaces:
ClientExecutor
,JerseyClient.ShutdownHook
class ClientRuntime extends java.lang.Object implements JerseyClient.ShutdownHook, ClientExecutor
Client-side request processing runtime.
-
-
Field Summary
Fields Modifier and Type Field 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 Summary
Constructors Constructor Description ClientRuntime(ClientConfig config, Connector connector, InjectionManager injectionManager, BootstrapBag bootstrapBag)
Create new client request processing runtime.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private ClientRequest
addUserAgent(ClientRequest clientRequest, java.lang.String connectorName)
private void
close()
(package private) java.lang.Runnable
createRunnableForAsyncProcessing(ClientRequest request, ResponseCallback callback)
Prepare aRunnable
to be used to submit aclient 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)
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.ScheduledFuture<T>
schedule(java.util.concurrent.Callable<T> callable, long delay, java.util.concurrent.TimeUnit unit)
Creates and executes aScheduledFuture
that becomes enabled after the given delay.java.util.concurrent.Future<?>
submit(java.lang.Runnable task)
Submits aRunnable
task for execution and returns aFuture
representing that task.<T> java.util.concurrent.Future<T>
submit(java.lang.Runnable task, T result)
Submits aRunnable
task for execution and returns aFuture
representing that task.<T> java.util.concurrent.Future<T>
submit(java.util.concurrent.Callable<T> task)
Submits a value-returning task for execution and returns aFuture
representing the pending results of the task.private java.util.concurrent.Future<?>
submit(java.util.concurrent.ExecutorService executor, java.lang.Runnable task)
-
-
-
Field Detail
-
LOG
private static final java.util.logging.Logger LOG
-
requestProcessingRoot
private final Stage<ClientRequest> requestProcessingRoot
-
responseProcessingRoot
private final Stage<ClientResponse> responseProcessingRoot
-
connector
private final Connector connector
-
config
private final ClientConfig config
-
requestScope
private final RequestScope requestScope
-
asyncRequestExecutor
private final LazyValue<java.util.concurrent.ExecutorService> asyncRequestExecutor
-
backgroundScheduler
private final LazyValue<java.util.concurrent.ScheduledExecutorService> backgroundScheduler
-
lifecycleListeners
private final java.lang.Iterable<ClientLifecycleListener> lifecycleListeners
-
closed
private final java.util.concurrent.atomic.AtomicBoolean closed
-
managedObjectsFinalizer
private final ManagedObjectsFinalizer managedObjectsFinalizer
-
injectionManager
private final InjectionManager injectionManager
-
-
Constructor Detail
-
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 Detail
-
createRunnableForAsyncProcessing
java.lang.Runnable createRunnableForAsyncProcessing(ClientRequest request, ResponseCallback callback)
Prepare aRunnable
to be used to submit aclient request
for asynchronous processing.- Parameters:
request
- client request to be sent.callback
- asynchronous response callback.- Returns:
Runnable
to be submitted for async processing usingsubmit(Runnable)
.
-
submit
public <T> java.util.concurrent.Future<T> submit(java.util.concurrent.Callable<T> task)
Description copied from interface:ClientExecutor
Submits a value-returning task for execution and returns aFuture
representing the pending results of the task. The Future'sget()
method will return the task's result upon successful completion.- Specified by:
submit
in interfaceClientExecutor
- Type Parameters:
T
- task's return type- Parameters:
task
- task to submit- Returns:
- a
Future
representing pending completion of the task
-
submit
public java.util.concurrent.Future<?> submit(java.lang.Runnable task)
Description copied from interface:ClientExecutor
Submits aRunnable
task for execution and returns aFuture
representing that task. The Future'sget()
method will return the given result upon successful completion.- Specified by:
submit
in interfaceClientExecutor
- Parameters:
task
- the task to submit- Returns:
- a
Future
representing pending completion of the task
-
submit
public <T> java.util.concurrent.Future<T> submit(java.lang.Runnable task, T result)
Description copied from interface:ClientExecutor
Submits aRunnable
task for execution and returns aFuture
representing that task. The Future'sget()
method will return the given result upon successful completion.- Specified by:
submit
in interfaceClientExecutor
- Type Parameters:
T
- result type- Parameters:
task
- the task to submitresult
- the result to return- Returns:
- a
Future
representing pending completion of the task
-
schedule
public <T> java.util.concurrent.ScheduledFuture<T> schedule(java.util.concurrent.Callable<T> callable, long delay, java.util.concurrent.TimeUnit unit)
Description copied from interface:ClientExecutor
Creates and executes aScheduledFuture
that becomes enabled after the given delay.- Specified by:
schedule
in interfaceClientExecutor
- Type Parameters:
T
- return type of the function- Parameters:
callable
- the function to executedelay
- the time from now to delay executionunit
- the time unit of the delay parameter- Returns:
- a
ScheduledFuture
that can be used to extract result or cancel
-
schedule
public java.util.concurrent.ScheduledFuture<?> schedule(java.lang.Runnable command, long delay, java.util.concurrent.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 interfaceClientExecutor
- Parameters:
command
- the task to executedelay
- the time from now to delay executionunit
- the time unit of the daly parameter- Returns:
- a scheduledFuture representing pending completion of the task and whose
get()
method will returnnull
upon completion
-
processResponse
private void processResponse(ClientResponse response, ResponseCallback callback)
-
processFailure
private void processFailure(java.lang.Throwable failure, ResponseCallback callback)
-
submit
private java.util.concurrent.Future<?> submit(java.util.concurrent.ExecutorService executor, java.lang.Runnable task)
-
addUserAgent
private ClientRequest addUserAgent(ClientRequest clientRequest, java.lang.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 thegetRequestScope()
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 java.lang.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 classjava.lang.Object
- Throws:
java.lang.Throwable
-
onShutdown
public void onShutdown()
Description copied from interface:JerseyClient.ShutdownHook
Invoked when the client instance is closed.- Specified by:
onShutdown
in interfaceJerseyClient.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.
-
-