adc 2004/02/03 21:42:58
Modified: modules/kernel/src/java/org/apache/geronimo Geronimo.java
modules/kernel/src/java/org/apache/geronimo/kernel
Kernel.java KernelMBean.java
modules/kernel/src/java/org/apache/geronimo/kernel/config
Run.java
modules/kernel/src/test/org/apache/geronimo/kernel
BootstrapTest.java ConfigTest.java GBeanTest.java
Log:
Added a kernel name to the Kernel and a way of retrieving
a Kernel by that name
Revision Changes Path
1.6 +2 -2
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/Geronimo.java
Index: Geronimo.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/Geronimo.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Geronimo.java 29 Jan 2004 14:00:12 -0000 1.5
+++ Geronimo.java 4 Feb 2004 05:42:57 -0000 1.6
@@ -143,7 +143,7 @@
}
}
- final Kernel kernel = new Kernel(domain,
LocalConfigStore.GBEAN_INFO, storeDir);
+ final Kernel kernel = new Kernel("geronimo.kernel", domain,
LocalConfigStore.GBEAN_INFO, storeDir);
Runtime.getRuntime().addShutdownHook(new Thread("Shutdown Thread") {
public void run() {
kernel.shutdown();
1.13 +55 -17
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.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- Kernel.java 26 Jan 2004 18:02:15 -0000 1.12
+++ Kernel.java 4 Feb 2004 05:42:57 -0000 1.13
@@ -55,39 +55,38 @@
*/
package org.apache.geronimo.kernel;
-import java.io.File;
-import java.io.IOException;
-import java.io.Serializable;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-
+import javax.management.InstanceAlreadyExistsException;
import javax.management.InstanceNotFoundException;
import javax.management.ListenerNotFoundException;
+import javax.management.MBeanException;
import javax.management.MBeanNotificationInfo;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.MalformedObjectNameException;
+import javax.management.NotCompliantMBeanException;
import javax.management.NotificationBroadcaster;
import javax.management.NotificationFilter;
import javax.management.NotificationListener;
import javax.management.ObjectName;
-import javax.management.InstanceAlreadyExistsException;
-import javax.management.NotCompliantMBeanException;
-import javax.management.MBeanException;
import javax.management.ReflectionException;
+import java.io.File;
+import java.io.IOException;
+import java.io.Serializable;
+import java.net.URI;
+import java.net.URL;
+import java.util.Hashtable;
+import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.jmx.DependencyService;
import org.apache.geronimo.gbean.jmx.GBeanMBean;
import org.apache.geronimo.kernel.config.ConfigurationStore;
import org.apache.geronimo.kernel.config.InvalidConfigException;
-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.gbean.jmx.DependencyService;
/**
* The core of a Geronimo instance.
@@ -125,6 +124,8 @@
*/
public static final ObjectName CONFIG_STORE =
JMXUtil.getObjectName("geronimo.boot:role=ConfigurationStore");
+ private static final Map kernels = new Hashtable();
+ private final String kernelName;
private final String domainName;
private final GBeanInfo storeInfo;
private final File configStore;
@@ -138,23 +139,28 @@
/**
* Construct a Kernel using the specified JMX domain and supply the
* information needed to create the ConfigurationStore.
+ * @param kernelName the name of the kernel that uniquely indentifies
the kernel in a VM
* @param domainName the domain name to be used for the JMX MBeanServer
* @param storeInfo the info for the GBeanMBean to be used for the
ConfigurationStore
* @param configStore a local directory to be used by the
ConfigurationStore;
* this must be present and writable when the kernel
is booted
*/
- public Kernel(String domainName, GBeanInfo storeInfo, File configStore) {
+ public Kernel(String kernelName, String domainName, GBeanInfo storeInfo,
File configStore) {
+ this.kernelName = kernelName;
this.domainName = domainName;
this.storeInfo = storeInfo;
this.configStore = configStore;
+
+ kernels.put(kernelName, this);
}
/**
* Construct a Kernel which does not have a config store.
- * @param domainName
+ * @param kernelName the name of the kernel that uniquely indentifies
the kernel in a VM
+ * @param domainName the domain name to be used for the JMX MBeanServer
*/
- public Kernel(String domainName) {
- this(domainName, null, null);
+ public Kernel(String kernelName, String domainName) {
+ this(kernelName, domainName, null, null);
}
/**
@@ -163,6 +169,38 @@
*/
public MBeanServer getMBeanServer() {
return mbServer;
+ }
+
+ /**
+ * Get the name of this kernel
+ * @return the name of this kernel
+ */
+ public String getKernelName() {
+ return kernelName;
+ }
+
+ /**
+ * Get a particular kernel indexed by a name
+ * @param name the name of the kernel to be obtained
+ * @return the kernel that was registered with that name
+ */
+ public static Kernel getKernel(String name) {
+ return (Kernel) kernels.get(name);
+ }
+
+ /**
+ * Obtain the single kernel that's registered.
+ *
+ * <p>This method assumes that there is only one kernel registered and
will throw an
+ * <code>IllegalStateException</code> if more than one has been
registered.
+ * @return the single kernel that's registered
+ * @throws IllegalStateException if more than one
+ */
+ public static Kernel getSingleKernel() {
+ int size = kernels.size();
+ if (size > 1) throw new IllegalStateException("More than one kernel
has been registered.");
+ if (size < 1) return null;
+ return (Kernel) kernels.values().iterator().next();
}
public static ObjectName getConfigObjectName(URI configID) throws
MalformedObjectNameException {
1.3 +3 -1
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/KernelMBean.java
Index: KernelMBean.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/KernelMBean.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- KernelMBean.java 14 Jan 2004 22:16:38 -0000 1.2
+++ KernelMBean.java 4 Feb 2004 05:42:57 -0000 1.3
@@ -73,6 +73,8 @@
public interface KernelMBean {
public MBeanServer getMBeanServer();
+ public String getKernelName();
+
public ObjectName load(GBeanMBean config, URL baseURL) throws
InvalidConfigException;
public void unload(ObjectName configName) throws NoSuchConfigException;
1.2 +2 -2
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/Run.java
Index: Run.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/Run.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Run.java 30 Jan 2004 20:11:18 -0000 1.1
+++ Run.java 4 Feb 2004 05:42:57 -0000 1.2
@@ -91,7 +91,7 @@
throw new AssertionError();
}
- final Kernel kernel = new Kernel("geronimo");
+ final Kernel kernel = new Kernel("geronimo.kernel", "geronimo");
try {
kernel.boot();
1.3 +3 -3
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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BootstrapTest.java 14 Jan 2004 08:31:07 -0000 1.2
+++ BootstrapTest.java 4 Feb 2004 05:42:57 -0000 1.3
@@ -77,13 +77,13 @@
private GBeanInfo storeInfo;
public void testCreate() throws Exception {
- Kernel kernel = new Kernel("geronimo", storeInfo, configRoot);
+ Kernel kernel = new Kernel("test.kernel", "geronimo", storeInfo,
configRoot);
kernel.boot();
kernel.shutdown();
}
public void testPersist() throws Exception {
- Kernel kernel = new Kernel("geronimo", storeInfo, configRoot);
+ Kernel kernel = new Kernel("test.kernel", "geronimo", storeInfo,
configRoot);
kernel.boot();
ObjectOutputStream oos = new ObjectOutputStream(new
FileOutputStream(kernelState));
oos.writeObject(kernel);
1.10 +2 -2
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.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- ConfigTest.java 25 Jan 2004 21:07:04 -0000 1.9
+++ ConfigTest.java 4 Feb 2004 05:42:57 -0000 1.10
@@ -150,7 +150,7 @@
storeInfo = LocalConfigStore.getGBeanInfo();
configRoot.mkdir();
- kernel = new Kernel("geronimo", storeInfo, configRoot);
+ kernel = new Kernel("test.kernel", "geronimo", storeInfo,
configRoot);
kernel.boot();
mbServer = kernel.getMBeanServer();
1.5 +2 -2
incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel/GBeanTest.java
Index: GBeanTest.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel/GBeanTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- GBeanTest.java 25 Jan 2004 21:07:04 -0000 1.4
+++ GBeanTest.java 4 Feb 2004 05:42:57 -0000 1.5
@@ -105,7 +105,7 @@
protected void setUp() throws Exception {
name = new ObjectName("test:name=MyMockGBean");
name2 = new ObjectName("test:name=MyMockGBean2");
- kernel = new Kernel("test");
+ kernel = new Kernel("test.kernel", "test");
kernel.boot();
}