Package org.glassfish.jersey.client
Class ClientRuntime
java.lang.Object
org.glassfish.jersey.client.ClientRuntime
- All Implemented Interfaces:
ClientExecutor,JerseyClient.ShutdownHook
Client-side request processing runtime.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final LazyValue<ExecutorService> private final LazyValue<ScheduledExecutorService> private final AtomicBooleanprivate final ClientConfigprivate final Connectorprivate final InjectionManagerprivate final Iterable<ClientLifecycleListener> private static final Loggerprivate final ManagedObjectsFinalizerprivate final Stage<ClientRequest> private final RequestScopeprivate final Stage<ClientResponse> -
Constructor Summary
ConstructorsConstructorDescriptionClientRuntime(ClientConfig config, Connector connector, InjectionManager injectionManager, BootstrapBag bootstrapBag) Create new client request processing runtime. -
Method Summary
Modifier and TypeMethodDescriptionprivate ClientRequestaddUserAgent(ClientRequest clientRequest, String connectorName) private voidclose()(package private) RunnablecreateRunnableForAsyncProcessing(ClientRequest request, ResponseCallback callback) Prepare aRunnableto be used to submit aclient requestfor asynchronous processing.protected voidfinalize()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.Get runtime configuration.Runtime connector.(package private) InjectionManagerGet injection manager.Get the request scope instance configured for the runtime.invoke(ClientRequest request) Invoke a request processing synchronously in the context of the caller's thread.voidInvoked when the client instance is closed.voidPre-initialize the client runtime.private voidprocessFailure(Throwable failure, ResponseCallback callback) private voidprocessResponse(ClientResponse response, ResponseCallback callback) Creates and executes a one-shot action that becomes enabled after the given delay.<T> ScheduledFuture<T> Creates and executes aScheduledFuturethat becomes enabled after the given delay.Future<?> <T> Future<T> <T> Future<T> Submits a value-returning task for execution and returns aFuturerepresenting the pending results of the task.private Future<?> submit(ExecutorService executor, Runnable task)
-
Field Details
-
LOG
-
requestProcessingRoot
-
responseProcessingRoot
-
connector
-
config
-
requestScope
-
asyncRequestExecutor
-
backgroundScheduler
-
lifecycleListeners
-
closed
-
managedObjectsFinalizer
-
injectionManager
-
-
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
Prepare aRunnableto be used to submit aclient requestfor asynchronous processing.- Parameters:
request- client request to be sent.callback- asynchronous response callback.- Returns:
Runnableto be submitted for async processing usingsubmit(Runnable).
-
submit
Description copied from interface:ClientExecutorSubmits a value-returning task for execution and returns aFuturerepresenting the pending results of the task. The Future'sget()method will return the task's result upon successful completion.- Specified by:
submitin interfaceClientExecutor- Type Parameters:
T- task's return type- Parameters:
task- task to submit- Returns:
- a
Futurerepresenting pending completion of the task
-
submit
Description copied from interface:ClientExecutorSubmits aRunnabletask for execution and returns aFuturerepresenting that task. The Future'sget()method will return the given result upon successful completion.- Specified by:
submitin interfaceClientExecutor- Parameters:
task- the task to submit- Returns:
- a
Futurerepresenting pending completion of the task
-
submit
Description copied from interface:ClientExecutorSubmits aRunnabletask for execution and returns aFuturerepresenting that task. The Future'sget()method will return the given result upon successful completion.- Specified by:
submitin interfaceClientExecutor- Type Parameters:
T- result type- Parameters:
task- the task to submitresult- the result to return- Returns:
- a
Futurerepresenting pending completion of the task
-
schedule
Description copied from interface:ClientExecutorCreates and executes aScheduledFuturethat becomes enabled after the given delay.- Specified by:
schedulein 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
ScheduledFuturethat can be used to extract result or cancel
-
schedule
Description copied from interface:ClientExecutorCreates and executes a one-shot action that becomes enabled after the given delay.- Specified by:
schedulein 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 returnnullupon completion
-
processResponse
-
processFailure
-
submit
-
addUserAgent
-
invoke
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
Get the request scope instance configured for the runtime.- Returns:
- request scope instance.
-
getConfig
Get runtime configuration.- Returns:
- runtime configuration.
-
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.Close will be invoked either via finalizer or via JerseyClient onShutdown hook, whatever comes first.
-
onShutdown
public void onShutdown()Description copied from interface:JerseyClient.ShutdownHookInvoked when the client instance is closed.- Specified by:
onShutdownin interfaceJerseyClient.ShutdownHook
-
close
private void close() -
preInitialize
public void preInitialize()Pre-initialize the client runtime. -
getConnector
Runtime connector.- Returns:
- runtime connector.
-
getInjectionManager
InjectionManager getInjectionManager()Get injection manager.- Returns:
- injection manager.
-