Hi,

Can we create a wiki page to post these information?

Thanks,
Raymond
--------------------------------------------------
From: "Ramkumar R" <[EMAIL PROTECTED]>
Sent: Monday, June 16, 2008 3:47 AM
To: <tuscany-dev@ws.apache.org>
Subject: [Summary] Monitor Extension Functionality & How to create a new monitor extension

Here is the brief summary on the monitor extensions, please review the same
and post your comments and suggestions on the same. This would help us for
the documentation.
**
*Need for Monitor Extension:*
**The need for monitor extension came as a requirement, to have a customized exception handling on Tuscany runtime especially when the user input errors
are determined while reading, resolving and building phase of the
contribution within the Tuscany runtime. Here different users/vendors using
Tuscany with their products wanted to ignore some of the user input errors
and allow the runtime to proceed further, while the others wanted to stop
processing when a error is determined at the end of each phase.



Another important need for a monitor extension is to validate the user
inputs (via contributions) and report all the issues identified in one go
(Example: As how the java compiler does for java code).

* *
*How monitor extension is applied to the current code:*
Currently monitors are introduced into various part of the code, where we do a validation for user input at different phases while reading, resolving and
building the contribution.
**

**

1. Errors and warnings are logged with the monitor as problems and the
processing
continues. Exceptions won't be thrown, where ever possible. Processing here
covers any processing of user input, i.e. contributions and the artifacts
they contain.



2. After each phase namely read, resolve and build contribution, the problems are read from the monitor for display to the user (currently this will have already happened as our current monitor will just log errors and warnings as
it receives them but you can imagine more capable monitors).



3. The controlling logic may look at the errors and warnings it is reporting
to the user and prevent further processing occurring. Or it may allow
processing
to continue. This  depends on which bit of processing we are talking about
and what errors have been reported.

* *

*How to initialize the monitor from the core runtime:*

Monitors are initialized in the core runtime using the utility extensions as
shown below.



UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(
UtilityExtensionPoint.*class*);

MonitorFactory monitorFactory = utilities.*getUtility*(MonitorFactory.*class
*);

monitor = monitorFactory.createMonitor();



* *

*Creating a Monitor Extension:*

* *

*NOTE: *Please have a look at the interface design of Monitor, Problem and
MonitorFactory from monitor module in the Tuscany source code.**

* *

*Step 1:  *Create a class MyMonitorImpl.java which implements the Monitor
interface.



*public* *class* MyMonitorImpl* implements* Monitor {

   *private* *static* *final* Logger *logger* = Logger.*getLogger*(
MyMonitorImpl.*class*.getName());



   // Cache all the problem reported to monitor for further analysis

   *private* List<Problem> problemCache = *new* ArrayList<Problem>();



   *public* *void* problem(Problem problem) {

       // Your custom code to handle the problem

   }

}**

**
**
In this code, we keep a cache of all the problems reported via the monitor
to allow the controlling logic to decide if the processing should continue
or not.
* *

*Step 2: *Create a class MyMonitorFactoryImpl.java which implements
the MonitorFactory
interface.



*public* *class* MyMonitorFactoryImpl* implements* MonitorFactory {



   *private* Monitor monitor = *null*;



   *public* Monitor createMonitor() {

       *if* (monitor == *null*){

           monitor = *new* MyMonitorImpl();

       }

       *return* monitor ;

   }

}





*Step 3: *Create a plain text file named as "META-
INF/services/org.apache.tuscany.sca.monitor.MonitorFactory"


Register the extension by adding a line in this file as shown below….
org.apache.tuscany.sca.monitor.impl.MyMonitorFactoryImpl

--
Thanks & Regards,
Ramkumar Ramalingam

Reply via email to