Class DefaultOperationHandle<Q extends Request,​S extends Result>

    • Field Detail

      • DEFAULT_RESPONSE_TIMEOUT_CONDITION

        private static final Predicate<Message> DEFAULT_RESPONSE_TIMEOUT_CONDITION
        Predicate that requires any result message except unsolicited.
      • logger

        protected final Logger logger
        Logger for this class.
      • request

        private final Q extends Request request
        Protocol request to send.
      • responseTimeout

        private final Duration responseTimeout
        Time to wait for a response.
      • messageID

        private Integer messageID
        Protocol message ID.
      • onResult

        private ResultHandler[] onResult
        Functions to handle response results.
      • onReferral

        private ReferralHandler[] onReferral
        Functions to handle referral URLs.
      • onException

        private ExceptionHandler onException
        Function to handle exceptions.
      • onComplete

        private CompleteHandler onComplete
        Function to run when the operation completes.
      • throwCondition

        private ResultPredicate throwCondition
        Function to run when a result is received to determine whether an exception should be raised.
      • responseSemaphore

        private final Semaphore responseSemaphore
        Semaphore to determine when a response has been received.
      • creationTime

        private final Instant creationTime
        Timestamp when the handle was created.
      • receivedTime

        private Instant receivedTime
        Timestamp when the result was received or an exception occurred.
      • consumedMessage

        private boolean consumedMessage
        Whether this handle has consumed any messages.
      • result

        private S extends Result result
        Protocol response result.
      • exception

        private LdapException exception
        Exception encountered attempting to process the request.
    • Constructor Detail

      • DefaultOperationHandle

        public DefaultOperationHandle​(Q req,
                                      TransportConnection conn,
                                      Duration timeout)
        Creates a new operation handle.
        Parameters:
        req - request to expect a response for
        conn - the request will be executed on
        timeout - duration to wait for a response
    • Method Detail

      • getResponseTimeoutCondition

        protected Predicate<Message> getResponseTimeoutCondition()
        Returns a predicate to determine whether the responseTimeout semaphore should be released.
        Returns:
        response timeout condition
      • evaluateThrowCondition

        protected void evaluateThrowCondition​(Result r)
                                       throws LdapException
        Invokes throwCondition, if it exists, for the supplied result.
        Parameters:
        r - to evaluate
        Throws:
        LdapException - if the condition fails
      • initializeMessageFunctional

        protected final <T> T[] initializeMessageFunctional​(T... functions)
        Iterates over the supplied functions and creates a new, initialized MessageFunctional if any exists.
        Type Parameters:
        T - type of functions
        Parameters:
        functions - to initialize
        Returns:
        array of functions with any MessageFunctional initialized
      • initializeMessageFunctional

        protected final <T> T initializeMessageFunctional​(T function)
        Creates a new MessageFunctional if 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​(LdapException cause)
        Abandons this operation. Any threads waiting on the result will receive an empty result. See Connection.operation(AbandonRequest).
        Parameters:
        cause - the reason this request was abandoned
      • supports

        private boolean supports​(Result r)
        Whether the supplied result belongs to this handle.
        Parameters:
        r - to inspect
        Returns:
        whether the supplied result belong to this handle
      • getMessageID

        public Integer getMessageID()
        Returns the message ID assigned to this handle.
        Returns:
        message ID
      • hasConsumedMessage

        public boolean hasConsumedMessage()
        Returns whether this handle has consumed any messages.
        Returns:
        whether this handle has consumed any messages
      • getRequest

        public Q 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

        public void result​(S r)
        Invokes onResult and sets the result. Handle is considered done when this is invoked.
        Parameters:
        r - result
      • processResult

        protected void processResult​(S r)
        Perform checks on the supplied result and invoke any configured onResult handlers.
        Parameters:
        r - to process
      • finalizeResult

        protected void finalizeResult​(S r)
        Sets result, notifies that message has been consumed and invokes complete().
        Parameters:
        r - to finalize
      • referral

        public void referral​(String... url)
        Invokes onReferral.
        Parameters:
        url - referral url
      • consumedMessage

        protected void consumedMessage()
        Indicates that a protocol message was consumed by a supplied consumer.
      • consumedMessage

        protected void consumedMessage​(Message message)
        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. Invokes onComplete. 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 result
        handler - to invoke
        Returns:
        result returned by the handler
        Throws:
        LdapException - if the handler throws an LdapException
        IllegalArgumentException - if original is not a referral
        IllegalStateException - if the handler does not return a valid result