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/05/23 23:46:58 UTC
svn commit: r659674 - in /ode/branches/APACHE_ODE_1.1:
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: Fri May 23 14:46:57 2008
New Revision: 659674
URL: http://svn.apache.org/viewvc?rev=659674&view=rev
Log:
ODE-82: Register PM API with JMX when Ode is deployed in JBI container
Added:
ode/branches/APACHE_ODE_1.1/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/ProcessAndInstanceManagementMBean.java
Modified:
ode/branches/APACHE_ODE_1.1/jbi/src/main/java/org/apache/ode/jbi/OdeLifeCycle.java
Added: ode/branches/APACHE_ODE_1.1/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/ProcessAndInstanceManagementMBean.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.1/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/ProcessAndInstanceManagementMBean.java?rev=659674&view=auto
==============================================================================
--- ode/branches/APACHE_ODE_1.1/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/ProcessAndInstanceManagementMBean.java (added)
+++ ode/branches/APACHE_ODE_1.1/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/ProcessAndInstanceManagementMBean.java Fri May 23 14:46:57 2008
@@ -0,0 +1,155 @@
+/*
+ * 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/branches/APACHE_ODE_1.1/jbi/src/main/java/org/apache/ode/jbi/OdeLifeCycle.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.1/jbi/src/main/java/org/apache/ode/jbi/OdeLifeCycle.java?rev=659674&r1=659673&r2=659674&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.1/jbi/src/main/java/org/apache/ode/jbi/OdeLifeCycle.java (original)
+++ ode/branches/APACHE_ODE_1.1/jbi/src/main/java/org/apache/ode/jbi/OdeLifeCycle.java Fri May 23 14:46:57 2008
@@ -21,13 +21,15 @@
import java.io.File;
import java.io.FileNotFoundException;
-import java.util.StringTokenizer;
+import java.util.HashMap;
+import java.util.Map;
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.transaction.TransactionManager;
@@ -36,6 +38,9 @@
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.iapi.BpelEventListener;
import org.apache.ode.bpel.intercept.MessageExchangeInterceptor;
import org.apache.ode.il.dbutil.Database;
@@ -70,6 +75,8 @@
private Database _db;
+ private ObjectName _mbeanName;
+
ServiceUnitManager getSUManager() {
return _suManager;
}
@@ -79,7 +86,7 @@
}
public ObjectName getExtensionMBeanName() {
- return null;
+ return _mbeanName;
}
public void init(ComponentContext context) throws JBIException {
@@ -118,6 +125,8 @@
registerMexInterceptors();
+ registerMBean();
+
__log.debug("Starting JCA connector.");
initConnector();
@@ -264,11 +273,40 @@
}
}
+ 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();
+ for (String listenerCN : listenersStr.split("\\s*(,|;)\\s*")) {
try {
_ode._server.registerBpelEventListener((BpelEventListener) Class.forName(listenerCN).newInstance());
__log.info(__msgs.msgBpelEventListenerRegistered(listenerCN));
@@ -283,8 +321,7 @@
private void registerMexInterceptors() {
String listenersStr = _ode._config.getMessageExchangeInterceptors();
if (listenersStr != null) {
- for (StringTokenizer tokenizer = new StringTokenizer(listenersStr, ",;"); tokenizer.hasMoreTokens();) {
- String interceptorCN = tokenizer.nextToken();
+ for (String interceptorCN : listenersStr.split("\\s*(,|;)\\s*")) {
try {
_ode._server.registerMessageExchangeInterceptor((MessageExchangeInterceptor) Class.forName(interceptorCN).newInstance());
__log.info(__msgs.msgMessageExchangeInterceptorRegistered(interceptorCN));
@@ -379,6 +416,8 @@
ClassLoader old = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+ unregisterMBean();
+
_ode.deactivatePMAPIs();
if (_connector != null) {