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 LoggerLOGGERLogger for this class.private AtomicBooleannotificationLockOnly one notification can occur at a time.private booleanopenWhether this queue is currently accepting new handles.private Map<Integer,DefaultOperationHandle<?,?>>pendingMap of message IDs to their operation handle.private SemaphorethrottleSemaphore to throttle incoming requests.private static intTHROTTLE_REQUESTSIf property is greater than zero, use the throttle semaphore.private static StringTHROTTLE_REQUESTS_PROPERTYThrottle requests system property.private static DurationTHROTTLE_TIMEOUTMaximum time to wait for the throttle semaphore.private static StringTHROTTLE_TIMEOUT_PROPERTYThrottle 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 voidabandonRequests()InvokesDefaultOperationHandle.abandon()for all handles that have sent a request but not received a response.private voidacquireThrottle()Attempt to acquire the throttle semaphore.voidclear()Removes all operation handles from the queue.voidclose()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.booleanisOpen()Returns whether this handle map is open.voidnotifyOperationHandles(UnsolicitedNotification notification)Send the supplied notification to all handles waiting for a response.voidnotifyOperationHandles(LdapException e)Notifies all operation handles in the queue that an exception has occurred.voidopen()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 voidreleaseThrottle(int permits)Release permits on the throttle semaphore.DefaultOperationHandle<?,?>remove(int id)Removes the operation handle from the supplied message id.intsize()Returns the size of this queue.StringtoString()
-
-
-
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 volatile 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 LdapExceptionAttempt 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
-
-