Class HandleMap


  • public final class HandleMap
    extends Object
    Container for operation handles that are waiting on a response from the LDAP server.
    • Field Detail

      • LOGGER

        private static final Logger LOGGER
        Logger for this class.
      • THROTTLE_REQUESTS_PROPERTY

        private static final String THROTTLE_REQUESTS_PROPERTY
        Throttle requests system property.
        See Also:
        Constant Field Values
      • THROTTLE_TIMEOUT_PROPERTY

        private static final String THROTTLE_TIMEOUT_PROPERTY
        Throttle timeout system property.
        See Also:
        Constant Field Values
      • THROTTLE_REQUESTS

        private static final int THROTTLE_REQUESTS
        If property is greater than zero, use the throttle semaphore.
      • THROTTLE_TIMEOUT

        private static final Duration THROTTLE_TIMEOUT
        Maximum time to wait for the throttle semaphore. Default is 60 seconds.
      • notificationLock

        private final AtomicBoolean notificationLock
        Only one notification can occur at a time.
      • throttle

        private final Semaphore throttle
        Semaphore to throttle incoming requests.
      • open

        private boolean open
        Whether this queue is currently accepting new handles.
    • Constructor Detail

      • HandleMap

        public HandleMap()
        Creates a new handle map.
    • Method Detail

      • open

        public void open()
        Open this queue to receive new handles.
      • close

        public void close()
        Close the queue to new handles.
      • isOpen

        public boolean isOpen()
        Returns whether this handle map is open.
        Returns:
        is open
      • get

        public DefaultOperationHandle<?,​?> get​(int id)
        Returns the operation handle for the supplied message id. Returns null if this queue is not open.
        Parameters:
        id - message id
        Returns:
        operation handle or null
      • remove

        public DefaultOperationHandle<?,​?> remove​(int id)
        Removes the operation handle from the supplied message id. Returns null if this queue is not open.
        Parameters:
        id - message id
        Returns:
        operation handle or null
      • put

        public DefaultOperationHandle<?,​?> put​(int id,
                                                     DefaultOperationHandle<?,​?> handle)
                                              throws LdapException
        Puts the supplied operation handle into the queue if the supplied id doesn't already exist in the queue.
        Parameters:
        id - message id
        handle - to put
        Returns:
        null or existing operation handle for the id
        Throws:
        LdapException - if this queue is not open
      • size

        public int size()
        Returns the size of this queue.
        Returns:
        queue size
      • clear

        public void clear()
        Removes all operation handles from the queue.
      • acquireThrottle

        private void acquireThrottle()
                              throws LdapException
        Attempt to acquire the throttle semaphore. No-op if throttling is not enabled.
        Throws:
        LdapException - if the semaphore cannot be acquired or the thread is interrupted
      • releaseThrottle

        private void releaseThrottle​(int permits)
        Release permits on the throttle semaphore. No-op if throttling is not enabled.
        Parameters:
        permits - number of permits to release
      • abandonRequests

        public void abandonRequests()
        Invokes DefaultOperationHandle.abandon() for all handles that have sent a request but not received a response. This method removes all handles from the queue.
      • notifyOperationHandles

        public void notifyOperationHandles​(LdapException e)
        Notifies all operation handles in the queue that an exception has occurred. See DefaultOperationHandle.exception(LdapException). This method removes all handles from the queue.
        Parameters:
        e - exception to provides to handles
      • notifyOperationHandles

        public void notifyOperationHandles​(UnsolicitedNotification notification)
        Send the supplied notification to all handles waiting for a response.
        Parameters:
        notification - to send to response handles