You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tuscany.apache.org by Jeremy Boynes <jb...@apache.org> on 2006/04/09 01:42:53 UTC

Monitoring Examples

I added monitoring instrumentation to a couple of the loader classes:
  WSDLDefinitionRegistryImpl
  StAXLoaderRegistryImpl

and setup the JSR47 logging configuration in the helloworld sample to
make it easy to turn monitoring messages from the runtime on and off.

If you look at StAXLoaderRegistryImpl, there is a monitor interface
defined as:
    public static interface Monitor {
        void registeringLoader(QName xmlType);
        void unregisteringLoader(QName xmlType);
        void elementLoad(QName xmlType);
    }

The implementation declares that it depends on an implementation of this
being available by using the @Monitor annotation:

    @org.apache.tuscany.core.system.annotation.Monitor
    public void setMonitor(Monitor monitor) {
        this.monitor = monitor;
    }

When it sees this annotation, the container uses the MonitorFactory to
obtain an instance of the monitor interface above and injects it into
the component (just like any other configuration property).

The component just makes calls on this interface when the applicable
events need to be sent e.g.
    public void registerLoader(StAXElementLoader<T> loader) {
        QName xmlType = loader.getXMLType();
        monitor.registeringLoader(xmlType);
        loaders.put(xmlType, loader);
    }

What happens then depends on the implementation of MonitorFactory that
was supplied to the runtime.

The JSR47-based one uses reflection Proxys to provide an implementation
of the interface and in the InvocationHandler generates a LogRecord
keyed with the class/method name called. Messages are retrieved from a
ResourceBundle located in the package tree of the monitor interface.

[[ This implementation is very inefficient in its use of dynamic proxies
and message lookups. There is room for a lot of performance improvement
there if someone would like to look at codegenerating the interface
implementation and/or other bytecode level tweaks. ]]

I also added setup code to the HelloWorld sample that sets up JSR47 and
an associated MonitorFactory; have a look in HelloWorldClient. This
configures JSR47 from a specific properties file so that all events just
get sent to the console, sets up illustrative default levels, and
defines a specific resource bundle for the messages.

The goal of all this is to make Tuscany components independent of any
specific logging framework (especially clogging) so that they can easily
be embedded in different runtime environments. At the same time, we want
a framework which makes I18N and other logging-type behaviour easy to
add (without having to maintain it all over the codebase).

--
Jeremy