Package adams.flow.control
Class StorageQueueHandler
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.flow.control.StorageQueueHandler
-
- All Implemented Interfaces:
LoggingSupporter
,SizeOfHandler
,Serializable
public class StorageQueueHandler extends LoggingObject
Wrapper class around anArrayList
object stored in internal storage. Allows to limit the queue size and the specification of a logging actor.- Version:
- $Revision$
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
LogEntry
, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected int
m_Limit
the limit for the queue (-1 is unlimited).protected Actor
m_Logging
the (optional) logging actor.protected Actor
m_Monitoring
the (optional) monitoring actor.protected String
m_Name
the name of the queue.protected ArrayBlockingQueue
m_Queue
the queue itself.-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description StorageQueueHandler(String name)
Initializes the limitless queue with no logging.StorageQueueHandler(String name, int limit, Actor logging, Actor monitoring)
Initializes the queue with the specified limit and logging.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(Object obj)
Adds the object to the queue.int
getLimit()
Returns the limit of the queue.Actor
getLogging()
Returns the logging actor.Actor
getMonitoring()
Returns the monitoring actor.String
getname()
Returns the name of the queue.boolean
hasLogging()
Checks whether a logging actor is available.boolean
hasMonitoring()
Checks whether a monitoring actor is available.protected void
log(LogEntry log, Actor actor)
Logs the log entry with the specified actor.protected void
logError(String msg, Object obj)
Creates a log entry and sends it to the logging actor.protected void
logMonitor(String type, Object obj)
Creates a log entry and sends it to the monitoring actor.Object
poll(long timeout, TimeUnit unit)
Polls the queue in a blocking fashion.Object
remove()
Removes the first element from the queue and returns it.void
setLoggingLevel(LoggingLevel value)
Sets the logging level.int
size()
Returns the size of the queue.String
toString()
Returns a short description of the queue.-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
-
-
-
Field Detail
-
m_Name
protected String m_Name
the name of the queue.
-
m_Queue
protected ArrayBlockingQueue m_Queue
the queue itself.
-
m_Limit
protected int m_Limit
the limit for the queue (-1 is unlimited).
-
m_Logging
protected Actor m_Logging
the (optional) logging actor.
-
m_Monitoring
protected Actor m_Monitoring
the (optional) monitoring actor.
-
-
Constructor Detail
-
StorageQueueHandler
public StorageQueueHandler(String name)
Initializes the limitless queue with no logging.- Parameters:
name
- the name of the queue
-
-
Method Detail
-
setLoggingLevel
public void setLoggingLevel(LoggingLevel value)
Sets the logging level.- Parameters:
value
- the level
-
getname
public String getname()
Returns the name of the queue.- Returns:
- the name
-
getLimit
public int getLimit()
Returns the limit of the queue.- Returns:
- the limit
-
hasLogging
public boolean hasLogging()
Checks whether a logging actor is available.- Returns:
- true if available
-
getLogging
public Actor getLogging()
Returns the logging actor.- Returns:
- the actor, null if not available
-
hasMonitoring
public boolean hasMonitoring()
Checks whether a monitoring actor is available.- Returns:
- true if available
-
getMonitoring
public Actor getMonitoring()
Returns the monitoring actor.- Returns:
- the actor, null if not available
-
log
protected void log(LogEntry log, Actor actor)
Logs the log entry with the specified actor.- Parameters:
log
- the log entry to sendactor
- the logging actor to send the LogEntry to
-
logError
protected void logError(String msg, Object obj)
Creates a log entry and sends it to the logging actor.- Parameters:
msg
- the msgobj
- the object
-
logMonitor
protected void logMonitor(String type, Object obj)
Creates a log entry and sends it to the monitoring actor.- Parameters:
type
- the monitoring event type (Add or Remove)obj
- the object to add, null in case of remove
-
add
public boolean add(Object obj)
Adds the object to the queue.- Parameters:
obj
- the object to add- Returns:
- true if successfully added
-
remove
public Object remove()
Removes the first element from the queue and returns it.- Returns:
- the first element from the queue
-
size
public int size()
Returns the size of the queue.- Returns:
- the size
-
poll
public Object poll(long timeout, TimeUnit unit) throws InterruptedException
Polls the queue in a blocking fashion.- Parameters:
timeout
- the timeout for the pollunit
- the time unit- Returns:
- the value from the queue
- Throws:
InterruptedException
- if interrupted
-
-