geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: rev 56462 - geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx
Date Wed, 03 Nov 2004 03:25:51 GMT
Author: dain
Date: Tue Nov  2 19:25:49 2004
New Revision: 56462

Modified:
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/AbstractManagedObject.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBean.java
Log:
Added gbeanEnabled flag to enable/disable gbeans
A disabled gbean can not be started, and will not be started from startRecursive


Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/AbstractManagedObject.java
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/AbstractManagedObject.java
(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/AbstractManagedObject.java
Tue Nov  2 19:25:49 2004
@@ -94,6 +94,11 @@
      */
     private ObjectName blocker;
 
+    /**
+     * Is this gbean enabled?  A disabled gbean can not be started.
+     */
+    private boolean enabled = true;
+
     // This must be volatile otherwise getState must be synchronized which will result in
deadlock as dependent
     // objects check if each other are in one state or another (i.e., classic A calls B while
B calls A)
     private volatile State state = State.STOPPED;
@@ -184,6 +189,24 @@
         return objectName;
     }
 
+    /**
+     * Is this gbean enabled.  A disabled gbean can not be started.
+     *
+     * @return true if the gbean is enabled and can be started
+     */
+    public synchronized final boolean isEnabled() {
+        return enabled;
+    }
+
+    /**
+     * Changes the enabled status.
+     *
+     * @param enabled the new enabled flag
+     */
+    public synchronized final void setEnabled(boolean enabled) {
+        this.enabled = enabled;
+    }
+
     public DependencyManager getDependencyManager() {
         return dependencyManager;
     }
@@ -272,6 +295,9 @@
             if (state == State.STARTING || state == State.RUNNING) {
                 return;
             }
+            if (!enabled) {
+                throw new IllegalStateException("A disabled GBean can not be started: objectName="
+ objectName);
+            }
             setStateInstance(State.STARTING);
         }
         sendNotification(State.STARTING.getEventTypeValue());
@@ -306,13 +332,21 @@
         Set dependents = dependencyManager.getChildren(objectName);
         for (Iterator iterator = dependents.iterator(); iterator.hasNext();) {
             ObjectName dependent = (ObjectName) iterator.next();
+            boolean enabled = true;
             try {
-                server.invoke(dependent, "startRecursive", null, null);
-            } catch (ReflectionException e) {
-                if (e.getTargetException() instanceof NoSuchMethodException) {
-                    // did not have a startRecursive method - ok
-                } else {
-                    throw e;
+                enabled = ((Boolean) server.getAttribute(dependent, "gbeanEnabled")).booleanValue();
+            } catch (AttributeNotFoundException e) {
+                // this is ok didn't have the attribute....
+            }
+            if (enabled) {
+                try {
+                    server.invoke(dependent, "startRecursive", null, null);
+                } catch (ReflectionException e) {
+                    if (e.getTargetException() instanceof NoSuchMethodException) {
+                        // did not have a startRecursive method - ok
+                    } else {
+                        throw e;
+                    }
                 }
             }
         }

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBean.java
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBean.java	(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBean.java	Tue
Nov  2 19:25:49 2004
@@ -154,7 +154,7 @@
     private final Class type;
 
     /**
-     * Is this gbean off line?
+     * Is this gbean offline?
      */
     private boolean offline = true;
 
@@ -933,6 +933,23 @@
                         "kernel",
                         Kernel.class,
                         null));
+
+        attributesMap.put("gbeanEnabled",
+                new GBeanMBeanAttribute(this,
+                        "gbeanEnabled",
+                        Boolean.TYPE,
+                        new MethodInvoker() {
+                            public Object invoke(Object target, Object[] arguments) throws
Exception {
+                                return new Boolean(isEnabled());
+                            }
+                        },
+                        new MethodInvoker() {
+                            public Object invoke(Object target, Object[] arguments) throws
Exception {
+                                Boolean enabled = (Boolean) arguments[0];
+                                setEnabled(enabled.booleanValue());
+                                return null;
+                            }
+                        }));
 
         //
         // Normal attributes

Mime
View raw message