You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by va...@apache.org on 2008/01/23 23:33:30 UTC

svn commit: r614716 - in /ode/trunk: bpel-runtime/src/main/java/org/apache/ode/bpel/engine/ProcessAndInstanceManagementMBean.java jbi/src/main/java/org/apache/ode/jbi/OdeLifeCycle.java

Author: vanto
Date: Wed Jan 23 14:33:28 2008
New Revision: 614716

URL: http://svn.apache.org/viewvc?rev=614716&view=rev
Log:
ODE-82: Register PM API with JMX when Ode is deployed in JBI container

Added:
    ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/ProcessAndInstanceManagementMBean.java
Modified:
    ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeLifeCycle.java

Added: ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/ProcessAndInstanceManagementMBean.java
URL: http://svn.apache.org/viewvc/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/ProcessAndInstanceManagementMBean.java?rev=614716&view=auto
==============================================================================
--- ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/ProcessAndInstanceManagementMBean.java (added)
+++ ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/ProcessAndInstanceManagementMBean.java Wed Jan 23 14:33:28 2008
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ode.bpel.engine;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+
+import javax.management.Attribute;
+import javax.management.AttributeList;
+import javax.management.AttributeNotFoundException;
+import javax.management.DynamicMBean;
+import javax.management.InvalidAttributeValueException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanConstructorInfo;
+import javax.management.MBeanException;
+import javax.management.MBeanInfo;
+import javax.management.MBeanNotificationInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.ReflectionException;
+
+import org.apache.ode.bpel.iapi.BpelServer;
+import org.apache.ode.bpel.iapi.ProcessStore;
+
+
+/**
+ * Standard MBean exposing ODE's process model and instance management API
+ * 
+ * @author Tammo van Lessen (University of Stuttgart)
+ */
+public class ProcessAndInstanceManagementMBean implements DynamicMBean {
+
+	private MBeanInfo _mbeanInfo;
+	private ProcessAndInstanceManagementImpl _pm;
+	
+	private static final List<String> __excludes = new ArrayList<String>();
+		static {
+		__excludes.add("hashCode");
+		__excludes.add("equals");
+		__excludes.add("getClass");
+		__excludes.add("wait");
+		__excludes.add("notify");
+		__excludes.add("notifyAll");
+		__excludes.add("toString");
+	}
+	
+	private final static Hashtable<String, Class<?>> primitives = new Hashtable<String, Class<?>>();
+	static {
+		primitives.put(Boolean.TYPE.toString(), Boolean.TYPE);
+		primitives.put(Character.TYPE.toString(), Character.TYPE);
+		primitives.put(Byte.TYPE.toString(), Byte.TYPE);
+		primitives.put(Short.TYPE.toString(), Short.TYPE);
+		primitives.put(Integer.TYPE.toString(), Integer.TYPE);
+		primitives.put(Long.TYPE.toString(), Long.TYPE);
+		primitives.put(Float.TYPE.toString(), Float.TYPE);
+		primitives.put(Double.TYPE.toString(), Double.TYPE);
+	}
+	
+	public ProcessAndInstanceManagementMBean(BpelServer server, ProcessStore store) {
+		this(new ProcessAndInstanceManagementImpl(server, store));
+	}
+	
+	/**
+	 */
+	public ProcessAndInstanceManagementMBean(ProcessAndInstanceManagementImpl pm) {
+		_pm = pm;
+		List<MBeanOperationInfo> exposedOperations = new ArrayList<MBeanOperationInfo>();
+		for (Method m : pm.getClass().getMethods()) {
+			if (!__excludes.contains(m.getName())) {
+				exposedOperations.add(new MBeanOperationInfo(m.getName(), m));
+			}
+		}
+
+		MBeanAttributeInfo[] attributes = new MBeanAttributeInfo[] {};
+		MBeanConstructorInfo[] constructors = new MBeanConstructorInfo[] {};
+		MBeanOperationInfo[] operations = new MBeanOperationInfo[exposedOperations.size()];
+		operations = (MBeanOperationInfo[]) exposedOperations.toArray(operations);
+		MBeanNotificationInfo[] notifications = new MBeanNotificationInfo[] {};
+		
+		_mbeanInfo = new MBeanInfo(getClass().getName(), "Process and Instance Management", 
+				attributes, constructors, operations, notifications);
+	}
+	
+	public Object getAttribute(String attribute)
+			throws AttributeNotFoundException, MBeanException,
+			ReflectionException {
+		throw new UnsupportedOperationException();
+	}
+
+	public AttributeList getAttributes(String[] attributes) {
+		throw new UnsupportedOperationException();
+	}
+
+	public MBeanInfo getMBeanInfo() {
+		return _mbeanInfo;
+	}
+
+	public Object invoke(String actionName, Object[] params, String[] signature)
+			throws MBeanException, ReflectionException {
+		try {
+			Method m = _pm.getClass().getMethod(actionName, findTypes(_pm.getClass().getClassLoader(), signature));
+			if (m == null) {
+				throw new ReflectionException(new NoSuchMethodException(actionName));
+			}
+			return m.invoke(_pm, params);
+		} catch (Exception e) {
+			throw new ReflectionException(e);
+		}
+	}
+
+	private Class[] findTypes(ClassLoader loader, String[] signature) throws ReflectionException {
+		if (signature == null)
+			return null;
+		final Class[] result = new Class[signature.length];
+		try {
+			for (int i = 0; i < signature.length; i++) {
+				result[i] = primitives.get(signature[i]);
+				if (result[i] == null) {
+					result[i] = Class.forName(signature[i], false, loader);
+				}
+			}
+		} catch (ClassNotFoundException e) {
+			throw new ReflectionException(e);
+		}
+		return result;
+	}
+	
+	public void setAttribute(Attribute attribute)
+			throws AttributeNotFoundException, InvalidAttributeValueException,
+			MBeanException, ReflectionException {
+		throw new UnsupportedOperationException();
+		
+	}
+
+	public AttributeList setAttributes(AttributeList attributes) {
+		throw new UnsupportedOperationException();
+	}
+
+}

