[jboss-cvs] JBossAS SVN: r77027 - in trunk/varia/src: resources/jmx/examples/mbean-configurator-service and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Aug 13 15:02:27 EDT 2008
Author: bstansberry at jboss.com
Date: 2008-08-13 15:02:27 -0400 (Wed, 13 Aug 2008)
New Revision: 77027
Added:
trunk/varia/src/main/org/jboss/jmx/examples/configuration/MBeanConfiguratorSupport.java
trunk/varia/src/main/org/jboss/jmx/examples/configuration/MBeanConfiguratorSupportMBean.java
trunk/varia/src/main/org/jboss/jmx/examples/configuration/SampleMBeanConfigurator.java
trunk/varia/src/main/org/jboss/jmx/examples/configuration/SampleMBeanConfiguratorMBean.java
Removed:
trunk/varia/src/main/org/jboss/jmx/examples/configuration/MBeanConfigurator.java
trunk/varia/src/main/org/jboss/jmx/examples/configuration/MBeanConfiguratorMBean.java
trunk/varia/src/resources/jmx/examples/mbean-configurator-service/sample-binding.xml
Modified:
trunk/varia/src/main/org/jboss/jmx/examples/configuration/SampleService.java
trunk/varia/src/resources/jmx/examples/mbean-configurator-service/META-INF/jboss-service.xml
Log:
[JBAS-5192] Convert MBeanConfigurator to deal with new SBM concept
Deleted: trunk/varia/src/main/org/jboss/jmx/examples/configuration/MBeanConfigurator.java
===================================================================
--- trunk/varia/src/main/org/jboss/jmx/examples/configuration/MBeanConfigurator.java 2008-08-13 18:33:34 UTC (rev 77026)
+++ trunk/varia/src/main/org/jboss/jmx/examples/configuration/MBeanConfigurator.java 2008-08-13 19:02:27 UTC (rev 77027)
@@ -1,129 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, 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.jmx.examples.configuration;
-
-import org.jboss.logging.Logger;
-import org.jboss.system.ServiceMBeanSupport;
-
-import javax.management.*;
-import java.io.Serializable;
-
-/**
- * @author <a href="mailto:tom at jboss.org">Tom Elrod</a>
- */
-public class MBeanConfigurator extends ServiceMBeanSupport implements MBeanConfiguratorMBean, NotificationListener
-{
-
- private static final Logger log = Logger.getLogger(MBeanConfigurator.class.getName());
-
- /**
- * Use the short class name as the default for the service name.
- */
- public String getName()
- {
- return "MBeanConfigurator";
- }
-
- public void startService()
- {
- try
- {
- log.debug("Starting MBeanConfigurator service.");
- ObjectName mbeanserver = new ObjectName("JMImplementation:type=MBeanServerDelegate");
- RegistrationNotificationFilter mbeanServerNotificationFilter = new RegistrationNotificationFilter();
- getServer().addNotificationListener(mbeanserver, this, mbeanServerNotificationFilter, null);
- }
- catch (Exception e)
- {
- log.error("Could not start MBeanConfigurator service.", e);
- }
- }
-
-
- public void mbeanRegistered(ObjectName objectName)
- throws ReflectionException, InstanceNotFoundException, MBeanException, MalformedObjectNameException
- {
- log.debug("MBean " + objectName + " registered. Will see if any attribute bindings present.");
- // Hard coded for now. We need someplace for standard service names...
- ObjectName serviceBindingMgr = new ObjectName("jboss.system:service=ServiceBindingManager");
- Object[] args = {objectName};
- String[] sig = {"javax.management.ObjectName"};
- MBeanServer server = getServer();
- if(server != null)
- {
- server.invoke(serviceBindingMgr, "applyServiceConfig", args, sig);
- }
- }
-
- /**
- * Callback method from the broadcaster MBean this listener implementation
- * is registered to.
- *
- * @param notification the notification object
- * @param handback the handback object given to the broadcaster
- * upon listener registration
- */
- public void handleNotification(Notification notification, Object handback)
- {
- //Should be a mbean registration notification due to RegistrationNotificationFilter being used.
- if (notification instanceof MBeanServerNotification)
- {
- if (notification.getType().equals(MBeanServerNotification.REGISTRATION_NOTIFICATION))
- {
- MBeanServerNotification serverNotification = (MBeanServerNotification) notification;
- try
- {
- mbeanRegistered(serverNotification.getMBeanName());
- }
- catch (Exception e)
- {
- log.error("Error configuring mbean " + serverNotification.getMBeanName(), e);
- }
- }
- }
-
- }
-
- public class RegistrationNotificationFilter implements NotificationFilter, Serializable
- {
-
- /**
- * This method is called before a notification is sent to see whether
- * the listener wants the notification.
- *
- * @param notification the notification to be sent.
- * @return true if the listener wants the notification, false otherwise
- */
- public boolean isNotificationEnabled(Notification notification)
- {
- boolean processNotification = false;
- if (notification instanceof MBeanServerNotification)
- {
- if (notification.getType().equals(MBeanServerNotification.REGISTRATION_NOTIFICATION))
- {
- processNotification = true;
- }
- }
- return processNotification;
- }
- }
-}
\ No newline at end of file
Deleted: trunk/varia/src/main/org/jboss/jmx/examples/configuration/MBeanConfiguratorMBean.java
===================================================================
--- trunk/varia/src/main/org/jboss/jmx/examples/configuration/MBeanConfiguratorMBean.java 2008-08-13 18:33:34 UTC (rev 77026)
+++ trunk/varia/src/main/org/jboss/jmx/examples/configuration/MBeanConfiguratorMBean.java 2008-08-13 19:02:27 UTC (rev 77027)
@@ -1,43 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, 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.jmx.examples.configuration;
-
-import org.jboss.system.ServiceMBean;
-
-import javax.management.*;
-
-/**
- * @author <a href="mailto:telrod at e2technologies.net">Tom Elrod</a>
- */
-public interface MBeanConfiguratorMBean extends ServiceMBean
-{
- /**
- * Indicates that an new mbean has been registered with the
- * MBeanServer and thus need to set any attributes from
- * service binding manager if they exist.
- *
- * @param objectName
- */
- public void mbeanRegistered(ObjectName objectName)
- throws ReflectionException, InstanceNotFoundException, MBeanException, MalformedObjectNameException;
-
-}
Copied: trunk/varia/src/main/org/jboss/jmx/examples/configuration/MBeanConfiguratorSupport.java (from rev 77011, trunk/varia/src/main/org/jboss/jmx/examples/configuration/MBeanConfigurator.java)
===================================================================
--- trunk/varia/src/main/org/jboss/jmx/examples/configuration/MBeanConfiguratorSupport.java (rev 0)
+++ trunk/varia/src/main/org/jboss/jmx/examples/configuration/MBeanConfiguratorSupport.java 2008-08-13 19:02:27 UTC (rev 77027)
@@ -0,0 +1,138 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.jmx.examples.configuration;
+
+import java.io.Serializable;
+
+import javax.management.MBeanServerNotification;
+import javax.management.Notification;
+import javax.management.NotificationFilter;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+
+import org.jboss.logging.Logger;
+import org.jboss.services.binding.ServiceBindingManager;
+import org.jboss.services.binding.ServiceBindingManagerMBean;
+import org.jboss.system.ServiceMBeanSupport;
+
+/**
+ * @author <a href="mailto:tom at jboss.org">Tom Elrod</a>
+ * @author Brian Stansberry
+ */
+public abstract class MBeanConfiguratorSupport extends ServiceMBeanSupport
+ implements MBeanConfiguratorSupportMBean, NotificationListener
+{
+
+ private static final Logger log = Logger.getLogger(MBeanConfiguratorSupport.class.getName());
+
+ private ServiceBindingManager serviceBindingManager;
+
+ /**
+ * Use the short class name as the default for the service name.
+ */
+ public String getName()
+ {
+ return "MBeanConfiguratorSupport";
+ }
+
+ public void startService()
+ {
+ try
+ {
+ log.debug("Starting MBeanConfiguratorSupport service.");
+
+ ObjectName mbeanserver = new ObjectName("JMImplementation:type=MBeanServerDelegate");
+ RegistrationNotificationFilter mbeanServerNotificationFilter = new RegistrationNotificationFilter();
+ getServer().addNotificationListener(mbeanserver, this, mbeanServerNotificationFilter, null);
+ }
+ catch (Exception e)
+ {
+ log.error("Could not start MBeanConfiguratorSupport service.", e);
+ }
+ }
+
+ public ServiceBindingManager getServiceBindingManager()
+ {
+ return serviceBindingManager;
+ }
+
+ public void setServiceBindingManager(ServiceBindingManager serviceBindingManager)
+ {
+ this.serviceBindingManager = serviceBindingManager;
+ }
+
+ public abstract void mbeanRegistered(ObjectName objectName)
+ throws Exception;
+
+ /**
+ * Callback method from the broadcaster MBean this listener implementation
+ * is registered to.
+ *
+ * @param notification the notification object
+ * @param handback the handback object given to the broadcaster
+ * upon listener registration
+ */
+ public void handleNotification(Notification notification, Object handback)
+ {
+ //Should be a mbean registration notification due to RegistrationNotificationFilter being used.
+ if (notification instanceof MBeanServerNotification)
+ {
+ if (notification.getType().equals(MBeanServerNotification.REGISTRATION_NOTIFICATION))
+ {
+ MBeanServerNotification serverNotification = (MBeanServerNotification) notification;
+ try
+ {
+ mbeanRegistered(serverNotification.getMBeanName());
+ }
+ catch (Exception e)
+ {
+ log.error("Error configuring mbean " + serverNotification.getMBeanName(), e);
+ }
+ }
+ }
+
+ }
+
+ public class RegistrationNotificationFilter implements NotificationFilter, Serializable
+ {
+
+ /**
+ * This method is called before a notification is sent to see whether
+ * the listener wants the notification.
+ *
+ * @param notification the notification to be sent.
+ * @return true if the listener wants the notification, false otherwise
+ */
+ public boolean isNotificationEnabled(Notification notification)
+ {
+ boolean processNotification = false;
+ if (notification instanceof MBeanServerNotification)
+ {
+ if (notification.getType().equals(MBeanServerNotification.REGISTRATION_NOTIFICATION))
+ {
+ processNotification = true;
+ }
+ }
+ return processNotification;
+ }
+ }
+}
\ No newline at end of file
Copied: trunk/varia/src/main/org/jboss/jmx/examples/configuration/MBeanConfiguratorSupportMBean.java (from rev 77011, trunk/varia/src/main/org/jboss/jmx/examples/configuration/MBeanConfiguratorMBean.java)
===================================================================
--- trunk/varia/src/main/org/jboss/jmx/examples/configuration/MBeanConfiguratorSupportMBean.java (rev 0)
+++ trunk/varia/src/main/org/jboss/jmx/examples/configuration/MBeanConfiguratorSupportMBean.java 2008-08-13 19:02:27 UTC (rev 77027)
@@ -0,0 +1,36 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.jmx.examples.configuration;
+
+import org.jboss.services.binding.ServiceBindingManager;
+import org.jboss.system.ServiceMBean;
+
+/**
+ * @author <a href="mailto:telrod at e2technologies.net">Tom Elrod</a>
+ */
+public interface MBeanConfiguratorSupportMBean extends ServiceMBean
+{
+ ServiceBindingManager getServiceBindingManager();
+
+ void setServiceBindingManager(ServiceBindingManager sbm);
+
+}
Added: trunk/varia/src/main/org/jboss/jmx/examples/configuration/SampleMBeanConfigurator.java
===================================================================
--- trunk/varia/src/main/org/jboss/jmx/examples/configuration/SampleMBeanConfigurator.java (rev 0)
+++ trunk/varia/src/main/org/jboss/jmx/examples/configuration/SampleMBeanConfigurator.java 2008-08-13 19:02:27 UTC (rev 77027)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.jmx.examples.configuration;
+
+import javax.management.Attribute;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+/**
+ * A SampleMBeanConfigurator.
+ *
+ * @author Brian Stansberry
+ * @version $Revision$
+ */
+public class SampleMBeanConfigurator extends MBeanConfiguratorSupport implements SampleMBeanConfiguratorMBean
+{
+ private ObjectName sampleServiceObjectName;
+
+ public ObjectName getSampleServiceObjectName()
+ {
+ return sampleServiceObjectName;
+ }
+
+ public void setSampleServiceObjectName(ObjectName sampleServiceObjectName)
+ {
+ this.sampleServiceObjectName = sampleServiceObjectName;
+ }
+
+
+ @Override
+ public void mbeanRegistered(ObjectName objectName) throws Exception
+ {
+ if (objectName.equals(sampleServiceObjectName))
+ {
+ String value = getServiceBindingManager().getStringBinding(objectName.getCanonicalName(), null, "socket://${host}:${port}", "localhost", 9999);
+ MBeanServer server = getServer();
+ server.setAttribute(objectName, new Attribute("TestAttribute", value));
+ }
+ }
+
+}
Added: trunk/varia/src/main/org/jboss/jmx/examples/configuration/SampleMBeanConfiguratorMBean.java
===================================================================
--- trunk/varia/src/main/org/jboss/jmx/examples/configuration/SampleMBeanConfiguratorMBean.java (rev 0)
+++ trunk/varia/src/main/org/jboss/jmx/examples/configuration/SampleMBeanConfiguratorMBean.java 2008-08-13 19:02:27 UTC (rev 77027)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.jmx.examples.configuration;
+
+import javax.management.ObjectName;
+
+/**
+ * StandardMBean interface for SampleMBeanConfigurator.
+ *
+ * @author Brian Stansberry
+ * @version $Revision$
+ */
+public interface SampleMBeanConfiguratorMBean extends MBeanConfiguratorSupportMBean
+{
+
+ public abstract ObjectName getSampleServiceObjectName();
+
+ public abstract void setSampleServiceObjectName(ObjectName sampleServiceObjectName);
+
+}
\ No newline at end of file
Modified: trunk/varia/src/main/org/jboss/jmx/examples/configuration/SampleService.java
===================================================================
--- trunk/varia/src/main/org/jboss/jmx/examples/configuration/SampleService.java 2008-08-13 18:33:34 UTC (rev 77026)
+++ trunk/varia/src/main/org/jboss/jmx/examples/configuration/SampleService.java 2008-08-13 19:02:27 UTC (rev 77027)
@@ -58,6 +58,12 @@
log.debug("SampleService:startService() called");
createSampleConfigMBean();
}
+
+ protected void stopService() throws Exception
+ {
+ ObjectName objname = new ObjectName("sample:name=SampleConfig");
+ getServer().unregisterMBean(objname);
+ }
public void createSampleConfigMBean()
throws MalformedObjectNameException, InstanceAlreadyExistsException, MBeanRegistrationException, javax.management.NotCompliantMBeanException
Modified: trunk/varia/src/resources/jmx/examples/mbean-configurator-service/META-INF/jboss-service.xml
===================================================================
--- trunk/varia/src/resources/jmx/examples/mbean-configurator-service/META-INF/jboss-service.xml 2008-08-13 18:33:34 UTC (rev 77026)
+++ trunk/varia/src/resources/jmx/examples/mbean-configurator-service/META-INF/jboss-service.xml 2008-08-13 19:02:27 UTC (rev 77027)
@@ -9,23 +9,14 @@
<!-- ===================================================================== -->
<server>
- <mbean code="org.jboss.jmx.examples.configuration.MBeanConfigurator"
+ <mbean code="org.jboss.jmx.examples.configuration.SampleMBeanConfigurator"
name="jboss.jmx:service=MBeanConfigurator">
- <depends>jboss.system:service=ServiceBindingManager</depends>
+
+ <attribute name="ServiceBindingManager"><inject bean="ServiceBindingManager"/></attribute>
+ <attribute name="SampleServiceObjectName">sample:name=SampleConfig</attribute>
+
</mbean>
-
- <!-- ServiceBindingManager required by MBeanConfigurator -->
- <!-- The StoreURL can be used for any mbean -->
- <mbean code="org.jboss.services.binding.ServiceBindingManager"
- name="jboss.system:service=ServiceBindingManager">
- <attribute name="ServerName">config-example</attribute>
- <attribute name="StoreURL">../docs/examples/jmx/mbean-configurator.sar/sample-binding.xml</attribute>
- <attribute name="StoreFactoryClassName">
- org.jboss.services.binding.XMLServicesStoreFactory
- </attribute>
- </mbean>
-
<!-- Sample service mbean whose only task is to create another -->
<!-- sample mbean (not a service) and register it with the -->
<!-- mbean server, which is referenced in the -->
Deleted: trunk/varia/src/resources/jmx/examples/mbean-configurator-service/sample-binding.xml
===================================================================
--- trunk/varia/src/resources/jmx/examples/mbean-configurator-service/sample-binding.xml 2008-08-13 18:33:34 UTC (rev 77026)
+++ trunk/varia/src/resources/jmx/examples/mbean-configurator-service/sample-binding.xml 2008-08-13 19:02:27 UTC (rev 77027)
@@ -1,21 +0,0 @@
-<!-- This is a sample binding for the MBean configurator example -->
-<!-- Will setup so sets attribute on SampleConfig mbean when it -->
-<!-- is registered with the MBeanServer (see SampleService to see -->
-<!-- How the SampleConfig mbean is created). Notice that when the -->
-<!-- SampleConfig mbean is first created, the default value for -->
-<!-- the testAttribute attribute is "Initial Value". This will be -->
-<!-- changed by the service binding below to "Changed Value". -->
-<service-bindings>
-
- <server name="config-example">
-
- <service-config name="sample:name=SampleConfig"
- delegateClass="org.jboss.services.binding.AttributeMappingDelegate"
- >
- <delegate-config>
- <attribute name="TestAttribute">Changed Value</attribute>
- </delegate-config>
- </service-config>
-
- </server>
-</service-bindings>
More information about the jboss-cvs-commits
mailing list