To avoid your application to depend on jMonit implementation
code, jMonit provides the feature API : Any aggregator of the
composite Monitor can expose a public interface, that we call
"Feature". The instrumented application can use those features
when the default
add(long)
method is not sufficient to expose it's state. This API class is
used as the identifier for aggregators factories.
The
monitor.getFeature(class)
method is used to acces a feature. This method MAY return null,
so allways check the returned object. The class argument is the
expected feature API interface. Thanks to Java5 constructs, the
returned object is safelly casted. The default Monitor
implementation will anto-enhance it's composite to add the
requested feature.
The following code sample demonstrates the feature API usage. Based on an existing monitor, we ask for a feature, dedicated to HTTP status monitoring. The returned object is then used to monitor the current request.
HttpStatus status = monitor.getFeature( HttpStatus.class ); if ( status != null ) { status.setHttpStatus( sc ); }
In many case, the aggregator code is simple and we can use a single class for aggregator and feature (feature is not required to be an interface).