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 InstantTimestamp when the request was abandoned.private TransportConnectionConnection to send the request on.private booleanWhether this handle has consumed any messages.private final InstantTimestamp when the handle was created.Predicate that requires any result message except unsolicited.private LdapExceptionException encountered attempting to process the request.protected final LoggerLogger for this class.private IntegerProtocol message ID.private CompleteHandlerFunction to run when the operation completes.private ResponseControlHandler[]Functions to handle response controls.private ExceptionHandlerFunction to handle exceptions.private IntermediateResponseHandler[]Functions to handle intermediate responses.private ReferralHandler[]Functions to handle referral URLs.private ReferralResultHandler<S>Function to chase referrals.private ResultHandler[]Functions to handle response results.private UnsolicitedNotificationHandler[]Function to handle unsolicited notifications.private InstantTimestamp when the result was received or an exception occurred.private final QProtocol request to send.private final SemaphoreSemaphore to determine when a response has been received.private final DurationTime to wait for a response.private SProtocol response result.private InstantTimestamp when the request was sent.private ResultPredicateFunction 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 TypeMethodDescriptionvoidabandon()Abandons this operation.voidabandon(LdapException cause) Abandons this operation.await()Waits for a result or reports a timeout exception.cancel()Cancels this operation.private voidcomplete()Releases the latch and sets the response as received.protected voidIndicates that a protocol message was consumed by a supplied consumer.private voidconsumedMessage(boolean signalResponseSemaphore) Indicates that a protocol message was consumed by a supplied consumer.protected voidconsumedMessage(Message message) Indicates that a protocol message was consumed by a supplied consumer.voidInvokesonControl.protected voidInvokesthrowCondition, if it exists, for the supplied result.voidInvokesnotifyExceptionHandlers(LdapException)followed bycomplete().protected voidfinalizeResult(S r) Setsresult, notifies that message has been consumed and invokescomplete().Returns the time this operation was abandoned.Returns the message ID assigned to this handle.Return the complete handler.Return the response control handlers.Return the exception handler.Return the intermediate response handlers.Return the referral handlers.Return the referral result handler.Return the result handlers.Return the unsolicited notification handlersReturns the time this operation received a result or encountered an exception.Returns the request.Returns a predicate to determine whether the responseTimeout semaphore should be released.Returns the time this operation sent a request.Return the throw condition.booleanReturns whether this handle has consumed any messages.protected final <T> TinitializeMessageFunctional(T function) Creates a newMessageFunctionalif function is of that type and initializes it.protected final <T> T[]initializeMessageFunctional(T... functions) Iterates over the supplied functions and creates a new, initializedMessageFunctionalif any exists.voidInvokesonIntermediate.voidmessageID(int id) Sets the message ID.protected voidInvokes any configured exception handlers with the supplied exception.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.onReferralResult(ReferralResultHandler<S> function) Sets the functions to execute when a response is complete and contains a referral result code.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.protected voidInvokesnotifyExceptionHandlers(LdapException)by wrapping the supplied exception inLdapException.protected SprocessReferralResult(S original, ReferralResultHandler<S> handler) Invokes the supplied referral result handler and returns the result of that handler.protected voidprocessResult(S r) Perform checks on the supplied result and invoke any configuredonResulthandlers.voidInvokesonReferral.voidInvokesonResultand sets the result.send()Sends this request to the server.voidsent()Sets the sent time to now.private booleanWhether the supplied result belongs to this handle.throwIf(ResultPredicate function) Sets the function to determine whether an exception should be raised by a particular result.toString()voidInvokesonUnsolicitedNotification.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.ldaptive.OperationHandle
execute
-
Field Details
-
DEFAULT_RESPONSE_TIMEOUT_CONDITION
Predicate that requires any result message except unsolicited. -
logger
Logger for this class. -
request
Protocol request to send. -
responseTimeout
Time to wait for a response. -
connection
Connection to send the request on. -
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. -
onReferralResult
Function to chase referrals. -
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. -
responseSemaphore
Semaphore 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. -
abandonedTime
Timestamp when the request was abandoned. -
consumedMessage
private volatile 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
-
getResponseTimeoutCondition
Returns a predicate to determine whether the responseTimeout semaphore should be released.- Returns:
- response timeout condition
-
send
Description copied from interface:OperationHandleSends this request to the server. -
await
Description copied from interface:OperationHandleWaits for a result or reports a timeout exception.- Specified by:
awaitin 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
-
evaluateThrowCondition
InvokesthrowCondition, if it exists, for the supplied result.- Parameters:
r- to evaluate- Throws:
LdapException- if the condition fails
-
onResult
Description copied from interface:OperationHandleSets the functions to execute when a result is received. -
onControl
Description copied from interface:OperationHandleSets the functions to execute when a control is received. -
onReferral
Description copied from interface:OperationHandleSets the functions to execute when a referral is received.- Specified by:
onReferralin interfaceOperationHandle<Q extends Request,S extends Result> - Parameters:
function- to execute on a referral- Returns:
- this handle
-
onIntermediate
Description copied from interface:OperationHandleSets the functions to execute when an intermediate response is received.- Specified by:
onIntermediatein 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:OperationHandleSets the functions to execute when an unsolicited notification is received.- Specified by:
onUnsolicitedNotificationin interfaceOperationHandle<Q extends Request,S extends Result> - Parameters:
function- to execute on an unsolicited notification- Returns:
- this handle
-
onReferralResult
Description copied from interface:OperationHandleSets the functions to execute when a response is complete and contains a referral result code.- Specified by:
onReferralResultin interfaceOperationHandle<Q extends Request,S extends Result> - Parameters:
function- to execute on a referral response- Returns:
- this handle
-
onException
Description copied from interface:OperationHandleSets the function to execute when an exception occurs.- Specified by:
onExceptionin interfaceOperationHandle<Q extends Request,S extends Result> - Parameters:
function- to execute when an exception occurs- Returns:
- this handle
-
onComplete
Description copied from interface:OperationHandleSets the function to execute when the operation completes.- Specified by:
onCompletein interfaceOperationHandle<Q extends Request,S extends Result> - Parameters:
function- to execute on completion- Returns:
- this handle
-
throwIf
Description copied from interface:OperationHandleSets the function to determine whether an exception should be raised by a particular result. -
initializeMessageFunctional
protected final <T> T[] initializeMessageFunctional(T... functions) Iterates over the supplied functions and creates a new, initializedMessageFunctionalif any exists.- Type Parameters:
T- type of functions- Parameters:
functions- to initialize- Returns:
- array of functions with any
MessageFunctionalinitialized
-
initializeMessageFunctional
protected final <T> T initializeMessageFunctional(T function) Creates a newMessageFunctionalif function is of that type and initializes it.- Type Parameters:
T- type of function- Parameters:
function- to initialize- Returns:
- initialized message functional or the same function
-
abandon
public void abandon()Description copied from interface:OperationHandleAbandons 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:OperationHandleCancels this operation. SeeCancelRequest. -
supports
Whether the supplied result belongs to this handle.- Parameters:
r- to inspect- Returns:
- whether the supplied result belong to this handle
-
getMessageID
Returns the message ID assigned to this handle.- Returns:
- message ID
-
getSentTime
Description copied from interface:OperationHandleReturns the time this operation sent a request.- Specified by:
getSentTimein interfaceOperationHandle<Q extends Request,S extends Result> - Returns:
- sent time
-
getReceivedTime
Description copied from interface:OperationHandleReturns the time this operation received a result or encountered an exception.- Specified by:
getReceivedTimein interfaceOperationHandle<Q extends Request,S extends Result> - Returns:
- received time
-
getAbandonedTime
Description copied from interface:OperationHandleReturns the time this operation was abandoned.- Specified by:
getAbandonedTimein interfaceOperationHandle<Q extends Request,S extends Result> - Returns:
- abandoned time
-
getOnResult
Return the result handlers.- Returns:
- result handlers
-
getOnControl
Return the response control handlers.- Returns:
- response control handlers
-
getOnReferral
Return the referral handlers.- Returns:
- referral handlers
-
getOnIntermediate
Return the intermediate response handlers.- Returns:
- intermediate response handlers
-
getOnException
Return the exception handler.- Returns:
- exception handler
-
getOnComplete
Return the complete handler.- Returns:
- complete handler
-
getThrowCondition
Return the throw condition.- Returns:
- throw condition
-
getOnUnsolicitedNotification
Return the unsolicited notification handlers- Returns:
- unsolicited notification handlers
-
getOnReferralResult
Return the referral result handler.- Returns:
- referral result handler
-
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
InvokesonResultand sets the result. Handle is considered done when this is invoked.- Parameters:
r- result
-
processResult
Perform checks on the supplied result and invoke any configuredonResulthandlers.- Parameters:
r- to process
-
finalizeResult
Setsresult, notifies that message has been consumed and invokescomplete().- Parameters:
r- to finalize
-
control
InvokesonControl.- Parameters:
c- response control
-
referral
InvokesonReferral.- Parameters:
url- referral url
-
intermediate
InvokesonIntermediate.- Parameters:
r- intermediate response
-
unsolicitedNotification
InvokesonUnsolicitedNotification.- Parameters:
u- unsolicited notification
-
processHandlerException
InvokesnotifyExceptionHandlers(LdapException)by wrapping the supplied exception inLdapException. If the supplied exception is an instance ofAbandonOperationException,abandon(LdapException)is invoked.- Parameters:
e- to process
-
notifyExceptionHandlers
Invokes any configured exception handlers with the supplied exception.- Parameters:
e- exception
-
exception
InvokesnotifyExceptionHandlers(LdapException)followed bycomplete().- Parameters:
e- exception
-
consumedMessage
protected void consumedMessage()Indicates that a protocol message was consumed by a supplied consumer. -
consumedMessage
Indicates that a protocol message was consumed by a supplied consumer.- Parameters:
message- that was consumed
-
consumedMessage
private void consumedMessage(boolean signalResponseSemaphore) Indicates that a protocol message was consumed by a supplied consumer.- Parameters:
signalResponseSemaphore- whether to signal the response semaphore
-
complete
private void complete()Releases the latch and sets the response as received. InvokesonComplete. Handle is considered done when this is invoked. -
processReferralResult
protected S processReferralResult(S original, ReferralResultHandler<S> handler) throws LdapException Invokes the supplied referral result handler and returns the result of that handler.- Parameters:
original- operation resulthandler- to invoke- Returns:
- result returned by the handler
- Throws:
LdapException- if the handler throws an LdapExceptionIllegalArgumentException- if original is not a referralIllegalStateException- if the handler does not return a valid result
-
toString
-