[jboss-cvs] JBossAS SVN: r96488 - in projects/kernel/trunk/jmx-mc-int/src/main/java/org/jboss/system: metadata and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Nov 18 09:10:52 EST 2009


Author: alesj
Date: 2009-11-18 09:10:51 -0500 (Wed, 18 Nov 2009)
New Revision: 96488

Modified:
   projects/kernel/trunk/jmx-mc-int/src/main/java/org/jboss/system/ServiceConfigurator.java
   projects/kernel/trunk/jmx-mc-int/src/main/java/org/jboss/system/metadata/ServiceAttributeMetaData.java
   projects/kernel/trunk/jmx-mc-int/src/main/java/org/jboss/system/microcontainer/ConfigureAction.java
Log:
[JBKERNEL-61]; unget on mbean attributes.


Modified: projects/kernel/trunk/jmx-mc-int/src/main/java/org/jboss/system/ServiceConfigurator.java
===================================================================
--- projects/kernel/trunk/jmx-mc-int/src/main/java/org/jboss/system/ServiceConfigurator.java	2009-11-18 12:59:59 UTC (rev 96487)
+++ projects/kernel/trunk/jmx-mc-int/src/main/java/org/jboss/system/ServiceConfigurator.java	2009-11-18 14:10:51 UTC (rev 96488)
@@ -64,7 +64,7 @@
  * @author <a href="mailto:jason at planet57.com">Jason Dillon</a>
  * @author <a href="mailto:dimitris at jboss.org">Dimitris Andreadis</a>
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version <tt>$Revision$</tt>
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
  */
 public class ServiceConfigurator
 {
@@ -115,6 +115,23 @@
    }
    
    /**
+    * Unconfigure an MBean
+    *
+    * @param server the server
+    * @param controller the service controller
+    * @param objectName the object name
+    * @param classLoaderName the classloader object name
+    * @param attrs the attributes
+    * @throws Exception for any error
+    */
+   public static void unconfigure(MBeanServer server, ServiceController controller, ObjectName objectName, ObjectName classLoaderName, Collection<ServiceAttributeMetaData> attrs) throws Exception
+   {
+      server = checkMBeanServer(server, controller);
+      ClassLoader cl = server.getClassLoader(classLoaderName);
+      unconfigure(server, controller, objectName, cl, attrs);
+   }
+
+   /**
     * Configure an MBean
     * 
     * @param server the server
@@ -173,6 +190,59 @@
    }
 
    /**
+    * Unconfigure an MBean
+    *
+    * @param server the server
+    * @param controller the service controller
+    * @param objectName the object name
+    * @param cl the classloader
+    * @param attrs the attributes
+    * @throws Exception for any error
+    */
+   public static void unconfigure(MBeanServer server, ServiceController controller, ObjectName objectName, ClassLoader cl, Collection<ServiceAttributeMetaData> attrs) throws Exception
+   {
+      ServiceValueContext valueContext = new ServiceValueContext(server, controller, cl);
+      server = checkMBeanServer(server, controller);
+
+      HashMap<String, MBeanAttributeInfo> attributeMap = getAttributeMap(server, objectName);
+
+      for (ServiceAttributeMetaData attribute : attrs)
+      {
+         String attributeName = attribute.getName();
+         if (attributeName == null || attributeName.length() == 0)
+            throw new RuntimeException("No or empty attribute name for " + objectName);
+         MBeanAttributeInfo attributeInfo = attributeMap.get(attributeName);
+         if (attributeInfo == null)
+         {
+            throw new RuntimeException("No Attribute found with name: " + attributeName + " for " + objectName
+                  +", attributes: "+attributeMap.keySet());
+         }
+
+         valueContext.setAttributeInfo(attributeInfo);
+         Object value = null;
+         ClassLoader previous = SecurityActions.setContextClassLoader(cl);
+         try
+         {
+            value = attribute.ungetValue(valueContext);
+         }
+         catch (Throwable ignored)
+         {
+         }
+         finally
+         {
+            SecurityActions.resetContextClassLoader(previous);
+         }
+         try
+         {
+            server.setAttribute(objectName, new Attribute(attributeName, value)); // check for primitives?
+         }
+         catch (Throwable ignored)
+         {
+         }
+      }
+   }
+
+   /**
     * Check the server/controller parameters
     * 
     * @param server the server

Modified: projects/kernel/trunk/jmx-mc-int/src/main/java/org/jboss/system/metadata/ServiceAttributeMetaData.java
===================================================================
--- projects/kernel/trunk/jmx-mc-int/src/main/java/org/jboss/system/metadata/ServiceAttributeMetaData.java	2009-11-18 12:59:59 UTC (rev 96487)
+++ projects/kernel/trunk/jmx-mc-int/src/main/java/org/jboss/system/metadata/ServiceAttributeMetaData.java	2009-11-18 14:10:51 UTC (rev 96488)
@@ -155,7 +155,13 @@
          throw ConfigurationException.rethrowAsConfigurationException("Error configuring attribute " + name, t);
       }
    }
-   
+
+   @Override
+   public Object ungetValue(ServiceValueContext valueContext) throws Throwable
+   {
+      return value.ungetValue(valueContext);
+   }
+
    public void visit(ServiceMetaDataVisitor visitor)
    {
       visitor.setContextState(ControllerState.CONFIGURED);

Modified: projects/kernel/trunk/jmx-mc-int/src/main/java/org/jboss/system/microcontainer/ConfigureAction.java
===================================================================
--- projects/kernel/trunk/jmx-mc-int/src/main/java/org/jboss/system/microcontainer/ConfigureAction.java	2009-11-18 12:59:59 UTC (rev 96487)
+++ projects/kernel/trunk/jmx-mc-int/src/main/java/org/jboss/system/microcontainer/ConfigureAction.java	2009-11-18 14:10:51 UTC (rev 96488)
@@ -39,7 +39,7 @@
  * 
  * @see ServiceControllerContextActions
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision$
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
  */
 public class ConfigureAction extends ServiceControllerContextAction
 {
@@ -50,13 +50,13 @@
     */
    public void installAction(ServiceControllerContext context) throws Throwable
    {
-      ServiceController controller = context.getServiceController();
-      ObjectName objectName = context.getObjectName();
-
       // Configure any attributes
       ServiceMetaData metaData = context.getServiceMetaData();
       if (metaData != null)
       {
+         ServiceController controller = context.getServiceController();
+         ObjectName objectName = context.getObjectName();
+
          List<ServiceAttributeMetaData> attrs = metaData.getAttributes();
          if (attrs.size() > 0)
          {
@@ -69,11 +69,32 @@
    }
 
    /**
-    * No-op
+    * Unconfigure the mbean.
+    * Unget values - releasing potential injections.
     * 
     * @param context The ServiceControllerContext we are uninstalling
     */
    public void uninstallAction(ServiceControllerContext context)
    {
+      // Unconfigure any attributes
+      ServiceMetaData metaData = context.getServiceMetaData();
+      if (metaData != null)
+      {
+         ServiceController controller = context.getServiceController();
+         ObjectName objectName = context.getObjectName();
+
+         List<ServiceAttributeMetaData> attrs = metaData.getAttributes();
+         if (attrs.size() > 0)
+         {
+            ObjectName classLoaderName = metaData.getClassLoaderName();
+            try
+            {
+               ServiceConfigurator.unconfigure(null, controller, objectName, classLoaderName, attrs);
+            }
+            catch (Exception ignored)
+            {
+            }
+         }
+      }
    }
 }




More information about the jboss-cvs-commits mailing list