...
Code Block | ||||
---|---|---|---|---|
| ||||
import org.fabric3.api.annotation.monitor.Monitor;
public void TheComponent {
@Monitor
protected ComponentMonitor monitor;
public void call(Message message) {
monitor.receivedRequest(message.getId);
try{
validate(message));
} catch (ValidationException e) {
// bad message
monitor.error("Invalid message", e)
}
// ...
}
|
When an @Monitor annotation is encountered, the Fabric3 runtime will generate a monitor proxy and inject it based on the monitor interface. Depending on the current monitor level, events may be logged or ignored. In the above example, if the monitor level is set to severe, the receivedRequest() event will be dropped.
Performance Considerations
Fabric3 uses JDK proxies to implement monitor interfaces. For most code paths in an application, this should not introduce significant performance impact as there are optimizations to avoid object creation when events are discarded. However, for performance intensive code paths, JDK proxies may introduce too much overhead. As an alternative, Fabric3 provides the org.fabric3.api.MonitorChannel interface. A monitor can be typed with this interface, which bypasses JDK proxies and instead uses static method calls:
Code Block | ||||
---|---|---|---|---|
| ||||
import org.fabric3.api.annotation.monitor.Monitor; public void TheComponent { @Monitor protected MonitorChannel monitor; public void call(Message message) { monitor.debug("Received request", message.getId); try{ validate(message)); } catch (ValidationException e) { // bad message monitor.severe("Invalid message", e) } // ... } |
Event-Based Monitoring
Fabric3 monitoring is built on SCA pub/sub eventing (c.f. PubSub Eventing). Monitor events are sent to an underlying channel where consumers can observe them. By default, monitor events emitted from application components are set to the ApplicationMonitorChannel, which is a channel provided by the Fabric3 runtime. The ApplicationMonitorChannel has a consumer attached which records events to a log using SLF4J (SLF4JLogBack (LogBack). For more information on how to configure application event logging, see The Fabric3 Server.