org.jmonit.monitors
Class AbstractMonitor

java.lang.Object
  extended by org.jmonit.monitors.AbstractMonitor
All Implemented Interfaces:
MonitoringEventBus, Monitor
Direct Known Subclasses:
DefaultMonitor

public abstract class AbstractMonitor
extends java.lang.Object
implements Monitor, MonitoringEventBus

A Monitor implementation that delegates to multiple monitors. Each monitor in the composite has a ROLE and can retrieve other monitors from the composite based on it. By convention, defaults monitors are registered using class name as role (or public interface class name)

Author:
Nicolas De Loof

Field Summary
protected  java.util.concurrent.ConcurrentMap<java.lang.Class<?>,Plugin> components
          Components of the composite, with public "feature" API class name as key
protected  java.lang.String name
           
protected  java.util.Set<java.lang.String> tags
           
 
Constructor Summary
AbstractMonitor(java.lang.String name)
           
 
Method Summary
 void add(long value)
          Convenience method to add a primitive numeric data to the monitor.
 void addListener(MonitoringEventListener listener)
          Adds the listener to the collection of listeners who will be notifed when any monitoring event occurs.
 void clear()
          Reset the monitor
 void fireMonitoringEvent(MonitoringEvent event)
          Dispatches the given MonitoringEvent to all registred listeners.
 Plugin get(java.lang.Class role)
           
<T> T
getFeature(java.lang.Class<T> clazz)
          To acces internal optional features or plugable extensions, application asks the monitor for the extension plublic API class.
 java.util.Set<java.lang.Class> getFeatures()
          
 java.lang.String getName()
           
 java.util.Set<java.lang.String> getTags()
          
 boolean hasFeatures(java.lang.Class[] features)
          
 boolean hasListener(MonitoringEventListener listener)
          Returns whether the specified instance of monitoring listener was added to the collection of listeners who will be notifed when an transfer event occurs
 boolean isFeatureSupported(java.lang.Class clazz)
           
 boolean isTagged(java.lang.String tag)
          
protected abstract  void onMonitorTaggedEvent(java.lang.String tag)
           
 void register(Plugin plugin, java.lang.Class role)
           
 void remove(java.lang.Class role)
           
 void removeListener(MonitoringEventListener listener)
          Removes the transfer listener from the collection of listeners so it no longer receives transfer events.
 Monitor tag(java.lang.String tag)
          Tag the monitor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

protected java.lang.String name

tags

protected java.util.Set<java.lang.String> tags

components

protected java.util.concurrent.ConcurrentMap<java.lang.Class<?>,Plugin> components
Components of the composite, with public "feature" API class name as key

Constructor Detail

AbstractMonitor

public AbstractMonitor(java.lang.String name)
Method Detail

add

public void add(long value)
Convenience method to add a primitive numeric data to the monitor.

Specified by:
add in interface Monitor
Parameters:
value - to be monitored
See Also:
Monitor.add(long)

fireMonitoringEvent

public void fireMonitoringEvent(MonitoringEvent event)
Dispatches the given MonitoringEvent to all registred listeners.

Specified by:
fireMonitoringEvent in interface MonitoringEventBus
Specified by:
fireMonitoringEvent in interface Monitor
Parameters:
event - the MonitorTaggedEvent which will be dispached to listeners
See Also:
org.jmonit.Monitor#fireEvent(MonitoringEvent)

clear

public void clear()
Reset the monitor

Specified by:
clear in interface Monitor
See Also:
Monitor.clear()

get

public Plugin get(java.lang.Class role)

isFeatureSupported

public boolean isFeatureSupported(java.lang.Class clazz)
Specified by:
isFeatureSupported in interface Monitor
Returns:
true if the feature is supported by the monitor

hasFeatures

public boolean hasFeatures(java.lang.Class[] features)

Specified by:
hasFeatures in interface Monitor
Parameters:
features - a set of requiered features
Returns:
true if the feature are supported by the monitor
See Also:
Monitor.hasFeatures(java.lang.Class[])

getFeature

public <T> T getFeature(java.lang.Class<T> clazz)
To acces internal optional features or plugable extensions, application asks the monitor for the extension plublic API class. The returned object implements the requested class.

The monitor is expected to "do its best" to return the expected feature, including register new features on-demand. To check for a feature to be supported, use Monitor.isFeatureSupported(java.lang.Class).

Specified by:
getFeature in interface Monitor
Returns:
null if the monitor doesn't support the requested API
See Also:
Monitor.getFeature(Class)

getFeatures

public java.util.Set<java.lang.Class> getFeatures()

Specified by:
getFeatures in interface Monitor
Returns:
all features supported by this monitor
See Also:
Monitor.getFeatures()

register

public void register(Plugin plugin,
                     java.lang.Class role)

remove

public void remove(java.lang.Class role)

getName

public java.lang.String getName()
Specified by:
getName in interface Monitor
Returns:
the name

getTags

public java.util.Set<java.lang.String> getTags()

Specified by:
getTags in interface Monitor
Returns:
the monitor tags
See Also:
Monitor.getTags()

isTagged

public boolean isTagged(java.lang.String tag)

Specified by:
isTagged in interface Monitor
Parameters:
tag - tag to test
Returns:
true if the monitor is tagged
See Also:
Monitor.isTagged(java.lang.String)

tag

public Monitor tag(java.lang.String tag)
Tag the monitor

Specified by:
tag in interface Monitor
Parameters:
tag - the tag
Returns:
the tagged monitor
See Also:
Monitor.tag(java.lang.String)

onMonitorTaggedEvent

protected abstract void onMonitorTaggedEvent(java.lang.String tag)
Parameters:
tag -

addListener

public void addListener(MonitoringEventListener listener)
Description copied from interface: MonitoringEventBus
Adds the listener to the collection of listeners who will be notifed when any monitoring event occurs.
If listener is null, no exception is thrown and no action is performed

Specified by:
addListener in interface MonitoringEventBus
Parameters:
listener - the monitoring listener
See Also:
MonitoringEventBus.removeListener(org.jmonit.events.MonitoringEventListener), MonitoringEventListener

hasListener

public boolean hasListener(MonitoringEventListener listener)
Description copied from interface: MonitoringEventBus
Returns whether the specified instance of monitoring listener was added to the collection of listeners who will be notifed when an transfer event occurs

Specified by:
hasListener in interface MonitoringEventBus
Parameters:
listener - the transfer listener
Returns:
true if given listener was added to the collection of listeners false otherwise
See Also:
MonitoringEventBus.addListener(org.jmonit.events.MonitoringEventListener)

removeListener

public void removeListener(MonitoringEventListener listener)
Description copied from interface: MonitoringEventBus
Removes the transfer listener from the collection of listeners so it no longer receives transfer events.
If listener is null or specified listener was not added to this MonitoringEventSupport object no exception is thrown and no action is performed

Specified by:
removeListener in interface MonitoringEventBus
Parameters:
listener - the monitoring listener
See Also:
MonitoringEventBus.addListener(org.jmonit.events.MonitoringEventListener)


Copyright © 2007 Nicolas De Loof. All Rights Reserved.