ValueType
- The exact type of the Channel Access values that are provided by
the monitor events.public interface ChannelAccessMonitor<ValueType extends ChannelAccessGettableValue<?>>
Monitor that represents a subscription to a ChannelAccessChannel
.
Subscriptions are the primary way of getting value updates for a Channel
Access channel because they work asynchronously and thus do not require
polling.
A monitor can be created in any connection state (except for a destroyed channel) and survives disconnects. However, it obviously will not deliver any values when the channel is not connected.
A monitor keeps strong references to its listeners and to the corresponding
ChannelAccessChannel
. However, the client implementation might or
might not keep strong references to the monitor. Therefore, user-code should
retain a strong reference to a monitor, in order to keep it alive, but should
also explicitly destroy
a monitor once it is not needed
any longer. Referencing the monitor from its listener might not be enough, if
the listener is only referenced by the monitor and there are no external
strong references.
It is safe to create a separate monitor for every place where one is needed. Monitors for the same channel with the same attributes (data type, element count, event mask) will actually share the same subscription, so that there is no significant overhead for having many monitors. Having a separate monitor for each purpose makes it easier to decide when a monitor is not needed any longer and can be destroyed.
Modifier and Type | Method and Description |
---|---|
boolean |
addMonitorListener(ChannelAccessMonitorListener<? super ValueType> listener)
Registers a listener with this monitor.
|
void |
destroy()
Destroys this monitor.
|
ChannelAccessChannel |
getChannel()
Returns the Channel Access channel that is associated with this monitor.
|
boolean |
isDestroyed()
Tells whether this monitor has been destroyed.
|
boolean |
removeMonitorListener(ChannelAccessMonitorListener<? super ValueType> listener)
Unregisters a listener from this monitor.
|
void destroy()
ChannelAccessChannel getChannel()
boolean isDestroyed()
destroy()
method is called or when its
channel
is destroyed. It might also be destroyed if
it is not used any longer (there are no strong references to it and it is
garbage collected).true
if this monitor has been destroyed,
false
if it is still alive.boolean addMonitorListener(ChannelAccessMonitorListener<? super ValueType> listener)
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.
listener
- listener to be registered with this monitor.true
if the listener has been added,
false
if the listener has already been added
earlier.boolean removeMonitorListener(ChannelAccessMonitorListener<? super ValueType> listener)
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
.
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–2018 aquenos GmbH. All rights reserved.