geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: rev 56340 - in geronimo/trunk/modules: deployment/src/java/org/apache/geronimo/deployment deployment/src/java/org/apache/geronimo/deployment/service kernel/src/java/org/apache/geronimo/gbean kernel/src/java/org/apache/geronimo/gbean/jmx kernel/src/java/org/apache/geronimo/kernel kernel/src/java/org/apache/geronimo/kernel/config system/src/java/org/apache/geronimo/system/configuration system/src/test/org/apache/geronimo/system/configuration
Date Tue, 02 Nov 2004 03:45:49 GMT
Author: dain
Date: Mon Nov  1 19:45:48 2004
New Revision: 56340

Added:
   geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/MockGBean.java
Modified:
   geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java
   geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/service/GBeanBuilder.java
   geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/service/GBeanHelper.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanData.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBean.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java
   geronimo/trunk/modules/system/src/test/org/apache/geronimo/system/configuration/LocalConfigStoreTest.java
Log:
Moved object name into GBeanData


Modified: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java
==============================================================================
--- geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java
(original)
+++ geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java
Mon Nov  1 19:45:48 2004
@@ -155,9 +155,9 @@
         gbeans.put(name, gbean);
     }
 
-    public void addGBean(ObjectName name, GBeanData gbean, ClassLoader classLoader) {
+    public void addGBean(GBeanData gbean, ClassLoader classLoader) {
         GBeanMBean gbeanMBean = new GBeanMBean(gbean, classLoader);
-        gbeans.put(name, gbeanMBean);
+        gbeans.put(gbean.getName(), gbeanMBean);
     }
 
     public void addDependency(URI uri) {

Modified: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/service/GBeanBuilder.java
==============================================================================
--- geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/service/GBeanBuilder.java
(original)
+++ geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/service/GBeanBuilder.java
Mon Nov  1 19:45:48 2004
@@ -35,13 +35,13 @@
  * @version $Rev$ $Date$
  */
 public class GBeanBuilder {
-    private final ObjectName name;
     private final GBeanData gbean;
     private final ClassLoader classLoader;
 
     public GBeanBuilder(String name, ClassLoader classLoader, String className) throws DeploymentException
{
+        ObjectName objectName;
         try {
-            this.name = new ObjectName(name);
+            objectName = new ObjectName(name);
         } catch (MalformedObjectNameException e) {
             throw new DeploymentException("Invalid ObjectName: " + name, e);
         }
@@ -49,7 +49,7 @@
         this.classLoader = classLoader;
 
         try {
-            gbean = new GBeanData(GBeanInfo.getGBeanInfo(className, classLoader));
+            gbean = new GBeanData(objectName, GBeanInfo.getGBeanInfo(className, classLoader));
         } catch (Exception e) {
             throw new DeploymentException("Unable to create GBean from class " + className,
e);
         }
@@ -95,9 +95,5 @@
 
     public GBeanData getGBeanData() {
         return gbean;
-    }
-
-    public ObjectName getName() {
-        return name;
     }
 }

Modified: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/service/GBeanHelper.java
==============================================================================
--- geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/service/GBeanHelper.java
(original)
+++ geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/service/GBeanHelper.java
Mon Nov  1 19:45:48 2004
@@ -45,6 +45,6 @@
             builder.setReference(gbean.getReferencesName(j), gbean.getReferencesPatternArray(j));
         }
 
-        context.addGBean(builder.getName(), builder.getGBeanData(), cl);
+        context.addGBean(builder.getGBeanData(), cl);
     }
 }

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanData.java
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanData.java	(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanData.java	Mon Nov
 1 19:45:48 2004
@@ -32,6 +32,7 @@
  * @version $Rev$ $Date$
  */
 public class GBeanData implements Externalizable {
+    private ObjectName name;
     private GBeanInfo gbeanInfo;
     private final Map attributes;
     private final Map references;
@@ -41,18 +42,28 @@
         references = new HashMap();
     }
 
-    public GBeanData(GBeanInfo gbeanInfo) {
+    public GBeanData(ObjectName name, GBeanInfo gbeanInfo) {
+        this.name = name;
         this.gbeanInfo = gbeanInfo;
         attributes = new HashMap();
         references = new HashMap();
     }
 
     public GBeanData(GBeanData gbeanData) {
+        name = gbeanData.name;
         gbeanInfo = gbeanData.gbeanInfo;
         attributes = new HashMap(gbeanData.attributes);
         references = new HashMap(gbeanData.references);
     }
 
+    public ObjectName getName() {
+        return name;
+    }
+
+    public void setName(ObjectName name) {
+        this.name = name;
+    }
+
     public GBeanInfo getGBeanInfo() {
         return gbeanInfo;
     }
@@ -101,6 +112,9 @@
         // write the gbean info
         out.writeObject(gbeanInfo);
 
+        // write the object name
+        out.writeObject(name);
+
         // write the attributes
         out.writeInt(attributes.size());
         for (Iterator iterator = attributes.entrySet().iterator(); iterator.hasNext();) {
@@ -135,16 +149,29 @@
         // read the gbean info
         gbeanInfo = (GBeanInfo) in.readObject();
 
-        // read the attributes
-        int attributeCount = in.readInt();
-        for (int i = 0; i < attributeCount; i++) {
-            setAttribute((String) in.readObject(), in.readObject());
+        // read the object name
+        try {
+            name = (ObjectName) in.readObject();
+        } catch (IOException e) {
+            throw (IOException) new IOException("Unable to deserialize ObjectName for GBeanData
of type " + gbeanInfo.getClassName()).initCause(e);
         }
 
-        // read the references
-        int endpointCount = in.readInt();
-        for (int i = 0; i < endpointCount; i++) {
-            setReferencePatterns((String) in.readObject(), (Set) in.readObject());
+        try {
+            // read the attributes
+            int attributeCount = in.readInt();
+            for (int i = 0; i < attributeCount; i++) {
+                setAttribute((String) in.readObject(), in.readObject());
+            }
+
+            // read the references
+            int endpointCount = in.readInt();
+            for (int i = 0; i < endpointCount; i++) {
+                setReferencePatterns((String) in.readObject(), (Set) in.readObject());
+            }
+        } catch (IOException e) {
+            throw (IOException) new IOException("Unable to deserialize GBeanData " + name).initCause(e);
+        } catch (ClassNotFoundException e) {
+            throw new ClassNotFoundException("Unable to find class used in GBeanData " +
name, 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	Mon
Nov  1 19:45:48 2004
@@ -684,10 +684,7 @@
      * @return the gbean data
      */
     public GBeanData getGBeanData() {
-        GBeanData gbeanData = new GBeanData();
-
-        // add the gbean info
-        gbeanData.setGBeanInfo(gbeanInfo);
+        GBeanData gbeanData = new GBeanData(objectName, gbeanInfo);
 
         // add the attributes
         for (int i = 0; i < attributes.length; i++) {

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java	(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java	Mon Nov
 1 19:45:48 2004
@@ -282,14 +282,14 @@
         }
     }
 
-    public void loadGBean(ObjectName name, GBeanData gbeanData, ClassLoader classLoader)
throws InstanceAlreadyExistsException, InvalidConfigException {
+    public void loadGBean(GBeanData gbeanData, ClassLoader classLoader) throws InstanceAlreadyExistsException,
InvalidConfigException {
         try {
             GBeanMBean gbean = new GBeanMBean(gbeanData, classLoader);
-            mbServer.registerMBean(gbean, name);
+            mbServer.registerMBean(gbean, gbeanData.getName());
         } catch (MBeanRegistrationException e) {
-            throw new InvalidConfigException("Invalid GBean configuration for " + name, e);
+            throw new InvalidConfigException("Invalid GBean configuration for " + gbeanData.getName(),
e);
         } catch (NotCompliantMBeanException e) {
-            throw new InvalidConfigException("Invalid GBean configuration for " + name, e);
+            throw new InvalidConfigException("Invalid GBean configuration for " + gbeanData.getName(),
e);
         }
     }
 

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java
(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java
Mon Nov  1 19:45:48 2004
@@ -349,18 +349,15 @@
      */
     private static Map loadGBeans(byte[] gbeanState, ClassLoader cl) throws InvalidConfigException
{
         Map gbeans = new HashMap();
-        ObjectName objectName = null;
         try {
             ObjectInputStream ois = new ConfigInputStream(new ByteArrayInputStream(gbeanState),
cl);
             try {
                 while (true) {
-                    objectName = (ObjectName) ois.readObject();
-
                     GBeanData gbeanData = new GBeanData();
                     gbeanData.readExternal(ois);
                     GBeanMBean gbean = new GBeanMBean(gbeanData, cl);
 
-                    gbeans.put(objectName, gbean);
+                    gbeans.put(gbeanData.getName(), gbean);
                 }
             } catch (EOFException e) {
                 // ok
@@ -369,8 +366,7 @@
             }
             return gbeans;
         } catch (Exception e) {
-            throw new InvalidConfigException("Unable to deserialize GBeanState" +
-                    (objectName == null ? "" : " " + objectName), e);
+            throw new InvalidConfigException("Unable to deserialize GBeanState", e);
         }
     }
 
@@ -401,8 +397,11 @@
             ObjectName objectName = (ObjectName) entry.getKey();
             GBeanMBean gbean = (GBeanMBean) entry.getValue();
             try {
-                oos.writeObject(objectName);
-                gbean.getGBeanData().writeExternal(oos);
+                GBeanData gbeanData = gbean.getGBeanData();
+                // todo we must explicitly set the bean name here from the gbean key because
the gbean mbean may
+                // not have been brought online, so the object namve in the gbean mbean will
be null
+                gbeanData.setName(objectName);
+                gbeanData.writeExternal(oos);
             } catch (Exception e) {
                 throw new InvalidConfigException("Unable to serialize GBeanState for " +
objectName, e);
             }

Added: geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/MockGBean.java
==============================================================================
--- (empty file)
+++ geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/MockGBean.java
Mon Nov  1 19:45:48 2004
@@ -0,0 +1,49 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.geronimo.system.configuration;
+
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GBeanInfoBuilder;
+
+/**
+ * @version $Rev: 46019 $ $Date: 2004-09-14 02:56:06 -0700 (Tue, 14 Sep 2004) $
+ */
+public class MockGBean {
+    private static final GBeanInfo GBEAN_INFO;
+
+    private String value;
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+    public static GBeanInfo getGBeanInfo() {
+        return GBEAN_INFO;
+    }
+
+    static {
+        GBeanInfoBuilder infoBuilder = new GBeanInfoBuilder("MockGBean", MockGBean.class);
+        infoBuilder.addAttribute("value", String.class, true);
+
+        GBEAN_INFO = infoBuilder.getBeanInfo();
+    }
+}

Modified: geronimo/trunk/modules/system/src/test/org/apache/geronimo/system/configuration/LocalConfigStoreTest.java
==============================================================================
--- geronimo/trunk/modules/system/src/test/org/apache/geronimo/system/configuration/LocalConfigStoreTest.java
(original)
+++ geronimo/trunk/modules/system/src/test/org/apache/geronimo/system/configuration/LocalConfigStoreTest.java
Mon Nov  1 19:45:48 2004
@@ -130,10 +130,10 @@
             root.mkdir();
 
             storeName = new ObjectName("geronimo.test:role=ConfigurationStore,name=LocalConfigStore");
-            GBeanData store = new GBeanData(LocalConfigStore.getGBeanInfo());
+            GBeanData store = new GBeanData(storeName, LocalConfigStore.getGBeanInfo());
             store.setAttribute("root", root.toURI());
 
-            kernel.loadGBean(storeName, store, getClass().getClassLoader());
+            kernel.loadGBean(store, getClass().getClassLoader());
             kernel.startGBean(storeName);
 
             GBeanMBean gbean = new GBeanMBean(Configuration.GBEAN_INFO);

Mime
View raw message