djencks 2004/01/14 00:31:07
Modified: modules/kernel/src/java/org/apache/geronimo/gbean
GBeanInfo.java
modules/kernel/src/java/org/apache/geronimo/gbean/jmx
GMBean.java
modules/kernel/src/java/org/apache/geronimo/kernel
Kernel.java
modules/kernel/src/java/org/apache/geronimo/kernel/config
Configuration.java LocalConfigStore.java
modules/kernel/src/test/org/apache/geronimo/kernel
BootstrapTest.java ConfigTest.java
modules/kernel/src/test/org/apache/geronimo/kernel/config
LocalConfigStoreTest.java
Log:
Fix problems with attribute value ordering, and serialize endpoint patterns
Revision Changes Path
1.2 +9 -11
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanInfo.java
Index: GBeanInfo.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanInfo.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- GBeanInfo.java 12 Jan 2004 01:38:55 -0000 1.1
+++ GBeanInfo.java 14 Jan 2004 08:31:06 -0000 1.2
@@ -108,7 +108,6 @@
private final Set operations;
private final Set notifications;
private final Set endpoints;
- private final List persistentAttributes;
public GBeanInfo(String className, Set attributes, GConstructorInfo
constructor, Set operations, Set endpoints, Set notifications) {
this(className, null, className, attributes, constructor,
operations, endpoints, notifications);
@@ -128,14 +127,6 @@
this.endpoints = Collections.unmodifiableSet(endpoints);
this.notifications = Collections.unmodifiableSet(notifications);
- List attrs = new ArrayList();
- for (Iterator i = attributes.iterator(); i.hasNext();) {
- GAttributeInfo info = (GAttributeInfo) i.next();
- if (info.isPersistent()) {
- attrs.add(info);
- }
- }
- persistentAttributes = Collections.unmodifiableList(attrs);
}
public String getName() {
@@ -155,7 +146,14 @@
}
public List getPersistentAttributes() {
- return persistentAttributes;
+ List attrs = new ArrayList();
+ for (Iterator i = attributes.iterator(); i.hasNext();) {
+ GAttributeInfo info = (GAttributeInfo) i.next();
+ if (info.isPersistent()) {
+ attrs.add(info);
+ }
+ }
+ return attrs;
}
public GConstructorInfo getConstructor() {
1.2 +7 -7
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GMBean.java
Index: GMBean.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GMBean.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- GMBean.java 12 Jan 2004 01:38:55 -0000 1.1
+++ GMBean.java 14 Jan 2004 08:31:07 -0000 1.2
@@ -215,9 +215,9 @@
/**
* "Bootstrapping" constructor. The class specified is loaded and the
static method
- * "getGeronimoMBeanInfo" is called to get the mbean info. Usually one
will include
- * this static method in the class to be wrapped in the GeronimoMBean
instance.
- * @param className name of the class to call getGeronimoMBeanInfo on
+ * "getGBeanInfo" is called to get the gbean info. Usually one will
include
+ * this static method in the class to be wrapped in the GMBean instance.
+ * @param className name of the class to call getGBeanInfo on
* @param classLoader the class loader for this GBean
* @throws java.lang.Exception if an exception occurs while getting the
GeronimoMBeanInfo from the class
*/
@@ -227,9 +227,9 @@
/**
* "Bootstrapping" constructor. The class specified is loaded and the
static method
- * "getGeronimoMBeanInfo" is called to get the mbean info. Usually one
will include
- * this static method in the class to be wrapped in the GeronimoMBean
instance.
- * @param className name of the class to call getGeronimoMBeanInfo on
+ * "getGBeanInfo" is called to get the gbean info. Usually one will
include
+ * this static method in the class to be wrapped in the GMBean instance.
+ * @param className name of the class to call getGBeanInfo on
* @throws java.lang.Exception if an exception occurs while getting the
GeronimoMBeanInfo from the class
*/
public GMBean(String className) throws Exception {
1.2 +8 -8
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java
Index: Kernel.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Kernel.java 12 Jan 2004 01:39:46 -0000 1.1
+++ Kernel.java 14 Jan 2004 08:31:07 -0000 1.2
@@ -59,8 +59,9 @@
import java.io.IOException;
import java.io.Serializable;
import java.net.URI;
-import java.net.URL;
import java.net.URISyntaxException;
+import java.net.URL;
+
import javax.management.InstanceNotFoundException;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
@@ -68,17 +69,16 @@
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.jmx.GMBean;
import org.apache.geronimo.kernel.config.ConfigurationStore;
import org.apache.geronimo.kernel.config.InvalidConfigException;
-import org.apache.geronimo.kernel.config.NoSuchConfigException;
import org.apache.geronimo.kernel.config.LocalConfigStore;
+import org.apache.geronimo.kernel.config.NoSuchConfigException;
import org.apache.geronimo.kernel.jmx.JMXUtil;
import org.apache.geronimo.kernel.service.DependencyService2;
-import org.apache.geronimo.gbean.GBeanInfo;
-import org.apache.geronimo.gbean.jmx.GMBean;
-import org.apache.commons.logging.impl.LogFactoryImpl;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
/**
* The core of a Geronimo instance.
1.2 +49 -11
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java
Index: Configuration.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Configuration.java 12 Jan 2004 01:39:46 -0000 1.1
+++ Configuration.java 14 Jan 2004 08:31:07 -0000 1.2
@@ -74,19 +74,23 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+
import javax.management.MBeanServer;
import javax.management.ObjectName;
+import javax.management.AttributeNotFoundException;
+import javax.management.InvalidAttributeValueException;
+import javax.management.MBeanException;
+import javax.management.ReflectionException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.geronimo.kernel.Kernel;
import org.apache.geronimo.gbean.GAttributeInfo;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GConstructorInfo;
import org.apache.geronimo.gbean.GEndpointInfo;
-import org.apache.geronimo.gbean.GOperationInfo;
import org.apache.geronimo.gbean.jmx.GMBean;
import org.apache.geronimo.gbean.jmx.GMBeanTarget;
+import org.apache.geronimo.kernel.Kernel;
/**
* A Configuration represents a collection of runnable services that can be
@@ -131,6 +135,7 @@
private ObjectName objectName;
private ClassLoader classLoader;
+ private byte[] savedState;
/**
* Constructor that can be used to create an offline Configuration,
typically
@@ -192,6 +197,11 @@
}
// save state
+ try {
+ savedState = storeGBeans(gbeans);
+ } catch (InvalidConfigException e) {
+ log.info(e);
+ }
gbeans = null;
}
@@ -242,6 +252,10 @@
this.objectName = objectName;
}
+ public byte[] getSavedState() {
+ return savedState;
+ }
+
private static class ConfigInputStream extends ObjectInputStream {
private final ClassLoader cl;
@@ -271,10 +285,7 @@
ObjectName objectName = (ObjectName) ois.readObject();
GBeanInfo info = (GBeanInfo) ois.readObject();
GMBean gbean = new GMBean(info, cl);
- for (Iterator iterator =
info.getPersistentAttributes().iterator(); iterator.hasNext();) {
- GAttributeInfo attributeInfo = (GAttributeInfo)
iterator.next();
- gbean.setAttribute(attributeInfo.getName(),
ois.readObject());
- }
+ loadGMBeanState(gbean, ois);
gbeans.put(objectName, gbean);
}
} catch (EOFException e) {
@@ -288,6 +299,17 @@
}
}
+ static void loadGMBeanState(GMBean gbean, ObjectInputStream ois) throws
IOException, AttributeNotFoundException, InvalidAttributeValueException,
MBeanException, ReflectionException, ClassNotFoundException {
+ int attributeCount = ois.readInt();
+ for (int i = 0; i < attributeCount; i ++) {
+ gbean.setAttribute((String)ois.readObject(), ois.readObject());
+ }
+ int endpointCount = ois.readInt();
+ for (int i = 0; i < endpointCount; i ++) {
+ gbean.setEndpointPatterns((String)ois.readObject(),
(Set)ois.readObject());
+ }
+ }
+
/**
* Return a byte array containing the persisted form of the supplied
GBeans
* @param gbeans a Map<ObjectName, GMBean> of GBeans to store
@@ -305,17 +327,32 @@
GMBean gbean = (GMBean) entry.getValue();
oos.writeObject(objectName);
oos.writeObject(gbean.getGBeanInfo());
- for (Iterator j =
gbean.getGBeanInfo().getPersistentAttributes().iterator(); j.hasNext();) {
- GAttributeInfo attributeInfo = (GAttributeInfo) j.next();
-
oos.writeObject(gbean.getAttribute(attributeInfo.getName()));
- }
+ storeGMBeanState(gbean, oos);
}
+ oos.flush();
} catch (Exception e) {
throw new InvalidConfigException("Unable to serialize
GBeanState", e);
}
return baos.toByteArray();
}
+ static void storeGMBeanState(GMBean gbean, ObjectOutputStream oos)
throws IOException, AttributeNotFoundException, MBeanException,
ReflectionException {
+ List persistentAttributes =
gbean.getGBeanInfo().getPersistentAttributes();
+ oos.writeInt(persistentAttributes.size());
+ for (Iterator j = persistentAttributes.iterator(); j.hasNext();) {
+ GAttributeInfo attributeInfo = (GAttributeInfo) j.next();
+ oos.writeObject(attributeInfo.getName());
+ oos.writeObject(gbean.getAttribute(attributeInfo.getName()));
+ }
+ Set endpointsSet = gbean.getGBeanInfo().getEndpointsSet();
+ oos.writeInt(endpointsSet.size());
+ for (Iterator iterator = endpointsSet.iterator();
iterator.hasNext();) {
+ GEndpointInfo gEndpointInfo = (GEndpointInfo) iterator.next();
+ oos.writeObject(gEndpointInfo.getName());
+
oos.writeObject(gbean.getEndpointPatterns(gEndpointInfo.getName()));
+ }
+ }
+
public static final GBeanInfo GBEAN_INFO;
static {
@@ -327,6 +364,7 @@
attrs.add(new GAttributeInfo("MBeanServer"));
attrs.add(new GAttributeInfo("ObjectName"));
attrs.add(new GAttributeInfo("ClassLoader"));
+ attrs.add(new GAttributeInfo("SavedState"));
List ctrNames = new ArrayList();
ctrNames.add("ID");
ctrNames.add("Parent");
1.2 +10 -12
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/LocalConfigStore.java
Index: LocalConfigStore.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/LocalConfigStore.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LocalConfigStore.java 12 Jan 2004 01:39:46 -0000 1.1
+++ LocalConfigStore.java 14 Jan 2004 08:31:07 -0000 1.2
@@ -80,9 +80,9 @@
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GConstructorInfo;
import org.apache.geronimo.gbean.InvalidConfigurationException;
+import org.apache.geronimo.gbean.WaitingException;
import org.apache.geronimo.gbean.jmx.GMBean;
import org.apache.geronimo.gbean.jmx.GMBeanTarget;
-import org.apache.geronimo.gbean.WaitingException;
/**
* Implementation of ConfigurationStore using the local filesystem.
@@ -225,17 +225,15 @@
try {
config = new GMBean(gbeanInfo);
} catch (InvalidConfigurationException e) {
- throw new InvalidConfigException("Unable to instanciate
Configuration GMBean", e);
+ throw new InvalidConfigException("Unable to instantiate
Configuration GMBean", e);
}
- for (Iterator i =
gbeanInfo.getPersistentAttributes().iterator(); i.hasNext();) {
- GAttributeInfo attr = (GAttributeInfo) i.next();
- try {
- config.setAttribute(attr.getName(), ois.readObject());
- } catch (ClassNotFoundException e) {
- throw new InvalidConfigException("Unable to read
attribute " + attr.getName(), e);
- } catch (Exception e) {
- throw new InvalidConfigException("Unable to set
attribute " + attr.getName(), e);
- }
+ try {
+ Configuration.loadGMBeanState(config, ois);
+ } catch (ClassNotFoundException e) {
+ //TODO more informative exceptions
+ throw new InvalidConfigException("Unable to read attribute
", e);
+ } catch (Exception e) {
+ throw new InvalidConfigException("Unable to set attribute ",
e);
}
return config;
} finally {
1.2 +3 -5
incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel/BootstrapTest.java
Index: BootstrapTest.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel/BootstrapTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BootstrapTest.java 12 Jan 2004 01:40:08 -0000 1.1
+++ BootstrapTest.java 14 Jan 2004 08:31:07 -0000 1.2
@@ -60,12 +60,10 @@
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
-import javax.management.ObjectName;
-import org.apache.geronimo.kernel.config.LocalConfigStore;
-import org.apache.geronimo.kernel.jmx.JMXUtil;
-import org.apache.geronimo.gbean.GBeanInfo;
import junit.framework.TestCase;
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.kernel.config.LocalConfigStore;
/**
*
1.2 +7 -11
incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel/ConfigTest.java
Index: ConfigTest.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel/ConfigTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ConfigTest.java 12 Jan 2004 01:40:08 -0000 1.1
+++ ConfigTest.java 14 Jan 2004 08:31:07 -0000 1.2
@@ -62,6 +62,9 @@
import java.net.URL;
import java.util.Iterator;
import java.util.Collections;
+import java.util.Map;
+import java.util.HashMap;
+
import javax.management.InstanceNotFoundException;
import javax.management.MBeanServer;
import javax.management.ObjectName;
@@ -136,16 +139,9 @@
mockBean.setAttribute("Value", "1234");
mockBean.setAttribute("Name", "Name");
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(gbeanName);
- oos.writeObject(mockBean.getGBeanInfo());
- for (Iterator i =
mockBean.getGBeanInfo().getPersistentAttributes().iterator(); i.hasNext();) {
- GAttributeInfo attr = (GAttributeInfo) i.next();
- oos.writeObject(mockBean.getAttribute(attr.getName()));
- }
- oos.close();
- state = baos.toByteArray();
+ Map gbeans = new HashMap();
+ gbeans.put(gbeanName, mockBean);
+ state = Configuration.storeGBeans(gbeans);
}
protected void tearDown() throws Exception {
1.2 +4 -7
incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel/config/LocalConfigStoreTest.java
Index: LocalConfigStoreTest.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel/config/LocalConfigStoreTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LocalConfigStoreTest.java 12 Jan 2004 01:40:08 -0000 1.1
+++ LocalConfigStoreTest.java 14 Jan 2004 08:31:07 -0000 1.2
@@ -72,8 +72,8 @@
import junit.framework.TestCase;
/**
- *
- *
+ *
+ *
* @version $Revision$ $Date$
*/
public class LocalConfigStoreTest extends TestCase {
@@ -106,10 +106,7 @@
JarOutputStream jos = new JarOutputStream(new
BufferedOutputStream(new FileOutputStream(sourceFile)));
jos.putNextEntry(new ZipEntry("META-INF/config.ser"));
ObjectOutputStream oos = new ObjectOutputStream(jos);
- for (Iterator i =
gbean.getGBeanInfo().getPersistentAttributes().iterator(); i.hasNext();) {
- GAttributeInfo attributeInfo = (GAttributeInfo) i.next();
- oos.writeObject(gbean.getAttribute(attributeInfo.getName()));
- }
+ Configuration.storeGMBeanState(gbean, oos);
oos.flush();
jos.closeEntry();
jos.close();