public abstract class AbstractVariableMonitor extends Object implements CacheChangedCaster, CacheCaster
| Modifier and Type | Class and Description |
|---|---|
private class |
AbstractVariableMonitor.Update
The repetitive task that refreshes the variables, updates the internal
cache and notifies listeners on cache changes.
|
| Modifier and Type | Field and Description |
|---|---|
private Map<String,Object> |
cache
The actual cache.
|
private Timer |
clock
Used for polling the variable list at fixed delay.
|
private Map<String,Set<CacheChangedListener>> |
ears
A set of listeners for changes on variables values per name.
|
private Object |
lock
If non-null, notified after each poll.
|
private AbstractVariableMonitor.Update |
poll
The polling timer task.
|
private Set<CacheListener> |
polling
The cache listeners.
|
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractVariableMonitor()
Constructor chaining.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addCacheChangedListener(CacheChangedListener ccl,
String key)
Adds a new cache changed listener to this polling instance.
|
void |
addCacheListener(CacheListener ear)
Adds a new cache changed listener to this polling instance.
|
boolean |
addMonitoring(Collection<String> vars)
Adds this list of variables to the monitor.
|
Collection<String> |
getMonitored()
Returns all currently monitored variable names.
|
Object |
getVariable(String name)
Returns the lately cached value of the variable of the provided name.
|
boolean |
isRunning()
Returns true, if the polling is in progress.
|
private void |
notifyListeners(CacheChangedEvent cce,
Collection<CacheChangedListener> signal)
Synchronizes on the listeners and notifies each of a cache changed event.
|
protected abstract Map<String,Object> |
refreshVariables(Collection<String> vars)
This method actually does the read-in of the variables.
|
void |
removeCacheChangedListener(CacheChangedListener ear,
String key)
Removes a cache changed listener from this polling instance.
|
void |
removeCacheListener(CacheListener ear)
Removes a cache changed listener from this polling instance.
|
int |
removeMonitoring(Collection<String> vars)
Removes the list of variables from the monitoring
|
void |
setLock(Object lock) |
void |
startMonitoring(long delay,
long period)
Starts monitoring of all variables.
|
void |
stopMonitoring()
Stops cache refreshing.
|
private Timer clock
private final Set<CacheListener> polling
private Map<String,Set<CacheChangedListener>> ears
private AbstractVariableMonitor.Update poll
private Object lock
protected AbstractVariableMonitor()
public void addCacheListener(CacheListener ear)
addCacheListener in interface CacheCasterear - The listener to be notified when the cache value changes.CacheCaster.addCacheListener(stella.io.CacheListener)public void removeCacheListener(CacheListener ear)
removeCacheListener in interface CacheCasterear - The listener to be notified when the cache value changes.CacheCaster.removeCacheListener(stella.io.CacheListener)public void addCacheChangedListener(CacheChangedListener ccl, String key)
addCacheChangedListener in interface CacheChangedCasterccl - The listener to be notified when the cache value changes.key - The serial command this listenr is interested in.public void removeCacheChangedListener(CacheChangedListener ear, String key)
removeCacheChangedListener in interface CacheChangedCasterear - The listener to be notified when the cache value changes.key - The serial command this listenr is interested in.private void notifyListeners(CacheChangedEvent cce, Collection<CacheChangedListener> signal)
cce - The cache changed event created during pollingsignal - The list of registered listeners for the events variable name.protected abstract Map<String,Object> refreshVariables(Collection<String> vars)
vars - Names of all variables that should be refreshedpublic boolean addMonitoring(Collection<String> vars)
vars - public int removeMonitoring(Collection<String> vars)
vars - public Collection<String> getMonitored()
public Object getVariable(String name)
name - The variables namepublic void setLock(Object lock)
lock - the lock to setpublic void startMonitoring(long delay,
long period)
public void stopMonitoring()
refreshVariables(Collection) will occur, thus underlying driver
can savely be closed.public boolean isRunning()