Modified: ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeLifeCycle.java
URL: http://svn.apache.org/viewvc/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeLifeCycle.java?rev=614716&r1=614715&r2=614716&view=diff
==============================================================================
--- ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeLifeCycle.java (original)
+++ ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeLifeCycle.java Wed Jan 23 14:33:28 2008
@@ -23,13 +23,13 @@
 import java.io.FileNotFoundException;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.StringTokenizer;
 import java.util.concurrent.Executors;
 
 import javax.jbi.JBIException;
 import javax.jbi.component.ComponentContext;
 import javax.jbi.component.ComponentLifeCycle;
 import javax.jbi.component.ServiceUnitManager;
+import javax.management.MBeanServer;
 import javax.management.ObjectName;
 import javax.naming.InitialContext;
 import javax.transaction.TransactionManager;
@@ -41,6 +41,8 @@
 import org.apache.ode.bpel.connector.BpelServerConnector;
 import org.apache.ode.bpel.dao.BpelDAOConnectionFactoryJDBC;
 import org.apache.ode.bpel.engine.BpelServerImpl;
+import org.apache.ode.bpel.engine.ProcessAndInstanceManagementMBean;
+import org.apache.ode.bpel.engine.ProcessAndInstanceManagementImpl;
 import org.apache.ode.bpel.evtproc.DebugBpelEventListener;
 import org.apache.ode.bpel.iapi.BpelEventListener;
 import org.apache.ode.bpel.intercept.MessageExchangeInterceptor;
@@ -76,6 +78,8 @@
     private BpelServerConnector _connector;
 
     private Database _db;
