Package org.ldaptive.transport
Class HandleMap
- java.lang.Object
-
- org.ldaptive.transport.HandleMap
-
public final class HandleMap extends Object
Container for operation handles that are waiting on a response from the LDAP server.
-
-
Field Summary
Fields Modifier and Type Field Description private static Logger
LOGGER
Logger for this class.private AtomicBoolean
notificationLock
Only one notification can occur at a time.private boolean
open
Whether this queue is currently accepting new handles.private Map<Integer,DefaultOperationHandle<?,?>>
pending
Map of message IDs to their operation handle.private Semaphore
throttle
Semaphore to throttle incoming requests.private static int
THROTTLE_REQUESTS
If property is greater than zero, use the throttle semaphore.private static String
THROTTLE_REQUESTS_PROPERTY
Throttle requests system property.private static Duration
THROTTLE_TIMEOUT
Maximum time to wait for the throttle semaphore.private static String
THROTTLE_TIMEOUT_PROPERTY
Throttle timeout system property.
-
Constructor Summary
Constructors Constructor Description HandleMap()
Creates a new handle map.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
abandonRequests()
InvokesDefaultOperationHandle.abandon()
for all handles that have sent a request but not received a response.private void
acquireThrottle()
Attempt to acquire the throttle semaphore.void
clear()
Removes all operation handles from the queue.void
close()
Close the queue to new handles.DefaultOperationHandle<?,?>
get(int id)
Returns the operation handle for the supplied message id.Collection<DefaultOperationHandle<?,?>>
handles()
Returns all the operation handles in the queue.boolean
isOpen()
Returns whether this handle map is open.void
notifyOperationHandles(UnsolicitedNotification notification)
Send the supplied notification to all handles waiting for a response.void
notifyOperationHandles(LdapException e)
Notifies all operation handles in the queue that an exception has occurred.void
open()
Open this queue to receive new handles.DefaultOperationHandle<?,?>
put(int id, DefaultOperationHandle<?,?> handle)
Puts the supplied operation handle into the queue if the supplied id doesn't already exist in the queue.private void
releaseThrottle(int permits)
Release permits on the throttle semaphore.DefaultOperationHandle<?,?>
remove(int id)
Removes the operation handle from the supplied message id.int
size()
Returns the size of this queue.String
toString()
-
-
-
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.
-
pending
private final Map<Integer,DefaultOperationHandle<?,?>> pending
Map of message IDs to their operation handle.
-
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.
-
-
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 idhandle
- to put- Returns:
- null or existing operation handle for the id
- Throws:
LdapException
- if this queue is not open
-
handles
public Collection<DefaultOperationHandle<?,?>> handles()
Returns all the operation handles in the queue.- Returns:
- all operation handles
-
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()
InvokesDefaultOperationHandle.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. SeeDefaultOperationHandle.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
-
-