Class AbstractConnectionWrapper<C extends Connection>
- Type Parameters:
C
- The type of wrapped connection.
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Connection
,Describable<ApiDescription,
Request>
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.forgerock.services.descriptor.Describable
Describable.Listener
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractConnectionWrapper
(C connection) Creates a new connection wrapper. -
Method Summary
Modifier and TypeMethodDescriptionaction
(Context context, ActionRequest request) Performs an action against a specific resource, or set of resources.actionAsync
(Context context, ActionRequest request) Asynchronously performs an action against a specific resource, or set of resources.void
addDescriptorListener
(Describable.Listener listener) Add a listener for API Descriptor changes.api
(ApiProducer<ApiDescription> producer) Provide the API description for the component.void
close()
Releases any resources associated with this connection.create
(Context context, CreateRequest request) Adds a new JSON resource.createAsync
(Context context, CreateRequest request) Asynchronously adds a new JSON resource.delete
(Context context, DeleteRequest request) Deletes a JSON resource.deleteAsync
(Context context, DeleteRequest request) Asynchronously deletes a JSON resource.handleApiRequest
(Context context, Request request) Handle a request for the API Descriptor.boolean
isClosed()
Indicates whether or not this connection has been explicitly closed by callingclose
.boolean
isValid()
Returnstrue
if this connection has not been closed and no fatal errors have been detected.patch
(Context context, PatchRequest request) Updates a JSON resource by applying a set of changes to its existing content.patchAsync
(Context context, PatchRequest request) Asynchronously updates a JSON resource by applying a set of changes to its existing content.query
(Context context, QueryRequest request, Collection<? super ResourceResponse> results) Searches for all JSON resources matching a user specified set of criteria, and places the results in the provided collection.query
(Context context, QueryRequest request, QueryResourceHandler handler) Searches for all JSON resources matching a user specified set of criteria, and returns aPromise
that will be completed with the results of the search.queryAsync
(Context context, QueryRequest request, QueryResourceHandler handler) Asynchronously searches for all JSON resources matching a user specified set of criteria, and returns aPromise
that will be completed with the results of the search.read
(Context context, ReadRequest request) Reads a JSON resource.readAsync
(Context context, ReadRequest request) Asynchronously reads a JSON resource.void
removeDescriptorListener
(Describable.Listener listener) Remove a listener from API Descriptor changes.protected Context
Optional Context-transformation function if the implementer has requirements to override theContext
provided in theConnection
's method invocations.update
(Context context, UpdateRequest request) Updates a JSON resource by replacing its existing content with new content.updateAsync
(Context context, UpdateRequest request) Asynchronously updates a JSON resource by replacing its existing content with new content.
-
Field Details
-
connection
The wrapped connection.
-
-
Constructor Details
-
AbstractConnectionWrapper
Creates a new connection wrapper.- Parameters:
connection
- The connection to be wrapped.
-
-
Method Details
-
transform
Optional Context-transformation function if the implementer has requirements to override theContext
provided in theConnection
's method invocations.The default implementation is a pass-through no-op.
- Parameters:
context
- the request context- Returns:
- the transformed context
-
action
Performs an action against a specific resource, or set of resources. Bulk updates are an example of an action request.The default implementation is to delegate.
- Specified by:
action
in interfaceConnection
- Parameters:
context
- The request context, such as associated principal.request
- The action request.- Returns:
- A JSON object containing the result of the action, the content of which is specified by the action.
- Throws:
ResourceException
- If the action could not be performed.
-
actionAsync
public Promise<ActionResponse,ResourceException> actionAsync(Context context, ActionRequest request) Asynchronously performs an action against a specific resource, or set of resources. Bulk updates are an example of an action request.The default implementation is to delegate.
- Specified by:
actionAsync
in interfaceConnection
- Parameters:
context
- The request context, such as associated principal.request
- The action request.- Returns:
- A future representing the result of the request.
-
close
public void close()Releases any resources associated with this connection. For physical connections to a server this will mean that the underlying socket is closed.Other connection implementations may behave differently. For example, a pooled connection will be released and returned to its connection pool.
Calling
close
on a connection that is already closed has no effect.The default implementation is to delegate.
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceConnection
-
create
Adds a new JSON resource.The default implementation is to delegate.
- Specified by:
create
in interfaceConnection
- Parameters:
context
- The request context, such as associated principal.request
- The create request.- Returns:
- The newly created JSON resource.
- Throws:
ResourceException
- If the JSON resource could not be created.
-
createAsync
public Promise<ResourceResponse,ResourceException> createAsync(Context context, CreateRequest request) Asynchronously adds a new JSON resource.The default implementation is to delegate.
- Specified by:
createAsync
in interfaceConnection
- Parameters:
context
- The request context, such as associated principal.request
- The create request.- Returns:
- A future representing the result of the request.
-
delete
Deletes a JSON resource.The default implementation is to delegate.
- Specified by:
delete
in interfaceConnection
- Parameters:
context
- The request context, such as associated principal.request
- The delete request.- Returns:
- The deleted JSON resource.
- Throws:
ResourceException
- If the JSON resource could not be deleted.
-
deleteAsync
public Promise<ResourceResponse,ResourceException> deleteAsync(Context context, DeleteRequest request) Asynchronously deletes a JSON resource.The default implementation is to delegate.
- Specified by:
deleteAsync
in interfaceConnection
- Parameters:
context
- The request context, such as associated principal.request
- The delete request.- Returns:
- A future representing the result of the request.
-
isClosed
public boolean isClosed()Indicates whether or not this connection has been explicitly closed by callingclose
. This method will not returntrue
if a fatal error has occurred on the connection unlessclose
has been called.The default implementation is to delegate.
- Specified by:
isClosed
in interfaceConnection
- Returns:
true
if this connection has been explicitly closed by callingclose
, orfalse
otherwise.
-
isValid
public boolean isValid()Returnstrue
if this connection has not been closed and no fatal errors have been detected. This method is guaranteed to returnfalse
only when it is called after the methodclose
has been called.The default implementation is to delegate.
- Specified by:
isValid
in interfaceConnection
- Returns:
true
if this connection is valid,false
otherwise.
-
patch
Updates a JSON resource by applying a set of changes to its existing content.The default implementation is to delegate.
- Specified by:
patch
in interfaceConnection
- Parameters:
context
- The request context, such as associated principal.request
- The update request.- Returns:
- The updated JSON resource.
- Throws:
ResourceException
- If the JSON resource could not be updated.
-
patchAsync
public Promise<ResourceResponse,ResourceException> patchAsync(Context context, PatchRequest request) Asynchronously updates a JSON resource by applying a set of changes to its existing content.The default implementation is to delegate.
- Specified by:
patchAsync
in interfaceConnection
- Parameters:
context
- The request context, such as associated principal.request
- The patch request.- Returns:
- A future representing the result of the request.
-
query
public QueryResponse query(Context context, QueryRequest request, QueryResourceHandler handler) throws ResourceException Searches for all JSON resources matching a user specified set of criteria, and returns aPromise
that will be completed with the results of the search.Result processing happens-before this method returns to the caller.
The default implementation is to delegate.
- Specified by:
query
in interfaceConnection
- Parameters:
context
- The request context, such as associated principal.request
- The query request.handler
- A query resource handler which can be used to process matching resources as they are received.- Returns:
- The query result.
- Throws:
ResourceException
- If the query could not be performed.
-
query
public QueryResponse query(Context context, QueryRequest request, Collection<? super ResourceResponse> results) throws ResourceException Searches for all JSON resources matching a user specified set of criteria, and places the results in the provided collection.The default implementation is to delegate.
- Specified by:
query
in interfaceConnection
- Parameters:
context
- The request context, such as associated principal.request
- The query request.results
- A collection into which matching resources will be added as they are received.- Returns:
- The query result.
- Throws:
ResourceException
- If the query could not be performed.
-
queryAsync
public Promise<QueryResponse,ResourceException> queryAsync(Context context, QueryRequest request, QueryResourceHandler handler) Asynchronously searches for all JSON resources matching a user specified set of criteria, and returns aPromise
that will be completed with the results of the search.Result processing happens-before the returned future completes.
The default implementation is to delegate.
- Specified by:
queryAsync
in interfaceConnection
- Parameters:
context
- The request context, such as associated principal.request
- The create request.handler
- A non-null
query resource handler which should be used to process matching resources as they are received.- Returns:
- A future representing the result of the request.
-
read
Reads a JSON resource.The default implementation is to delegate.
- Specified by:
read
in interfaceConnection
- Parameters:
context
- The request context, such as associated principal.request
- The read request.- Returns:
- The JSON resource.
- Throws:
ResourceException
- If the JSON resource could not be read.
-
readAsync
Asynchronously reads a JSON resource.The default implementation is to delegate.
- Specified by:
readAsync
in interfaceConnection
- Parameters:
context
- The request context, such as associated principal.request
- The read request.- Returns:
- A future representing the result of the request.
-
update
Updates a JSON resource by replacing its existing content with new content.The default implementation is to delegate.
- Specified by:
update
in interfaceConnection
- Parameters:
context
- The request context, such as associated principal.request
- The update request.- Returns:
- The updated JSON resource.
- Throws:
ResourceException
- If the JSON resource could not be updated.
-
updateAsync
public Promise<ResourceResponse,ResourceException> updateAsync(Context context, UpdateRequest request) Asynchronously updates a JSON resource by replacing its existing content with new content.The default implementation is to delegate.
- Specified by:
updateAsync
in interfaceConnection
- Parameters:
context
- The request context, such as associated principal.request
- The update request.- Returns:
- A future representing the result of the request.
-
api
Description copied from interface:Describable
Provide the API description for the component. This method should perform the heavy-lifting of computing the API descriptor, and should be expected to be called rarely. Upstream handlers should call this method in order to compose all of their downstream API Descriptors into a single descriptor.- Specified by:
api
in interfaceDescribable<ApiDescription,
Request> - Parameters:
producer
- The API producer that provides general information to be built into the descriptor.- Returns:
- The description object.
-
handleApiRequest
Description copied from interface:Describable
Handle a request for the API Descriptor. This method should not do any computation, but should return the already computed descriptor.- Specified by:
handleApiRequest
in interfaceDescribable<ApiDescription,
Request> - Parameters:
context
- The request context.request
- The request.- Returns:
- The descriptor.
-
addDescriptorListener
Description copied from interface:Describable
Add a listener for API Descriptor changes. The described object should call all the listeners.- Specified by:
addDescriptorListener
in interfaceDescribable<ApiDescription,
Request> - Parameters:
listener
- The listener.
-
removeDescriptorListener
Description copied from interface:Describable
Remove a listener from API Descriptor changes.- Specified by:
removeDescriptorListener
in interfaceDescribable<ApiDescription,
Request> - Parameters:
listener
- The listener.
-