You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by am...@apache.org on 2005/08/06 22:47:11 UTC
svn commit: r230585 - in /geronimo/trunk/modules/kernel/src:
java/org/apache/geronimo/gbean/ java/org/apache/geronimo/gbean/runtime/
java/org/apache/geronimo/kernel/ java/org/apache/geronimo/kernel/basic/
java/org/apache/geronimo/kernel/config/ java/or...
Author: ammulder
Date: Sat Aug 6 13:47:02 2005
New Revision: 230585
URL: http://svn.apache.org/viewcvs?rev=230585&view=rev
Log:
Proxies should use interfaces from the caller's class loader
- Interfaces in GBeanInfo are tracked by name, not by class
- When ProxyManager computes intefaces, the caller must supply
a ClassLoader to use to instantiate them
Add GBeanQuery to list GBeans by interface as well as by name
Make Configurations editable
- Can add or remove a GBean at runtime
Bug fix to the GBeanInfoBuilder to handle interfaces in superclass
GBeanInfo
Add start/startRecursive framework operations to allow a GBean to
implement StateManageable
Added:
geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanQuery.java
Modified:
geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanInfoBuilder.java
geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java
geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java
geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/KernelGBean.java
geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicKernel.java
geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicProxyManager.java
geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java
geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/jmx/KernelDelegate.java
geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/ProxyManager.java
geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/ConfigTest.java
geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/GBeanTest.java
Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanInfoBuilder.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanInfoBuilder.java?rev=230585&r1=230584&r2=230585&view=diff
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanInfoBuilder.java (original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanInfoBuilder.java Sat Aug 6 13:47:02 2005
@@ -108,6 +108,11 @@
references.put(referenceInfo.getName(), new RefInfo(referenceInfo.getReferenceType(), referenceInfo.getNameTypeName()));
}
+ for (Iterator iterator = source.getInterfaces().iterator(); iterator.hasNext();) {
+ String intf = (String) iterator.next();
+ interfaces.add(intf);
+ }
+
//in case subclass constructor has same parameters as superclass.
constructor = source.getConstructor();
}
@@ -180,7 +185,19 @@
}
}
if(intf.isInterface()) {
- interfaces.add(intf);
+ addInterface(interfaces, intf);
+ }
+ }
+
+ private static void addInterface(Set set, Class intf) {
+ String name = intf.getName();
+ if(set.contains(name)) {
+ return;
+ }
+ set.add(name);
+ Class cls[] = intf.getInterfaces();
+ for (int i = 0; i < cls.length; i++) {
+ addInterface(set, cls[i]);
}
}
Added: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanQuery.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanQuery.java?rev=230585&view=auto
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanQuery.java (added)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanQuery.java Sat Aug 6 13:47:02 2005
@@ -0,0 +1,83 @@
+/**
+ *
+ * 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.gbean;
+
+import java.io.Serializable;
+
+/**
+ * Criteria for querying for a list of GBeans. Currently all criteria are
+ * "ORed" (a GBean meeting any of them matches).
+ *
+ * @version $Rev: 209177 $ $Date: 2005-07-04 21:42:14 -0400 (Mon, 04 Jul 2005) $
+ */
+public class GBeanQuery implements Serializable {
+ private String[] gbeanNames;
+ private String[] interfaces;
+
+ /**
+ * A query that will be populated later by getters and setters.
+ */
+ public GBeanQuery() {
+ }
+
+ /**
+ * A query with a single GBean name, single interface, or both. Either
+ * argument may be null.
+ *
+ * @param gbeanName A GBean name criterion, or null if there is none
+ * @param interfaceName An object name criterion, or null if there is none
+ */
+ public GBeanQuery(String gbeanName, String interfaceName) {
+ gbeanNames = gbeanName == null ? null : new String[]{gbeanName};
+ interfaces = interfaceName == null ? null : new String[]{interfaceName};
+ }
+
+ /**
+ * A query with zero or more GBean names and zero or more interfaces.
+ * Either argument may be null.
+ *
+ * @param gbeanNames GBean name criteria, or null if there are none
+ * @param interfaceNames Interface name criteria, or null if there are none
+ */
+ public GBeanQuery(String[] gbeanNames, String[] interfaceNames) {
+ this.gbeanNames = gbeanNames;
+ interfaces = interfaceNames;
+ }
+
+ public String[] getGBeanNames() {
+ return gbeanNames;
+ }
+
+ public void setGBeanNames(String[] gbeanNames) {
+ this.gbeanNames = gbeanNames;
+ }
+
+ public String[] getInterfaces() {
+ return interfaces;
+ }
+
+ public void setInterfaces(String[] interfaces) {
+ this.interfaces = interfaces;
+ }
+
+ /**
+ * Checks whether any criteria are present.
+ */
+ public boolean isCriteria() {
+ return (gbeanNames != null && gbeanNames.length > 0) || (interfaces != null && interfaces.length > 0);
+ }
+}
Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java?rev=230585&r1=230584&r2=230585&view=diff
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java (original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java Sat Aug 6 13:47:02 2005
@@ -100,7 +100,7 @@
/**
* Interfaces for this GBean
*/
- private final Class[] interfaces;
+ private final String[] interfaces;
/**
* Attributes lookup table
@@ -213,7 +213,7 @@
Set constructorArgs = new HashSet(gbeanInfo.getConstructor().getAttributeNames());
// interfaces
- interfaces = (Class[]) gbeanInfo.getInterfaces().toArray(new Class[0]);
+ interfaces = (String[]) gbeanInfo.getInterfaces().toArray(new String[0]);
// attributes
Map attributesMap = new HashMap();
@@ -242,8 +242,23 @@
referenceIndex.put(references[i].getName(), new Integer(i));
}
+ // framework operations
+ GBeanOperation opStart = GBeanOperation.createFrameworkOperation(this, "start", Collections.EMPTY_LIST, new MethodInvoker() {
+ public Object invoke(Object target, Object[] arguments) throws Exception {
+ GBeanInstance.this.kernel.startGBean(objectName);
+ return null;
+ }
+ });
+ GBeanOperation opStartRecursive = GBeanOperation.createFrameworkOperation(this, "startRecursive", Collections.EMPTY_LIST, new MethodInvoker() {
+ public Object invoke(Object target, Object[] arguments) throws Exception {
+ GBeanInstance.this.kernel.startRecursiveGBean(objectName);
+ return null;
+ }
+ });
// operations
Map operationsMap = new HashMap();
+ operationsMap.put(new GOperationSignature("start", new String[0]), opStart);
+ operationsMap.put(new GOperationSignature("startRecursive", new String[0]), opStartRecursive);
for (Iterator iterator = gbeanInfo.getOperations().iterator(); iterator.hasNext();) {
GOperationInfo operationInfo = (GOperationInfo) iterator.next();
GOperationSignature signature = new GOperationSignature(operationInfo.getName(), operationInfo.getParameterList());
Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java?rev=230585&r1=230584&r2=230585&view=diff
==============================================================================
--- 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 Sat Aug 6 13:47:02 2005
@@ -22,6 +22,7 @@
import org.apache.geronimo.gbean.GBeanData;
import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GBeanQuery;
import org.apache.geronimo.kernel.jmx.JMXUtil;
import org.apache.geronimo.kernel.lifecycle.LifecycleMonitor;
import org.apache.geronimo.kernel.proxy.ProxyManager;
@@ -186,6 +187,12 @@
* @return a List of javax.management.ObjectName of matching GBeans registered with this kernel
*/
Set listGBeans(Set patterns);
+
+ /**
+ * Returns a Set of all GBeans matching any of the specified criteria
+ * @return a List of javax.management.ObjectName of matching GBeans registered with this kernel
+ */
+ Set listGBeans(GBeanQuery query);
/**
* Gets the value of an attribute on the specified gbean
Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/KernelGBean.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/KernelGBean.java?rev=230585&r1=230584&r2=230585&view=diff
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/KernelGBean.java (original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/KernelGBean.java Sat Aug 6 13:47:02 2005
@@ -23,6 +23,7 @@
import org.apache.geronimo.gbean.GBeanData;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoBuilder;
+import org.apache.geronimo.gbean.GBeanQuery;
import org.apache.geronimo.kernel.lifecycle.LifecycleMonitor;
import org.apache.geronimo.kernel.proxy.ProxyManager;
@@ -138,6 +139,10 @@
public Set listGBeans(Set patterns) throws InternalKernelException {
return kernel.listGBeans(patterns);
+ }
+
+ public Set listGBeans(GBeanQuery query) {
+ return kernel.listGBeans(query);
}
public void registerShutdownHook(Runnable hook) {
Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicKernel.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicKernel.java?rev=230585&r1=230584&r2=230585&view=diff
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicKernel.java (original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicKernel.java Sat Aug 6 13:47:02 2005
@@ -23,13 +23,16 @@
import java.util.LinkedList;
import java.util.Map;
import java.util.Set;
+import java.util.Collections;
import javax.management.ObjectName;
+import javax.management.MalformedObjectNameException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.geronimo.gbean.GBeanData;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanName;
+import org.apache.geronimo.gbean.GBeanQuery;
import org.apache.geronimo.gbean.runtime.GBeanInstance;
import org.apache.geronimo.kernel.DependencyManager;
import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
@@ -258,6 +261,59 @@
gbeans.addAll(listGBeans(pattern));
}
return gbeans;
+ }
+
+ public Set listGBeans(String[] patterns) {
+ Set gbeans = new HashSet();
+ for(int i=0; i<patterns.length; i++) {
+ ObjectName pattern = null;
+ try {
+ pattern = ObjectName.getInstance(patterns[i]);
+ } catch (MalformedObjectNameException e) {}
+ gbeans.addAll(listGBeans(pattern));
+ }
+ return gbeans;
+ }
+
+ public Set listGBeansByInterface(String[] interfaces) {
+ Set gbeans = new HashSet();
+ Set all = null;
+ try {
+ all = listGBeans(ObjectName.getInstance("*:*"));
+ } catch (MalformedObjectNameException e) {
+ throw new IllegalStateException("How can *:* be an invalid pattern");
+ }
+ for (Iterator it = all.iterator(); it.hasNext();) {
+ ObjectName name = (ObjectName) it.next();
+ try {
+ GBeanInfo info = getGBeanData(name).getGBeanInfo();
+ Set intfs = info.getInterfaces();
+ for (int i = 0; i < interfaces.length; i++) {
+ String candidate = interfaces[i];
+ if(intfs.contains(candidate)) {
+ gbeans.add(name);
+ break;
+ }
+ }
+ } catch (GBeanNotFoundException e) {}
+ }
+ return gbeans;
+ }
+
+ /**
+ * Returns a Set of all GBeans matching the specified criteria
+ *
+ * @return a List of javax.management.ObjectName of matching GBeans registered with this kernel
+ */
+ public Set listGBeans(GBeanQuery query) {
+ Set results = new HashSet();
+ if(query.getGBeanNames() != null && query.getGBeanNames().length > 0) {
+ results.addAll(listGBeans(query.getGBeanNames()));
+ }
+ if(query.getInterfaces() != null && query.getInterfaces().length > 0) {
+ results.addAll(listGBeansByInterface(query.getInterfaces()));
+ }
+ return results;
}
/**
Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicProxyManager.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicProxyManager.java?rev=230585&r1=230584&r2=230585&view=diff
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicProxyManager.java (original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicProxyManager.java Sat Aug 6 13:47:02 2005
@@ -65,7 +65,7 @@
return createProxyFactory(type).createProxy(target);
}
- public Object createProxy(ObjectName target) {
+ public Object createProxy(ObjectName target, ClassLoader loader) {
assert target != null: "target is null";
try {
GBeanInfo info = kernel.getGBeanInfo(target);
@@ -73,10 +73,16 @@
log.warn("No interfaces found for "+target+" ("+info.getClassName()+")");
return null;
}
- Class[] intfs = (Class[]) info.getInterfaces().toArray(new Class[0]);
+ String[] names = (String[]) info.getInterfaces().toArray(new String[0]);
+ Class[] intfs = new Class[names.length];
+ for (int i = 0; i < intfs.length; i++) {
+ intfs[i] = loader.loadClass(names[i]);
+ }
return createProxyFactory(intfs).createProxy(target);
} catch (GBeanNotFoundException e) {
throw new IllegalArgumentException("Could not get GBeanInfo for target object: " + target);
+ } catch (ClassNotFoundException e) {
+ throw new IllegalArgumentException("Could not load interface in provided ClassLoader: " + e.getMessage());
}
}
@@ -100,7 +106,7 @@
if (!optional[i].isInterface()) {
throw new IllegalArgumentException("Cannot create a proxy for a class (only interfaces) -- " + optional[i].getName());
}
- if (set.contains(optional[i])) {
+ if (set.contains(optional[i].getName())) {
list.add(optional[i]);
}
}
@@ -111,10 +117,10 @@
return createProxyFactory((Class[]) list.toArray(new Class[list.size()])).createProxy(target);
}
- public Object[] createProxies(String[] objectNameStrings) throws MalformedObjectNameException {
+ public Object[] createProxies(String[] objectNameStrings, ClassLoader loader) throws MalformedObjectNameException {
Object[] result = new Object[objectNameStrings.length];
for (int i = 0; i < result.length; i++) {
- result[i] = createProxy(ObjectName.getInstance(objectNameStrings[i]));
+ result[i] = createProxy(ObjectName.getInstance(objectNameStrings[i]), loader);
}
return result;
}
Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java?rev=230585&r1=230584&r2=230585&view=diff
==============================================================================
--- 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 Sat Aug 6 13:47:02 2005
@@ -47,6 +47,10 @@
import org.apache.geronimo.gbean.GBeanLifecycle;
import org.apache.geronimo.kernel.Kernel;
import org.apache.geronimo.kernel.ObjectInputStreamExt;
+import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
+import org.apache.geronimo.kernel.InternalKernelException;
+import org.apache.geronimo.kernel.management.State;
import org.apache.geronimo.kernel.jmx.JMXUtil;
import org.apache.geronimo.kernel.repository.MissingDependencyException;
import org.apache.geronimo.kernel.repository.Repository;
@@ -131,7 +135,7 @@
private Set objectNames;
/**
- * The classloadeder used to load the child GBeans contained in this configuration.
+ * The classloader used to load the child GBeans contained in this configuration.
*/
private ConfigurationClassLoader configurationClassLoader;
@@ -268,22 +272,14 @@
// create and initialize GBeans
Collection gbeans = loadGBeans(gbeanState, configurationClassLoader);
- // set configurationBaseUrl attribute on each gbean
- for (Iterator i = gbeans.iterator(); i.hasNext();) {
- GBeanData gbeanData = (GBeanData) i.next();
- setGBeanBaseUrl(gbeanData, baseURL);
- }
-
// register all the GBeans
Set objectNames = new HashSet();
for (Iterator i = gbeans.iterator(); i.hasNext();) {
GBeanData gbeanData = (GBeanData) i.next();
- ObjectName name = gbeanData.getName();
- log.trace("Registering GBean " + name);
- kernel.loadGBean(gbeanData, configurationClassLoader);
- objectNames.add(name);
- // todo change this to a dependency on the gbeanData itself as soon as we add that feature
- kernel.getDependencyManager().addDependency(name, this.objectName);
+ // set configurationBaseUrl attribute on each gbean
+ setGBeanBaseUrl(gbeanData, baseURL);
+ // add the GBean to the kernel
+ loadGBean(gbeanData, objectNames);
}
this.objectNames = objectNames;
} finally {
@@ -338,27 +334,10 @@
}
}
- public void doStop() throws Exception {
+ public synchronized void doStop() throws Exception {
log.info("Stopping configuration " + id);
- // get the gbean data for all gbeans
- GBeanData[] gbeans = new GBeanData[objectNames.size()];
- Iterator iterator = objectNames.iterator();
- for (int i = 0; i < gbeans.length; i++) {
- ObjectName objectName = (ObjectName) iterator.next();
- try {
- gbeans[i] = kernel.getGBeanData(objectName);
- } catch (Exception e) {
- throw new InvalidConfigException("Unable to serialize GBeanData for " + objectName, e);
- }
- }
-
- // save state
- try {
- gbeanState = storeGBeans(gbeans);
- } catch (InvalidConfigException e) {
- log.info("Unable to update persistent state during shutdown", e);
- }
+ GBeanData[] gbeans = storeCurrentGBeans();
// shutdown the configuration and unload all beans
shutdown();
@@ -440,6 +419,51 @@
return configurationClassLoader;
}
+ public synchronized void addGBean(GBeanData beanData, boolean start) throws InvalidConfigException, GBeanAlreadyExistsException {
+ ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(configurationClassLoader);
+ ObjectName name = loadGBean(beanData, objectNames);
+ if(start) {
+ try {
+ kernel.startRecursiveGBean(name);
+ } catch (GBeanNotFoundException e) {
+ throw new IllegalStateException("How could we not find a GBean that we just loaded ('"+name+"')?");
+ }
+ }
+ } finally {
+ Thread.currentThread().setContextClassLoader(oldCl);
+ }
+ storeCurrentGBeans();
+ }
+
+ public synchronized void removeGBean(ObjectName name) throws GBeanNotFoundException {
+ if(!objectNames.contains(name)) {
+ throw new GBeanNotFoundException(name);
+ }
+ kernel.getDependencyManager().removeDependency(name, this.objectName);
+ try {
+ if(kernel.getGBeanState(name) == State.RUNNING_INDEX) {
+ kernel.stopGBean(name);
+ }
+ kernel.unloadGBean(name);
+ } catch (GBeanNotFoundException e) {
+ // Bean is no longer loaded
+ }
+ objectNames.remove(name);
+ }
+
+ private ObjectName loadGBean(GBeanData beanData, Set objectNames) throws GBeanAlreadyExistsException {
+ ObjectName name = beanData.getName();
+ setGBeanBaseUrl(beanData, baseURL);
+ log.trace("Registering GBean " + name);
+ kernel.loadGBean(beanData, configurationClassLoader);
+ objectNames.add(name);
+ // todo change this to a dependency on the gbeanData itself as soon as we add that feature
+ kernel.getDependencyManager().addDependency(name, this.objectName);
+ return name;
+ }
+
/**
* Load GBeans from the supplied byte array using the supplied ClassLoader
*
@@ -474,6 +498,34 @@
/**
* Return a byte array containing the persisted form of the supplied GBeans
*
+ * @return the persisted GBeans
+ * @throws org.apache.geronimo.kernel.config.InvalidConfigException if there is a problem serializing the state
+ */
+ public synchronized GBeanData[] storeCurrentGBeans() throws InvalidConfigException {
+ // get the gbean data for all gbeans
+ GBeanData[] gbeans = new GBeanData[objectNames.size()];
+ Iterator iterator = objectNames.iterator();
+ for (int i = 0; i < gbeans.length; i++) {
+ ObjectName objectName = (ObjectName) iterator.next();
+ try {
+ gbeans[i] = kernel.getGBeanData(objectName);
+ } catch (Exception e) {
+ throw new InvalidConfigException("Unable to serialize GBeanData for " + objectName, e);
+ }
+ }
+
+ // save state
+ try {
+ gbeanState = storeGBeans(gbeans);
+ } catch (InvalidConfigException e) {
+ log.info("Unable to update persistent state during shutdown", e);
+ }
+ return gbeans;
+ }
+
+ /**
+ * Return a byte array containing the persisted form of the supplied GBeans
+ *
* @param gbeans the gbean data to persist
* @return the persisted GBeans
* @throws org.apache.geronimo.kernel.config.InvalidConfigException if there is a problem serializing the state
@@ -526,6 +578,9 @@
infoFactory.addReference("Parent", ConfigurationParent.class);
infoFactory.addReference("Repositories", Repository.class, "GBean");
infoFactory.addReference("ConfigurationStore", ConfigurationStore.class);
+
+ infoFactory.addOperation("addGBean", new Class[]{GBeanData.class, boolean.class});
+ infoFactory.addOperation("removeGBean", new Class[]{ObjectName.class});
infoFactory.setConstructor(new String[]{
"kernel",
Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/jmx/KernelDelegate.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/jmx/KernelDelegate.java?rev=230585&r1=230584&r2=230585&view=diff
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/jmx/KernelDelegate.java (original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/jmx/KernelDelegate.java Sat Aug 6 13:47:02 2005
@@ -27,6 +27,7 @@
import org.apache.geronimo.gbean.GBeanData;
import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GBeanQuery;
import org.apache.geronimo.kernel.DependencyManager;
import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
import org.apache.geronimo.kernel.GBeanNotFoundException;
@@ -214,6 +215,16 @@
public Set listGBeans(Set patterns) {
try {
return (Set) invokeKernel("listGBeans", new Object[] {patterns}, new String[] {Set.class.getName()});
+ } catch (RuntimeException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new InternalKernelException(e);
+ }
+ }
+
+ public Set listGBeans(GBeanQuery query) {
+ try {
+ return (Set) invokeKernel("listGBeans", new Object[] {query}, new String[] {GBeanQuery.class.getName()});
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/ProxyManager.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/ProxyManager.java?rev=230585&r1=230584&r2=230585&view=diff
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/ProxyManager.java (original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/ProxyManager.java Sat Aug 6 13:47:02 2005
@@ -38,9 +38,11 @@
* will return null.
*
* @param target the target object name
+ * @param loader the ClassLoader used to load the interfaces used by the
+ * proxy
* @return the proxy, or null if the GBeanInfo declares no interfaces
*/
- public Object createProxy(ObjectName target);
+ public Object createProxy(ObjectName target, ClassLoader loader);
/**
* Create proxies for the specified targets. The proxies will implement
@@ -49,11 +51,13 @@
* will return a null in that spot in the array.
*
* @param objectNameStrings An array of ObjectNames, each in String form
+ * @param loader the ClassLoader used to load the interfaces used by the
+ * proxies
* @return an array of proxies of the same length as the argument array,
* where each value is a proxy or null if the corresponding
* GBeanInfo declares no interfaces
*/
- public Object[] createProxies(String[] objectNameStrings) throws MalformedObjectNameException;
+ public Object[] createProxies(String[] objectNameStrings, ClassLoader loader) throws MalformedObjectNameException;
/**
* Create a proxy for the specified target, implementing the specified
Modified: geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/ConfigTest.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/ConfigTest.java?rev=230585&r1=230584&r2=230585&view=diff
==============================================================================
--- geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/ConfigTest.java (original)
+++ geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/ConfigTest.java Sat Aug 6 13:47:02 2005
@@ -91,6 +91,46 @@
assertFalse(kernel.isLoaded(configName));
}
+ public void testAddToConfig() throws Exception {
+ URI id = new URI("test");
+ ObjectName configName = Configuration.getConfigurationObjectName(id);
+
+ // create the config gbean data
+ GBeanData config = new GBeanData(Configuration.getConfigurationObjectName(id), Configuration.GBEAN_INFO);
+ config.setAttribute("id", id);
+ config.setReferencePatterns("Parent", null);
+ config.setAttribute("classPath", Collections.EMPTY_LIST);
+ config.setAttribute("gBeanState", state);
+ config.setAttribute("dependencies", Collections.EMPTY_LIST);
+ config.setName(configName);
+
+ // load and start the config
+ kernel.loadGBean(config, this.getClass().getClassLoader());
+ kernel.startRecursiveGBean(configName);
+
+ assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(configName));
+ assertNotNull(kernel.getAttribute(configName, "configurationClassLoader"));
+
+ ObjectName gbeanName3 = new ObjectName("geronimo.test:name=MyMockGMBean3");
+ try {
+ kernel.getGBeanState(gbeanName3);
+ fail("Gbean should not be found yet");
+ } catch (GBeanNotFoundException e) {
+ }
+ GBeanData mockBean3 = new GBeanData(gbeanName3, MockGBean.getGBeanInfo());
+ mockBean3.setAttribute("value", "1234");
+ mockBean3.setAttribute("name", "child");
+ mockBean3.setAttribute("finalInt", new Integer(1));
+ kernel.invoke(configName, "addGBean", new Object[]{mockBean3,Boolean.TRUE}, new String[]{GBeanData.class.getName(), boolean.class.getName()});
+
+ assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(gbeanName3));
+ assertEquals(new Integer(1), kernel.getAttribute(gbeanName3, "finalInt"));
+ assertEquals("1234", kernel.getAttribute(gbeanName3, "value"));
+ assertEquals("child", kernel.getAttribute(gbeanName3, "name"));
+
+
+ }
+
protected void setUp() throws Exception {
kernel = KernelFactory.newInstance().createKernel("test");
kernel.boot();
Modified: geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/GBeanTest.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/GBeanTest.java?rev=230585&r1=230584&r2=230585&view=diff
==============================================================================
--- geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/GBeanTest.java (original)
+++ geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/GBeanTest.java Sat Aug 6 13:47:02 2005
@@ -89,7 +89,7 @@
kernel.startGBean(name);
ProxyManager mgr = kernel.getProxyManager();
- Object test = mgr.createProxy(name);
+ Object test = mgr.createProxy(name, myCl);
assertTrue(test instanceof MockEndpoint);
assertTrue(test instanceof MockParentInterface1);
assertTrue(test instanceof MockParentInterface2);