DebugList is meant to be used as a drop-in replacement for
BasicEventList
at the root of pipelines of
EventList
s during
development. It provides methods for turning on various types of assertions
which throw
RuntimeException
s when they are violated. The goal is to
detect and fail fast on error conditions in much the same way Iterators
commonly throw
java.util.ConcurrentModificationException
s.
Some of the assertions that are controlled by this DebugList include:
setLockCheckingEnabled(boolean)
toggles whether this DebugList
asserts that all read operations are guarded by read locks and all
write operations are guarded by write locks.
getSanctionedReaderThreads()
is the Set of Threads which are
allowed to read from the DebugList. If the Set is empty then
ALL Threads are assumed to be sanctioned readers.
getSanctionedWriterThreads()
is the Set of Threads which are
allowed to write to the DebugList. If the Set is empty then
ALL Threads are assumed to be sanctioned writers.
This class is left non-final to allow subclassing but since it is a
debugging tool, we make no guarantees about backward compatibility between
releases. It is meant to evolve as users discover new assertions to be added.
DebugList createNewDebugList
public DebugList createNewDebugList()
Returns a new empty
DebugList
which shares the same
ListEventListener
and
ReadWriteLock
with this DebugList.
This method is particularly useful when debugging a
CompositeList
where some member lists are DebugLists and thus must share an identical
publisher and locks in order to participate in the CompositeList.
afterReadOperation
protected void afterReadOperation()
This method is currently a no-op and exists for parity. Subclasses may
choose to insert extract assertion logic here.
afterWriteOperation
protected void afterWriteOperation()
This method is currently a no-op and exists for parity. Subclasses may
choose to insert extract assertion logic here.
beforeReadOperation
protected void beforeReadOperation()
This generic method is called immediately before any read operation is
invoked. All generic read assertions should take place here.
beforeWriteOperation
protected void beforeWriteOperation()
This generic method is called immediately before any write operation is
invoked. All generic write assertions should take place here.
getSanctionedReaderThreads
public Set getSanctionedReaderThreads()
Returns the Set
of Threads that are allowed to perform reads on
this DebugList. If the Set
is empty, all Threads are allowed to
read from this DebugList. Users are expected to add and remove Threads
directly on this Set
.
getSanctionedWriterThreads
public Set getSanctionedWriterThreads()
Returns the Set
of Threads that are allowed to perform writes on
this DebugList. If the Set
is empty, all Threads are allowed to
write to this DebugList. Users are expected to add and remove Threads
directly on this Set
.
isLockCheckingEnabled
public boolean isLockCheckingEnabled()
Returns true if DebugList is currently checking the calling
Thread for lock ownership before each read and write operation.
setLockCheckingEnabled
public void setLockCheckingEnabled(boolean lockCheckingEnabled)
If lockCheckingEnabled
is true this DebugList will
check the calling Thread for lock ownership before each read and write
operation; false indicates this check shouldn't be performed.