com.ibm.ia.testdriver
Class DebugInfoReceiverQueue
- java.lang.Object
-
- com.ibm.ia.testdriver.DebugInfoReceiverQueue
-
- All Implemented Interfaces:
- DebugReceiver
public class DebugInfoReceiverQueue extends java.lang.Object implements DebugReceiver
A reference implementation of theDebugReceiverinterface. A queue abstraction for cachingDebugInfoelements allows for capacity bounds and the definition of a retention policy. Elements are maintained in a FIFO order and stored and retrieved on a per agent basis. Retrieval can be blocking or non-blocking and the caching of new elements can be dynamically suspended and resumed on a solution wide basis.This class was not explicitly designed to be extended.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classDebugInfoReceiverQueue.DiscardPolicyDefine the the retention policy options for the agent queues.
-
Constructor Summary
Constructors Constructor and Description DebugInfoReceiverQueue()Deprecated.DebugInfoReceiverQueue(DriverProperties driverProperties)Create a newDebugInfoReceiverQueuecache for the agents of a given solution.
-
Method Summary
Methods Modifier and Type Method and Description voidaddDebugInfo(DebugInfo instance, java.lang.String sourceagent)The default policy is to discard the newest (arriving) elements if the capacity limits for a given agent queue are reached.java.lang.String[]agentQueueNames()Answers with the names of all agent queues in use for caching at the time of the call.voidclearDebugInfo()Remove allDebugInfoelements from all agent queues.voidclearDebugInfo(java.lang.String agent)Remove allDebugInfoelements from the target agent queue.intgetCapacity()Answers with the maximum element capacity of the individual agent queues.DebugInfogetDebugInfo(java.lang.String agent)Retrieves the element at the head of the queue for a given agent, removing it from the queue.DebugInfo[]getDebugInfo(java.lang.String agent, int count)Retrieves and removes at most the given number of available elements from the named agent queue.DebugInfogetDebugInfo(java.lang.String agent, long timeout, java.util.concurrent.TimeUnit unit)Retrieves and removes the element at the head of the given agent queue, waiting up to the specified wait time if necessary for an element to become available.DebugInfo[]getDebugInfo(java.lang.String agent, long timeout, java.util.concurrent.TimeUnit unit, int count)Retrieves and removes at most the given number of available elements from the named agent queue, waiting up to the specified amount of time for those elements to appear.DebugInfoReceiverQueue.DiscardPolicygetDiscardPolicy()Answers with the current state of the agent queue retention policy.booleanisPaused()Answers whether the the caching of newDebugInfoelements has been suspended.DebugInfopeekDebugInfo(java.lang.String agent)Retrieves the element at the head of the queue for the given agent.voidsetDiscardPolicy(DebugInfoReceiverQueue.DiscardPolicy policy)Set the retention policy for all agent queues.voidsetPaused(boolean pause)Suspend or resume the caching ofDebugInfoelements on a solution wide basis.intsizeDebugInfo(java.lang.String agent)Answers the number ofDebugInfoelements in a given agent's queue at the time of the call.DebugInfotakeDebugInfo(java.lang.String agent)Retrieves and removes the element at the head of this agent queue, waiting if necessary until an element becomes available.
-
-
-
Constructor Detail
-
DebugInfoReceiverQueue
@Deprecated public DebugInfoReceiverQueue()
Deprecated. UseDebugInfoReceiverQueue(DriverProperties).Create a newDebugInfoReceiverQueuecache for the agents of a given solution. Capacity limits for the agent element queues are set to the default value fromDriverPropertiesclass.
-
DebugInfoReceiverQueue
public DebugInfoReceiverQueue(DriverProperties driverProperties)
Create a newDebugInfoReceiverQueuecache for the agents of a given solution. Capacity limits for the agent element queues are set to the value from the suppliedDriverPropertiesclass.- Parameters:
driverProperties- aDriverPropertiesobject containing the desired capacity limit for agent queues
-
-
Method Detail
-
addDebugInfo
public void addDebugInfo(DebugInfo instance, java.lang.String sourceagent)
The default policy is to discard the newest (arriving) elements if the capacity limits for a given agent queue are reached. It is possible to change the policy to one where the oldest elements are evicted instead.- Specified by:
addDebugInfoin interfaceDebugReceiversourceagent- - the name of the agent which generated the event- See Also:
DebugReceiver.addDebugInfo(com.ibm.ia.common.debug.DebugInfo, java.lang.String)
-
peekDebugInfo
public DebugInfo peekDebugInfo(java.lang.String agent)
Retrieves the element at the head of the queue for the given agent. The element is not removed from the queue. No guarantee is made that the element will be available for retrieval at a subsequent point in time.- Parameters:
agent- the name of agent queue to peek into- Returns:
- A
DebugInfoelement ornullif the queue is empty or there is no queue for the agent
-
takeDebugInfo
public DebugInfo takeDebugInfo(java.lang.String agent) throws java.lang.InterruptedException
Retrieves and removes the element at the head of this agent queue, waiting if necessary until an element becomes available.- Throws:
java.lang.InterruptedException- if interrupted while waiting- Parameters:
agent- the name of agent queue to take from- Returns:
- A
DebugInfoelement from the head of the agent's queue, null if there is no queue for the requested agent
-
getDebugInfo
public DebugInfo getDebugInfo(java.lang.String agent)
Retrieves the element at the head of the queue for a given agent, removing it from the queue.- Parameters:
agent- the name of agent queue to get from- Returns:
- A
DebugInfoelement ornullif the queue is empty or there is no queue for the agent
-
getDebugInfo
public DebugInfo getDebugInfo(java.lang.String agent, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
Retrieves and removes the element at the head of the given agent queue, waiting up to the specified wait time if necessary for an element to become available.- Throws:
java.lang.InterruptedException- if interrupted while waiting- Parameters:
agent- the name of the agent queue to get fromtimeout- how long to wait in units ofunitbefore returningunit- aTimeUnitdescribing how to interpret thetimeoutvalue- Returns:
- A
DebugInfoelement ornullif the time to wait expires and the queue is still empty or there is no queue for the agent
-
getDebugInfo
public DebugInfo[] getDebugInfo(java.lang.String agent, int count)
Retrieves and removes at most the given number of available elements from the named agent queue.- Parameters:
agent- the name of the agent queue to get fromcount- the maximum number ofDebugInfoelements to return- Returns:
- an array of
DebugInfoelements where the size of the array is from zero up to thecount
-
getDebugInfo
public DebugInfo[] getDebugInfo(java.lang.String agent, long timeout, java.util.concurrent.TimeUnit unit, int count) throws java.lang.InterruptedException
Retrieves and removes at most the given number of available elements from the named agent queue, waiting up to the specified amount of time for those elements to appear. No order or sequence guarantees are made if this call is interleaved with other retrieval methods in a threaded environment. When only one element is desired (i.e.countis 1) then usegetDebugInfo(String, long, TimeUnit).- Throws:
java.lang.InterruptedException- if interrupted while waiting- Parameters:
agent- the agent queue to get fromtimeout- how long to wait in units ofunitbefore returningunit- aTimeUnitdescribing how to interpret thetimeoutvaluecount- the maximum number ofDebugInfoelements to return- Returns:
- an array of
DebugInfoelements where the size of the array is from zero up to thecount
-
agentQueueNames
public java.lang.String[] agentQueueNames()
Answers with the names of all agent queues in use for caching at the time of the call. Initially there are no queues. When aDebugInfoobject arrives a new queue is created. When an agent queue is cleared viaclearDebugInfo(String)orclearDebugInfo()it is dropped until a newDebugInfoarrives.- Returns:
- an array of String containing the names of all agent queues
-
sizeDebugInfo
public int sizeDebugInfo(java.lang.String agent)
Answers the number ofDebugInfoelements in a given agent's queue at the time of the call.- Parameters:
agent- the name of agent queue to size- Returns:
- the number of
DebugInfoelements in the agent queue, -1 if the size could not be determined
-
clearDebugInfo
public void clearDebugInfo()
Remove allDebugInfoelements from all agent queues. Caching is automatically paused during this operation if it was not paused already. The state of caching is restored before exiting.
-
clearDebugInfo
public void clearDebugInfo(java.lang.String agent)
Remove allDebugInfoelements from the target agent queue. Caching is automatically paused during this operation if it was not paused already. The state of caching is restored before exiting.- Parameters:
agent- the name of the agent queue to clear
-
getCapacity
public int getCapacity()
Answers with the maximum element capacity of the individual agent queues. When this capacity is reached, incomingDebugInfoelements are handled according to the queue retention policy.- Returns:
- the maximum number of
DebugInfoelements each agent queue can hold
-
getDiscardPolicy
public DebugInfoReceiverQueue.DiscardPolicy getDiscardPolicy()
Answers with the current state of the agent queue retention policy.- Returns:
DISCARDNEWESTif arriving elements are to be discarded orDISCARDOLDESTif the oldest elements should be evicted instead
-
setDiscardPolicy
public void setDiscardPolicy(DebugInfoReceiverQueue.DiscardPolicy policy)
Set the retention policy for all agent queues. When the arrival of a newDebugInfoelement would cause an agent's queue to exceed its capacity, elements are discarded or evicted from the queue. The elements to be discarded can be the arriving elements or the oldest elements in the queue.- Parameters:
policy-DISCARDNEWESTto have arriving elements discarded orDISCARDOLDESTto have the oldest elements removed from the queue
-
isPaused
public boolean isPaused()
Answers whether the the caching of newDebugInfoelements has been suspended. When caching is suspended arrivingDebugInfoelements are discarded.- Returns:
- a
booleanvalue oftrueif caching is suspended,falseif caching is active
-
setPaused
public void setPaused(boolean pause)
Suspend or resume the caching ofDebugInfoelements on a solution wide basis. When caching is paused, arrivingDebugInfoelements are discarded.- Parameters:
pause- abooleanvalue oftruesuspends caching,falseresumes
-
-