Package org.ldaptive.transport
Class DefaultOperationHandle<Q extends Request,S extends Result>
java.lang.Object
org.ldaptive.transport.DefaultOperationHandle<Q,S>
- Type Parameters:
Q
- type of requestS
- type of result
- All Implemented Interfaces:
OperationHandle<Q,
S>
- Direct Known Subclasses:
DefaultCompareOperationHandle
,DefaultExtendedOperationHandle
,DefaultSearchOperationHandle
,NettyConnection.BindOperationHandle
public class DefaultOperationHandle<Q extends Request,S extends Result>
extends Object
implements OperationHandle<Q,S>
Handle that notifies on the components of an LDAP operation request.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate TransportConnection
Connection to send the request on.private boolean
Whether this handle has consumed any messages.private final Instant
Timestamp when the handle was created.private LdapException
Exception encountered attempting to process the request.protected final org.slf4j.Logger
Logger for this class.private Integer
Protocol message ID.private CompleteHandler
Function to run when the operation completes.private ResponseControlHandler[]
Functions to handle response controls.private ExceptionHandler
Function to handle exceptions.private IntermediateResponseHandler[]
Functions to handle intermediate responses.private ReferralHandler[]
Functions to handle referral URLs.private ResultHandler[]
Functions to handle response results.private UnsolicitedNotificationHandler[]
Function to handle unsolicited notifications.private Instant
Timestamp when the result was received or an exception occurred.private Request
Protocol request to send.private final CountDownLatch
Latch to determine when a response has been received.private Duration
Time to wait for a response.private S
Protocol response result.private Instant
Timestamp when the request was sent.private ResultPredicate
Function to run when a result is received to determine whether an exception should be raised. -
Constructor Summary
ConstructorsConstructorDescriptionDefaultOperationHandle
(Q req, TransportConnection conn, Duration timeout) Creates a new operation handle. -
Method Summary
Modifier and TypeMethodDescriptionvoid
abandon()
Abandons this operation.void
abandon
(LdapException cause) Abandons this operation.await()
Waits for a result or reports a timeout exception.cancel()
Cancels this operation.private void
complete()
Releases the latch and sets the response as received.protected void
Indicates that a protocol message was consumed by a supplied consumer.void
InvokesonControl
.void
InvokesonException
followed bycomplete()
.Returns the message ID assigned to this handle.Returns the time this operation received a result or encountered an exception.Returns the request.Returns the time this operation sent a request.boolean
Returns whether this handle has consumed any messages.protected void
initializeMessageFunctional
(Object... functions) Iterates over the supplied functions, set the connection and request if the type isMessageFunctional
.void
InvokesonIntermediate
.void
messageID
(int id) Sets the message ID.onComplete
(CompleteHandler function) Sets the function to execute when the operation completes.onControl
(ResponseControlHandler... function) Sets the functions to execute when a control is received.onException
(ExceptionHandler function) Sets the function to execute when an exception occurs.onIntermediate
(IntermediateResponseHandler... function) Sets the functions to execute when an intermediate response is received.onReferral
(ReferralHandler... function) Sets the functions to execute when a referral is received.onResult
(ResultHandler... function) Sets the functions to execute when a result is received.onUnsolicitedNotification
(UnsolicitedNotificationHandler... function) Sets the functions to execute when an unsolicited notification is received.void
InvokesonReferral
.void
InvokesonResult
and sets the result.send()
Sends this request to the server.void
sent()
Sets the sent time to now.throwIf
(ResultPredicate function) Sets the function to determine whether an exception should be raised by a particular result.toString()
void
InvokesonUnsolicitedNotification
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.ldaptive.OperationHandle
execute
-
Field Details
-
logger
protected final org.slf4j.Logger loggerLogger for this class. -
request
Protocol request to send. -
connection
Connection to send the request on. -
responseTimeout
Time to wait for a response. -
messageID
Protocol message ID. -
onResult
Functions to handle response results. -
onControl
Functions to handle response controls. -
onReferral
Functions to handle referral URLs. -
onIntermediate
Functions to handle intermediate responses. -
onException
Function to handle exceptions. -
onUnsolicitedNotification
Function to handle unsolicited notifications. -
onComplete
Function to run when the operation completes. -
throwCondition
Function to run when a result is received to determine whether an exception should be raised. -
responseDone
Latch to determine when a response has been received. -
creationTime
Timestamp when the handle was created. -
sentTime
Timestamp when the request was sent. SeeTransportConnection.write(DefaultOperationHandle)
. -
receivedTime
Timestamp when the result was received or an exception occurred. -
consumedMessage
private boolean consumedMessageWhether this handle has consumed any messages. -
result
Protocol response result. -
exception
Exception encountered attempting to process the request.
-
-
Constructor Details
-
DefaultOperationHandle
Creates a new operation handle.- Parameters:
req
- request to expect a response forconn
- the request will be executed ontimeout
- duration to wait for a response
-
-
Method Details
-
send
Description copied from interface:OperationHandle
Sends this request to the server. -
await
Description copied from interface:OperationHandle
Waits for a result or reports a timeout exception.- Specified by:
await
in interfaceOperationHandle<Q extends Request,
S extends Result> - Returns:
- result of the operation or empty if the operation is abandoned
- Throws:
LdapException
- if an error occurs executing the request
-
onResult
Description copied from interface:OperationHandle
Sets the functions to execute when a result is received. -
onControl
Description copied from interface:OperationHandle
Sets the functions to execute when a control is received. -
onReferral
Description copied from interface:OperationHandle
Sets the functions to execute when a referral is received.- Specified by:
onReferral
in interfaceOperationHandle<Q extends Request,
S extends Result> - Parameters:
function
- to execute on a referral- Returns:
- this handle
-
onIntermediate
Description copied from interface:OperationHandle
Sets the functions to execute when an intermediate response is received.- Specified by:
onIntermediate
in interfaceOperationHandle<Q extends Request,
S extends Result> - Parameters:
function
- to execute on an intermediate response- Returns:
- this handle
-
onUnsolicitedNotification
public DefaultOperationHandle<Q,S> onUnsolicitedNotification(UnsolicitedNotificationHandler... function) Description copied from interface:OperationHandle
Sets the functions to execute when an unsolicited notification is received.- Specified by:
onUnsolicitedNotification
in interfaceOperationHandle<Q extends Request,
S extends Result> - Parameters:
function
- to execute on an unsolicited notification- Returns:
- this handle
-
onException
Description copied from interface:OperationHandle
Sets the function to execute when an exception occurs.- Specified by:
onException
in interfaceOperationHandle<Q extends Request,
S extends Result> - Parameters:
function
- to execute when an exception occurs- Returns:
- this handle
-
onComplete
Description copied from interface:OperationHandle
Sets the function to execute when the operation completes.- Specified by:
onComplete
in interfaceOperationHandle<Q extends Request,
S extends Result> - Parameters:
function
- to execute on completion- Returns:
- this handle
-
throwIf
Description copied from interface:OperationHandle
Sets the function to determine whether an exception should be raised by a particular result. -
initializeMessageFunctional
Iterates over the supplied functions, set the connection and request if the type isMessageFunctional
.- Parameters:
functions
- to initialize
-
abandon
public void abandon()Description copied from interface:OperationHandle
Abandons this operation. -
abandon
Abandons this operation. Any threads waiting on the result will receive an empty result. SeeConnection.operation(AbandonRequest)
.- Parameters:
cause
- the reason this request was abandoned
-
cancel
Description copied from interface:OperationHandle
Cancels this operation. SeeCancelRequest
. -
getMessageID
Returns the message ID assigned to this handle.- Returns:
- message ID
-
getSentTime
Description copied from interface:OperationHandle
Returns the time this operation sent a request.- Specified by:
getSentTime
in interfaceOperationHandle<Q extends Request,
S extends Result> - Returns:
- sent time
-
getReceivedTime
Description copied from interface:OperationHandle
Returns the time this operation received a result or encountered an exception.- Specified by:
getReceivedTime
in interfaceOperationHandle<Q extends Request,
S extends Result> - Returns:
- received time
-
getOnResult
-
getOnControl
-
getOnReferral
-
getOnIntermediate
-
getOnException
-
getOnComplete
-
getThrowCondition
-
getOnUnsolicitedNotification
-
hasConsumedMessage
public boolean hasConsumedMessage()Returns whether this handle has consumed any messages.- Returns:
- whether this handle has consumed any messages
-
getRequest
Returns the request.- Returns:
- request
-
messageID
public void messageID(int id) Sets the message ID.- Parameters:
id
- message ID
-
sent
public void sent()Sets the sent time to now. -
result
InvokesonResult
and sets the result. Handle is considered done when this is invoked.- Parameters:
r
- result
-
control
InvokesonControl
.- Parameters:
c
- response control
-
referral
InvokesonReferral
.- Parameters:
url
- referral url
-
intermediate
InvokesonIntermediate
.- Parameters:
r
- intermediate response
-
unsolicitedNotification
InvokesonUnsolicitedNotification
.- Parameters:
u
- unsolicited notification
-
exception
InvokesonException
followed bycomplete()
.- Parameters:
e
- exception
-
consumedMessage
protected void consumedMessage()Indicates that a protocol message was consumed by a supplied consumer. -
complete
private void complete()Releases the latch and sets the response as received. InvokesonComplete
. Handle is considered done when this is invoked. -
toString
-