[jboss-svn-commits] JBL Code SVN: r12961 - labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/lifecycle.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sat Jun 30 10:24:00 EDT 2007


Author: tcunning
Date: 2007-06-30 10:24:00 -0400 (Sat, 30 Jun 2007)
New Revision: 12961

Added:
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/lifecycle/LifecycleController.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/lifecycle/LifecycleControllerMBean.java
Modified:
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/lifecycle/AbstractManagedLifecycle.java
Log:
bug:JBESB-544
Commit gateway/listener controller.


Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/lifecycle/AbstractManagedLifecycle.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/lifecycle/AbstractManagedLifecycle.java	2007-06-30 08:48:04 UTC (rev 12960)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/lifecycle/AbstractManagedLifecycle.java	2007-06-30 14:24:00 UTC (rev 12961)
@@ -106,6 +106,9 @@
         }
 
         this.config = config;
+        
+        LifecycleController lc = new LifecycleController(this, config);
+        lc.registerMBean();
     }
     
     /**
@@ -119,9 +122,9 @@
     public final void initialise()
     	throws ManagedLifecycleException
     {
-	changeState(ManagedLifecycleState.INITIALISING) ;
-	try
-	{
+		changeState(ManagedLifecycleState.INITIALISING) ;
+		try
+		{
             doInitialise() ;
             changeState(ManagedLifecycleState.INITIALISED) ;
         }
@@ -155,7 +158,7 @@
     public final void start()
     	throws ManagedLifecycleException
     {
-	changeState(ManagedLifecycleState.STARTING) ;
+    	changeState(ManagedLifecycleState.STARTING) ;
         try
         {
             doStart() ;
@@ -194,7 +197,7 @@
     public final void stop()
     	throws ManagedLifecycleException
     {
-	changeState(ManagedLifecycleState.STOPPING) ;
+    	changeState(ManagedLifecycleState.STOPPING) ;
         try
         {
             doStop() ;
@@ -232,7 +235,7 @@
     public final void destroy()
     	throws ManagedLifecycleException
     {
-	changeState(ManagedLifecycleState.DESTROYING) ;
+    	changeState(ManagedLifecycleState.DESTROYING) ;
         try
         {
             doDestroy() ;

Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/lifecycle/LifecycleController.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/lifecycle/LifecycleController.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/lifecycle/LifecycleController.java	2007-06-30 14:24:00 UTC (rev 12961)
@@ -0,0 +1,288 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.listeners.lifecycle;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import javax.management.Attribute;
+import javax.management.AttributeList;
+import javax.management.AttributeNotFoundException;
+import javax.management.DynamicMBean;
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.InstanceNotFoundException;
+import javax.management.InvalidAttributeValueException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanException;
+import javax.management.MBeanInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.MBeanRegistrationException;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.NotCompliantMBeanException;
+import javax.management.ObjectName;
+import javax.management.ReflectionException;
+
+import org.jboss.mx.util.MBeanServerLocator;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
+
+/**
+ * LifecycleController is an MBean implementation that 
+ *
+ * @author <a href="mailto:tcunning at redhat.com">tcunning at redhat.com</a>
+ */
+public class LifecycleController implements DynamicMBean {
+	private ManagedLifecycle m_lifecycle;
+	private ConfigTree m_config;
+	
+	/**
+	 * Constructor using lifecycle and config tree.
+	 * @param f_lifecycle lifecycle
+	 * @param f_configtree config tree
+	 */
+	public LifecycleController(ManagedLifecycle f_lifecycle, ConfigTree f_configtree) {
+		m_lifecycle = f_lifecycle;
+		m_config = f_configtree;
+	}
+
+	/**
+	 * Lifecycle mutator.
+	 * @param f_aml lifecycle
+	 */
+	public void setLifecycle(ManagedLifecycle f_aml) {
+		m_lifecycle = f_aml;
+	}
+
+	/**
+	 * ConfigTree mutator.
+	 * @param f_ct config tree
+	 */
+	public void setConfigTree(ConfigTree f_ct) {
+		m_config = f_ct;
+	}
+	
+	/**
+	 * Calls destroy on the lifecycle.
+	 */
+	public void destroy() throws ManagedLifecycleException {
+		m_lifecycle.destroy();
+	}
+
+	/**
+	 * Calls initialise on the lifecycle.
+	 */
+	public void initialise() throws ManagedLifecycleException {
+		m_lifecycle.initialise();
+	}
+
+	/**
+	 * Calls start on the lifecycle. 
+	 */
+	public void start() throws ManagedLifecycleException {
+		m_lifecycle.start();
+	}
+
+	/**
+	 * Calls stop on the lifecycle.
+	 */
+	public void stop() throws ManagedLifecycleException {
+		m_lifecycle.stop();
+	}
+		
+	/**
+	 * Register this MBean with JBoss.
+	 */
+	protected void registerMBean() {
+		MBeanServer mbeanServer = MBeanServerLocator.locateJBoss();
+		ObjectName listObjectName = null;
+		try {
+			String name = m_config.getName();
+
+			String serviceName = m_config.getAttribute(ListenerTagNames.SERVICE_NAME_TAG);
+			String targetName = m_config.getAttribute(ListenerTagNames.TARGET_SERVICE_NAME_TAG);
+			if (serviceName != null) {
+				listObjectName = new ObjectName("jboss.esb:name=" + name 
+						+ "," + ListenerTagNames.SERVICE_NAME_TAG + "=" + serviceName);
+			} else if (targetName != null) {
+				listObjectName = new ObjectName("jboss.esb:name=" + name
+						+ "," + ListenerTagNames.TARGET_SERVICE_NAME_TAG + "=" + targetName );				
+			} else {
+				listObjectName = new ObjectName("jboss.esb:name=" + name);
+			}
+		} catch (MalformedObjectNameException e1) {
+			e1.printStackTrace();
+		} catch (NullPointerException e1) {
+			e1.printStackTrace();
+		}
+		
+		if (mbeanServer.isRegistered(listObjectName)) {
+	    	try {
+	    		mbeanServer.unregisterMBean(listObjectName);
+			} catch (InstanceNotFoundException e) {
+				e.printStackTrace();
+			} catch (MBeanRegistrationException e) {
+				e.printStackTrace();
+			}
+        }
+		
+	    try {
+	    	mbeanServer.registerMBean(this, listObjectName);
+		} catch (InstanceAlreadyExistsException e) {
+			e.printStackTrace();
+		} catch (MBeanRegistrationException e) {
+			e.printStackTrace();
+		} catch (NotCompliantMBeanException e) {
+			e.printStackTrace();
+		}
+	}
+
+	/**
+	 * Gets the list of attributes.    We return all Lifecycle attributes from 
+	 */
+	public AttributeList getAttributes(String[] arg0) {
+		AttributeList attributeList = new AttributeList();
+		Set<String> set = m_config.getAttributeNames();		
+		String[] attribs = (String[])set.toArray(new String[set.size()]);
+		for (int i = 0; i < attribs.length; i++) {
+			Attribute at = new Attribute(attribs[i], m_config.getAttribute(attribs[i]));
+			attributeList.add(at);
+		}
+		
+		// Add lifecycle state to the list of properties
+		Attribute lifecycleState = new Attribute("LifecycleState", m_lifecycle.getState().toString());
+		attributeList.add(lifecycleState);
+		
+		return attributeList;
+	}
+
+	/**
+	 * Gets the attribute value.   
+	 */
+    public synchronized String getAttribute(String name) throws AttributeNotFoundException {
+    	String value = null;
+    	if (name.equals("LifecycleState")) {
+        	value = m_lifecycle.getState().toString();
+        } else {
+        	value = m_config.getAttribute(name);
+        }
+        if (value != null)
+            return value;
+        else
+            throw new AttributeNotFoundException("No such property: " + name);
+    }
+	
+	/**
+	 *  This creates the MBeanInfo object provided.     We are returning generic 
+	 *  text for the attribute descriptions (the word Property and the name of the 
+	 *  attribute), all of the attributes are read-only, and we provide four 
+	 *  invocation methods - start/stop/initialise/destroy on the Lifecycle. 
+	 */
+    public MBeanInfo getMBeanInfo() {
+		SortedSet<String> names = new TreeSet<String>();
+        for (Object name : m_config.getAttributeNames())
+            names.add((String) name);
+        names.add("LifecycleState");
+        MBeanAttributeInfo[] attrs = new MBeanAttributeInfo[names.size()];
+        Iterator<String> it = names.iterator();
+        for (int i = 0; i < attrs.length; i++) {
+            String name = it.next();
+            attrs[i] = new MBeanAttributeInfo(
+                    name, "java.lang.String", "Property " + name, true, false, false);
+        }
+        MBeanOperationInfo[] opers = {
+            new MBeanOperationInfo(
+            		"start", "Start the lifecycle",
+                    null, "void", MBeanOperationInfo.ACTION),
+            new MBeanOperationInfo(
+                    "initialise", "Initialise the lifecycle",
+                    null, "void", MBeanOperationInfo.ACTION),
+            new MBeanOperationInfo(
+            		"stop", "Stop the lifecycle",
+                    null, "void", MBeanOperationInfo.ACTION),
+            new MBeanOperationInfo(
+            		"destroy", "Destroy the lifecycle",
+                    null, "void", MBeanOperationInfo.ACTION),
+        };
+        return new MBeanInfo(
+                this.getClass().getName(), "Lifecycle Controller MBean",
+                attrs, null, opers, null); // notifications
+	}
+
+    /**
+     * Invoke calls the four operations provided by the LifecycleController - 
+     * initialise, start, stop, destroy.    If one of the operation methods fails,
+     * we throw the exception, and if an unknown operation is called, we throw
+     * an exception.
+     */
+	public Object invoke(String method, Object[] arg1, String[] arg2) throws MBeanException, ReflectionException {
+		if (method.equalsIgnoreCase("start")) {
+			try {
+				start();
+			} catch (ManagedLifecycleException e) {
+				throw new MBeanException(e);
+			}
+			return "Invoking the " + method + " on the lifecycle.";
+		} else if (method.equalsIgnoreCase("initialise")) {
+			try {
+				initialise();
+			} catch (ManagedLifecycleException e) {
+				throw new MBeanException(e);
+			}
+			return "Invoking the " + method + " on the lifecycle.";
+		} else if (method.equalsIgnoreCase("stop")) {
+			try {
+				stop();
+			} catch (ManagedLifecycleException e) {
+				throw new MBeanException(e);
+			}
+			return "Invoking the " + method + " on the lifecycle.";
+		} else if (method.equalsIgnoreCase("destroy")) {
+			try {
+				destroy();
+			} catch (ManagedLifecycleException e) {
+				throw new MBeanException(e);
+			}
+			return "Invoking the " + method + " on the lifecycle.";
+		} else {
+			throw new ReflectionException(new NoSuchMethodException(method));
+		}
+	}
+
+	/**
+	 * This method is here to implement the DynamicMBean interface in full, but it is
+	 * not used because all of the attributes provided are read-only.
+	 */
+	public void setAttribute(Attribute arg0) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
+	}
+
+	/**
+	 * This method is here to implement the DynamicMBean interface in full, but it is
+	 * not used because all of the attributes provided are read-only.
+	 */
+	public AttributeList setAttributes(AttributeList arg0) {
+		// TODO Auto-generated method stub
+		return null;
+	}	
+}

Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/lifecycle/LifecycleControllerMBean.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/lifecycle/LifecycleControllerMBean.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/lifecycle/LifecycleControllerMBean.java	2007-06-30 14:24:00 UTC (rev 12961)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.listeners.lifecycle;
+
+/**
+ * LifecycleControllerMBean is an MBean that monitors lifecycle state and allows
+ * management of the lifeycle state. 
+ *
+ * @author <a href="mailto:tcunning at redhat.com">tcunning at redhat.com</a>
+ */
+public interface LifecycleControllerMBean {
+	
+	public void initialise() throws ManagedLifecycleException;
+	public void start() throws ManagedLifecycleException;
+	public void stop() throws ManagedLifecycleException;
+	public void destroy() throws ManagedLifecycleException;
+}




More information about the jboss-svn-commits mailing list