ValueType
- The exact type of the Channel Access values that are provided by
the monitor events.public abstract class AbstractChannelAccessMonitor<ValueType extends ChannelAccessGettableValue<?>> extends java.lang.Object implements ChannelAccessMonitor<ValueType>
Abstract base class for ChannelAccessMonitor
implementations. This
class takes care of handling the monitor listeners.
This class uses a HashSet
to keep all
ChannelAccessMonitorListeners
that are
registered with this monitor. Derived classes should call the
notifyListeners(ChannelAccessGettableValue)
and
notifyListeners(ChannelAccessStatus, String)
methods in order to
notify the listeners. Implementations may choose to override the
notifyListener(ChannelAccessMonitorListener, ChannelAccessGettableValue)
and
notifyListener(ChannelAccessMonitorListener, ChannelAccessStatus, String)
methods in order to customize the handling of notifications (e.g. catch
certain exceptions possibly thrown by listeners).
Modifier and Type | Field and Description |
---|---|
protected java.lang.Object |
listenerLock
Synchronization object that this class synchronizes on when retrieving or
modifying the set of registered listeners or triggering the listeners.
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractChannelAccessMonitor()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addMonitorListener(ChannelAccessMonitorListener<? super ValueType> listener)
Registers a listener with this monitor.
|
protected void |
notifyListener(ChannelAccessMonitorListener<? super ValueType> listener,
ChannelAccessStatus status,
java.lang.String message)
Notifies a listener about an error.
|
protected void |
notifyListener(ChannelAccessMonitorListener<? super ValueType> listener,
ValueType value)
Notifies a listener about a monitor event with a value that was received
from the server.
|
protected void |
notifyListeners(ChannelAccessStatus status,
java.lang.String message)
Notifies the listeners about an error.
|
protected void |
notifyListeners(ValueType value)
Notifies the listeners about a new value that was received.
|
boolean |
removeMonitorListener(ChannelAccessMonitorListener<? super ValueType> listener)
Unregisters a listener from this monitor.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
destroy, getChannel, isDestroyed
protected final java.lang.Object listenerLock
protected AbstractChannelAccessMonitor()
protected void notifyListeners(ChannelAccessStatus status, java.lang.String message)
notifyListener(ChannelAccessMonitorListener, ChannelAccessStatus, String)
so that derived classes can take extra precautions (e.g. catch certain
exceptions thrown by a listener). This method also saves the last error
so that listeners that are registered after the event can be notified
with the error status.status
- Channel Access status code associated with the error.message
- text message describing the error in greater detail (might be
null
).protected void notifyListeners(ValueType value)
notifyListener(ChannelAccessMonitorListener, ChannelAccessGettableValue)
so that derived classes can take extra precautions (e.g. catch certain
exceptions thrown by a listener). This method also saves the last value
so that listeners that are registered after the event can be notified
with the latest value.value
- value that has been received from the server.protected void notifyListener(ChannelAccessMonitorListener<? super ValueType> listener, ChannelAccessStatus status, java.lang.String message)
listener
- the listener that should be notified. Notifications should
happen by calling the listener's
monitorError(...)
method.status
- Channel Access status code associated with the error.message
- text message describing the error in greater detail (might be
null
).protected void notifyListener(ChannelAccessMonitorListener<? super ValueType> listener, ValueType value)
listener
- the listener that should be notified. Notifications should
happen by calling the listener's
monitorEvent(...)
method.value
- value that has been received from the server.public boolean addMonitorListener(ChannelAccessMonitorListener<? super ValueType> listener)
ChannelAccessMonitor
Registers a listener with this monitor. The listener will be notified when a monitor event occurs or when there is an error affecting the monitor. If the monitor has already received events, the listener is notified about the most recent event when being added.
If the specified listener is already registered with this monitor, no
action is taken and this method returns false
.
Important note: Typically, the listener is executed by
the thread that performs network I/O. For this reason, it is important
that the listener does not block or perform any long-running operations.
Instead, the listener should delegate any such operation to a different
thread (e.g. using an Executor
). Any violation of this rule might
result in unexpected or unpredictable behavior. In particular, a blocking
listener might cause a dead-lock, which results in the whole Channel
Access client being stalled indefinitely.
addMonitorListener
in interface ChannelAccessMonitor<ValueType extends ChannelAccessGettableValue<?>>
listener
- listener to be registered with this monitor.true
if the listener has been added,
false
if the listener has already been added
earlier.public boolean removeMonitorListener(ChannelAccessMonitorListener<? super ValueType> listener)
ChannelAccessMonitor
Unregisters a listener from this monitor. After being removed the listener will not be notified about further events regarding this monitor.
If the specified listener has already been removed from this monitor or
has never been added, no action is taken and this method returns
false
.
removeMonitorListener
in interface ChannelAccessMonitor<ValueType extends ChannelAccessGettableValue<?>>
listener
- listener to be unregistered from this monitor.true
if the listener has been removed,
false
if the listener has already been removed
earlier or if it has never been added.Copyright © 2014–2017 aquenos GmbH. All rights reserved.