+    
+    private ObjectName _mbeanName;
 
     ServiceUnitManager getSUManager() {
         return _suManager;
@@ -86,7 +90,7 @@
     }
 
     public ObjectName getExtensionMBeanName() {
-        return null;
+        return _mbeanName;
     }
 
     public void init(ComponentContext context) throws JBIException {
@@ -122,6 +126,8 @@
             registerMexInterceptors();
             
             registerExtensionActivityBundles();
+            
+            registerMBean();
 
             __log.debug("Starting JCA connector.");
             initConnector();
@@ -266,12 +272,41 @@
         }
     }
 
+    private void registerMBean() throws JBIException {
+    	ProcessAndInstanceManagementMBean pmapi = new ProcessAndInstanceManagementMBean(_ode._server,_ode._store);
+        MBeanServer server = _ode.getContext().getMBeanServer();
+        try {
+	        if (server != null) {
+	            _mbeanName = _ode.getContext().getMBeanNames().createCustomComponentMBeanName("Management");
+	            if (server.isRegistered(_mbeanName)) {
+	                server.unregisterMBean(_mbeanName);
+	            }
+	            server.registerMBean(pmapi, _mbeanName);
+	        }
+        } catch (Exception e) {
+        	throw new JBIException(e);
+        }
+    }
+    
+    private void unregisterMBean() throws JBIException {
+    	try {
+    		if (_mbeanName != null) {
+	            MBeanServer server = _ode.getContext().getMBeanServer();
+	            assert server != null;
+	            if (server.isRegistered(_mbeanName)) {
+	                server.unregisterMBean(_mbeanName);
+	            }
+	        }
+	    } catch (Exception e) {
+	    	throw new JBIException(e);
+	    }
+    }
+    
     private void registerEventListeners() {
         String listenersStr = _ode._config.getEventListeners();
         if (listenersStr != null) {
-            for (StringTokenizer tokenizer = new StringTokenizer(listenersStr, ",;"); tokenizer.hasMoreTokens();) {
-                String listenerCN = tokenizer.nextToken();
-                try {
+            for (String listenerCN : listenersStr.split("\\s*(,|;)\\s*")) {
+            	try {
                     _ode._server.registerBpelEventListener((BpelEventListener) Class.forName(listenerCN).newInstance());
                     __log.info(__msgs.msgBpelEventListenerRegistered(listenerCN));
                 } catch (Exception e) {
@@ -285,9 +320,8 @@
     private void registerMexInterceptors() {
         String listenersStr = _ode._config.getMessageExchangeInterceptors();
         if (listenersStr != null) {
-            for (StringTokenizer tokenizer = new StringTokenizer(listenersStr, ",;"); tokenizer.hasMoreTokens();) {
-                String interceptorCN = tokenizer.nextToken();
-                try {
+            for (String interceptorCN : listenersStr.split("\\s*(,|;)\\s*")) {
+            	try {
                     _ode._server.registerMessageExchangeInterceptor((MessageExchangeInterceptor) Class.forName(interceptorCN).newInstance());
                     __log.info(__msgs.msgMessageExchangeInterceptorRegistered(interceptorCN));
                 } catch (Exception e) {
@@ -303,9 +337,8 @@
         if (extensionsStr != null) {
         	Map<QName, ExtensionValidator> validators = new HashMap<QName, ExtensionValidator>();
         	// TODO replace StringTokenizer by regex
-        	for (StringTokenizer tokenizer = new StringTokenizer(extensionsStr, ",;"); tokenizer.hasMoreTokens();) {
-                String bundleCN = tokenizer.nextToken();
-                try {
+            for (String bundleCN : extensionsStr.split("\\s*(,|;)\\s*")) {
+            	try {
                 	// instantiate bundle
                 	AbstractExtensionBundle bundle = (AbstractExtensionBundle) Class.forName(bundleCN).newInstance();
                 	
@@ -406,6 +439,8 @@
     public void shutDown() throws JBIException {
         ClassLoader old = Thread.currentThread().getContextClassLoader();
         Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+        
+        unregisterMBean();
 
         if (_connector != null) {
             try {