Hello,
I tried to produce a working piece of code showing how a JSR77 implementation could be separated from the kernel by exposing some instrumentation hooks.
More accurately, here is a short description of the general idea:
A kernel component, KC, mirroring a J2EE managed object, MO, implements the following interface:
public interface InstrumentationHook {
public J2EEManagedObject getManagedObject();
public void setEventProviderInst(EvtProvInst anEvtProv);
public StateManageableInst getStateManageableInst();
}KC creates its corresponding MO.
KC calls MO.setEventProvider() in order to notify MO that it emits events. If KC emits events, then MO calls back KC via the setEventProviderInst() method. The instance passed to KC is an event provider instrumentation hook used by KC to send event to the JSR77 model.
KC calls MO.setStateManageable() in order to notify MO that its state is manageable. If the state of KC is manageable, then MO calls back KC via the getStateManageableInst() method. The returned instance is an instrumentation hook used by MO to manage the state of KC.
Regarding the statistics, I assume that the same mechanism could be applied.
What I like in this implementation is the fact that it is orthogonal - to some extent - to the kernel. More accurately, it could potentially be a re-usable component. The kernel deals with the instrumentation hooks provided by the implementation and that is it.
Let me know if this proposition makes sense and if it worth the price to investigate more in this direction or if I should give up.
Cheers, Gianny
_________________________________________________________________
MSN Messenger 6 http://g.msn.fr/FR1001/866 : ajoutez une image � votre pseudo pour dialoguer avec vos amis
<<attachment: demo-specs-j2ee-management-18082003.zip>>
Index: incubator/modules/core/src/java/org/apache/geronimo/common/AbstractStateManageable.java===================================================================
RCS file: /home/cvspublic/incubator-geronimo/modules/core/src/java/org/apache/geronimo/common/AbstractStateManageable.java,v
retrieving revision 1.3
diff -u -r1.3 AbstractStateManageable.java
--- incubator/modules/core/src/java/org/apache/geronimo/common/AbstractStateManageable.java 16 Aug 2003 23:16:18 -0000 1.3
+++ incubator/modules/core/src/java/org/apache/geronimo/common/AbstractStateManageable.java 18 Aug 2003 10:57:08 -0000
@@ -55,6 +55,7 @@
*/
package org.apache.geronimo.common;
+import java.lang.reflect.Method;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@@ -85,6 +86,11 @@
import org.apache.geronimo.deployment.dependency.DependencyServiceMBean;
import org.apache.geronimo.deployment.service.MBeanRelationship;
import org.apache.geronimo.jmx.JMXUtil;
+import org.apache.geronimo.management.j2ee.J2EEManagedObject;
+import org.apache.geronimo.management.j2ee.instrumentation.EvtProvInst;
+import org.apache.geronimo.management.j2ee.instrumentation.EvtProvInstImpl;
+import org.apache.geronimo.management.j2ee.instrumentation.InstrumentationHook;
+import org.apache.geronimo.management.j2ee.instrumentation.StateManageableInst;
/**
* Abstract implementation of JSR77 StateManageable.
@@ -93,7 +99,15 @@
*
* @version $Revision: 1.3 $ $Date: 2003/08/16 23:16:18 $
*/
-public abstract class AbstractStateManageable extends NotificationBroadcasterSupport implements StateManageable, NotificationListener, MBeanRegistration {
+public abstract class AbstractStateManageable
+ extends NotificationBroadcasterSupport
+ implements StateManageableInst, NotificationListener, MBeanRegistration,
+ InstrumentationHook {
+
+ protected J2EEManagedObject m_managedObject;
+ protected EvtProvInst m_eventProviderInst =
+ EvtProvInstImpl.SILENT_PROVIDER;
+
protected Log log = LogFactory.getLog(getClass());
protected MBeanServer server;
protected ObjectName objectName;
@@ -119,6 +133,23 @@
*/
protected abstract void doStop() throws Exception;
+ public AbstractStateManageable() {
+ initManagedObject();
+ }
+
+ public J2EEManagedObject getManagedObject() {
+ return m_managedObject;
+ }
+
+ public StateManageableInst getStateManageableInst() {
+ return null;
+ }
+
+ public void setEventProviderInst(
+ EvtProvInst eventProviderInstrumentation) {
+ m_eventProviderInst = eventProviderInstrumentation;
+ }
+
public MBeanNotificationInfo[] getNotificationInfo() {
return new MBeanNotificationInfo[]{
new MBeanNotificationInfo(J2EENotification.TYPES,
@@ -256,6 +287,9 @@
}
}+ protected void initManagedObject() {
+ }
+
private final void doNotification(String s) {
sendNotification(new Notification(s, this, sequenceNumber++));
}
@@ -449,7 +483,24 @@
startTime = System.currentTimeMillis();
}
state = newState;
-
+
+ switch (state.toInt()) {
+ case State.STARTING_INDEX:
+ m_eventProviderInst.sendStarting(m_managedObject);
+ break;
+ case State.STOPPING_INDEX:
+ m_eventProviderInst.sendStopping(m_managedObject);
+ break;
+ case State.RUNNING_INDEX:
+ m_eventProviderInst.sendRunning(m_managedObject);
+ break;
+ case State.STOPPED_INDEX:
+ m_eventProviderInst.sendStopped(m_managedObject);
+ break;
+ case State.FAILED_INDEX:
+ m_eventProviderInst.sendFailed(m_managedObject);
+ break;
+ }
doNotification(state.getEventTypeValue());
}
}
Index: incubator/modules/core/src/java/org/apache/geronimo/deployment/scanner/DeploymentScanner.java
===================================================================
RCS file: /home/cvspublic/incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/scanner/DeploymentScanner.java,v
retrieving revision 1.8
diff -u -r1.8 DeploymentScanner.java
--- incubator/modules/core/src/java/org/apache/geronimo/deployment/scanner/DeploymentScanner.java 17 Aug 2003 06:09:14 -0000 1.8
+++ incubator/modules/core/src/java/org/apache/geronimo/deployment/scanner/DeploymentScanner.java 18 Aug 2003 10:57:10 -0000
@@ -57,10 +57,9 @@
import java.io.File;
import java.io.IOException;
+import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
-import java.net.URI;
-import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -68,7 +67,6 @@
import java.util.Set;
import java.util.Collections;
import java.util.StringTokenizer;
-import javax.management.MBeanRegistration;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.management.relation.RelationServiceMBean;
@@ -76,6 +74,9 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.geronimo.jmx.JMXUtil;
+import org.apache.geronimo.management.j2ee.ManagedObjectFactory;
+import org.apache.geronimo.management.j2ee.ManagedObjectFactoryImpl;
+import org.apache.geronimo.management.j2ee.instrumentation.StateManageableInst;
import org.apache.geronimo.common.AbstractStateManageable;
/**
@@ -221,4 +222,80 @@
log.error(e.getMessage(), e);
}
}
+
+ /**
+ * This method MUST be overriden by components mapped to a J2EE managed
+ * object.
+ *
+ * A standard implementation is to:
+ * <ul>
+ * <li>Create the relevant J2EE managed object; and
+ * <li>Register against this managed object the types of information
+ * provided.
+ * </ul>
+ */
+ protected void initManagedObject() {
+
+ ManagedObjectFactory factory = new ManagedObjectFactoryImpl();
+
+ // Create the managed object mirroring this component. For demonstration
+ // purpose, a J2EEDomain is used.
+ m_managedObject =
+ factory.createJ2EEDomain(this, "domain", "scanner");
+ // DeploymentScanner is an event provider. m_managedObject performs
+ // a call-back in order to provide an event provider instrumentation
+ // to it. More accurately, m_managedObject calls
+ // InstrumentationHook.setEventProviderInst() on this instance.
+ m_managedObject.setEventProvider(true);
+
+ // DeploymentScanner is a state manageable class. m_managedObject
+ // performs a call-back in order to get a StateManageableInst view of
+ // it. More accurately, m_managedObject calls
+ // InstrumentationHook.getStateManageableInst() on this instance.
+ m_managedObject.setStateManageable(true);
+ }
+
+ public StateManageableInst getStateManageableInst() {
+ return new StateManageableAdapter(this);
+ }
+
+ /**
+ * Adapter of the inner working of the Deployment scanner in order to
+ * provide a state manageable instrumentation to the J2EE managed object.
+ *
+ * @version $Revision$ $Date$
+ */
+ private static class StateManageableAdapter implements StateManageableInst{
+
+ DeploymentScanner m_adaptee;
+
+ public StateManageableAdapter(DeploymentScanner aDeploymentScanner) {
+ m_adaptee = aDeploymentScanner;
+ }
+
+ /**
+ * It is fortunate to have an inner working wich maps directly to the
+ * state manageable requirement: the instrumentation simply forwards
+ * the call to the component.
+ *
+ * However, in order to be able to plug the proposed JSR implementation
+ * on another container, this bridge can be really helpful.
+ */
+ public void start() throws Exception, IllegalStateException {
+ m_adaptee.start();
+ }
+
+ public void startRecursive() throws Exception, IllegalStateException {
+ m_adaptee.startRecursive();
+ }
+
+ public void stop() throws Exception, IllegalStateException {
+ m_adaptee.stop();
+ }
+
+ public void execute(Method aMethod, Object[] aParamArray) {
+ }
+
+ }
+
}
