public class ThreadedMatcherEditor<E> extends AbstractMatcherEditorListenerSupport<E>
Internally, a ThreadedMatcherEditor enqueues MatcherEvents as they
they are received from the source MatcherEditor. The MatcherEvents on the
queue are fired by another Thread as rapidly as the MatcherEditorListeners
can consume them. Two methods exist on this class which enable subclasses
to customize aspects of processing queued MatcherEvents:
executeMatcherEventQueueRunnable(Runnable) is consulted when
a Thread must be selected to execute the given Runnable which will
drain the queue of MatcherEvents. Subclasses may override to
customize which Thread is used.
coalesceMatcherEvents(List) is used to compress
many enqueued MatcherEvents into a single representative
MatcherEvent. This implies a contract between all registered
MatcherEditorListeners and this ThreadedMatcherEditor that
guarantees that processing the coalesced MatcherEvent is equivalent
to processing all MatcherEvents sequentially.
MatcherEditor threadedMatcherEditor = new ThreadedMatcherEditor(new AnyMatcherEditor()); FilterList filterList = new FilterList(new BasicEventList(), threadedMatcherEditor);
MatcherEditor.Event<E>, MatcherEditor.Listener<E>| Constructor and Description |
|---|
ThreadedMatcherEditor(MatcherEditor<E> source)
Creates a ThreadedMatcherEditor which wraps the given
source. |
ThreadedMatcherEditor(MatcherEditor<E> source,
java.util.concurrent.Executor executor)
Creates a ThreadedMatcherEditor which wraps the given
source. |
| Modifier and Type | Method and Description |
|---|---|
protected MatcherEditor.Event<E> |
coalesceMatcherEvents(java.util.List<MatcherEditor.Event<E>> matcherEvents)
This method implements the strategy for coalescing many queued
MatcherEvents into a single representative MatcherEvent.
|
protected void |
executeMatcherEventQueueRunnable(java.lang.Runnable runnable)
This method executes the given
runnable on a Thread. |
java.util.concurrent.Executor |
getExecutor()
Returns the executor used to process the enqueued MatcherEvents.
|
Matcher<E> |
getMatcher()
Returns the current Matcher specified by the source
MatcherEditor. |
addMatcherEditorListener, createChangedEvent, createConstrainedEvent, createMatchAllEvent, createMatchNoneEvent, createRelaxedEvent, fireChangedMatcher, removeMatcherEditorListenerclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitfromMatcherpublic ThreadedMatcherEditor(MatcherEditor<E> source)
source.
MatcherEvents fired from the source will be enqueued within
this MatcherEditor until they are processed on an alternate Thread.
The Thread selection strategy is encapsulated by a default executor,
which always starts a new thread (for backward compatibility).
Another constructor is provided for specifying a custom executor.source - the MatcherEditor to wrap with buffering functionalityjava.lang.NullPointerException - if source is nullThreadedMatcherEditor(MatcherEditor, Executor)public ThreadedMatcherEditor(MatcherEditor<E> source, java.util.concurrent.Executor executor)
source.
MatcherEvents fired from the source will be enqueued within
this MatcherEditor until they are processed on an alternate Thread.
The Thread selection strategy is encapsulated by the provided executor.source - the MatcherEditor to wrap with buffering functionalityexecutor - strategy for processing the enqueued MatcherEvents, if an ExecutorService is passed, it has to be shutdown by the providerjava.lang.NullPointerException - if source is nullexecuteMatcherEventQueueRunnable(Runnable)public Matcher<E> getMatcher()
MatcherEditor.MatcherEditorpublic java.util.concurrent.Executor getExecutor()
ExecutorService was passed in, it has to be shutdown by the provider.protected MatcherEditor.Event<E> coalesceMatcherEvents(java.util.List<MatcherEditor.Event<E>> matcherEvents)
matcherEvents were fired
sequentially. In general, any group of matcherEvents can be
succesfully coalesced as a single MatcherEvent with a type of
changed, however, this method's default implementation
uses a few heuristics to do more intelligent coalescing in order to
gain speed improvements:
matcherEvents ends in a MatcherEvent which is a
MatcherEditor.Event.MATCH_ALL or MatcherEditor.Event.MATCH_NONE
type, the last MatcherEvent is returned, regardless of previous
MatcherEvents
matcherEvents only contains a series of
monotonically constraining MatcherEvents, the final MatcherEvent
is returned
matcherEvents only contains a series of
monotonically relaxing MatcherEvents, the final MatcherEvent is
returned
matcherEvents contains both constraining and
relaxing MatcherEvents, the final MatcherEvent is returned with
its type as MatcherEditor.Event.CHANGED
1, 2, and 3 above merely represent
safe optimizations of the type of MatcherEvent that can be returned.
It could also have been returned as a MatcherEvent with a type of
MatcherEditor.Event.CHANGED and be assumed to work correctly, though
potentially less efficiently, since it is a more generic type of change.
Subclasses with the ability to fire precise MatcherEvents with fine grain
types (i.e. relaxed or constrained) when
coalescing matcherEvents in situations not recounted above
may do so by overiding this method.
matcherEvents - an array of MatcherEvents recorded in the order
they were received from the source MatcherEditormatcherEvents had been fired
sequentiallyprotected void executeMatcherEventQueueRunnable(java.lang.Runnable runnable)
runnable on a Thread.
The particular Thread chosen to execute the Runnable is left to the
executor provided as constructor argument. When no executor is provided,
a default executor will be used, which constructs a new Thread named
MatcherQueueThread to execute the runnable
each time this method is called. Subclasses may override this method
to use any Thread selection strategy they wish, but providing a custom
executor is now the preferred way.runnable - a Runnable to execute on an alternate ThreadThreadedMatcherEditor(MatcherEditor, Executor)Glazed Lists, Copyright © 2003 publicobject.com, O'Dell Engineering.
Documentation build by swimmesberger at Wed Feb 13 09:45:20 CET 2019