geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jboy...@apache.org
Subject svn commit: r154941 - in geronimo/trunk: modules/deployment/src/java/org/apache/geronimo/deployment/ modules/kernel/src/java/org/apache/geronimo/gbean/ modules/kernel/src/java/org/apache/geronimo/gbean/runtime/ modules/kernel/src/java/org/apache/geronimo/kernel/ modules/kernel/src/java/org/apache/geronimo/kernel/jmx/ modules/kernel/src/java/org/apache/geronimo/kernel/registry/ modules/kernel/src/test/org/apache/geronimo/gbean/ modules/system/src/java/org/apache/geronimo/system/main/ plugins/maven-geronimo-plugin/src/java/org/apache/geronimo/deployment/mavenplugin/
Date Wed, 23 Feb 2005 03:23:56 GMT
Author: jboynes
Date: Tue Feb 22 19:23:52 2005
New Revision: 154941

URL: http://svn.apache.org/viewcvs?view=rev&rev=154941
Log:
Change GBean registries to key off GBeanName rather than ObjectName.
To reduce impact, the kernel API is currently unchanged and the kernel
maps names accordingly; this will be removed when the API is updated.

The JMXGBeanRegistry now uses an injected MBeanServer rather than
creating one itself; client code that creates this type of registry
has been updated to create the MBeanServer as well.

The GBeanDataRegistry (which holds GBeanData not GBeanInstance instances)
is no longer a GBeanRegistry but its own class. This is only used by
DeploymentContext.


Modified:
    geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java
    geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/GBeanDataRegistry.java
    geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanName.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/jmx/JMXGBeanRegistry.java
    geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/registry/AbstractGBeanRegistry.java
    geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/registry/BasicGBeanRegistry.java
    geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/registry/GBeanRegistry.java
    geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/gbean/GBeanNameTest.java
    geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/main/Daemon.java
    geronimo/trunk/plugins/maven-geronimo-plugin/src/java/org/apache/geronimo/deployment/mavenplugin/StartServer.java

Modified: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java?view=diff&r1=154940&r2=154941
==============================================================================
--- 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
Tue Feb 22 19:23:52 2005
@@ -113,7 +113,7 @@
             throw new AssertionError();
         }
 
-        gbeans.setDefaultDomain(domain);
+//        gbeans.setDefaultDomain(domain);
 
         if (kernel != null && parentID != null) {
             ConfigurationManager configurationManager = kernel.getConfigurationManager();

Modified: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/GBeanDataRegistry.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/GBeanDataRegistry.java?view=diff&r1=154940&r2=154941
==============================================================================
--- geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/GBeanDataRegistry.java
(original)
+++ geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/GBeanDataRegistry.java
Tue Feb 22 19:23:52 2005
@@ -16,36 +16,34 @@
  */
 package org.apache.geronimo.deployment;
 
-import java.util.Set;
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Iterator;
 import javax.management.ObjectName;
 
 import org.apache.geronimo.gbean.GBeanData;
+import org.apache.geronimo.gbean.GBeanName;
 import org.apache.geronimo.kernel.GBeanNotFoundException;
-import org.apache.geronimo.kernel.registry.AbstractGBeanRegistry;
 
 /**
  * @version $Rev:  $ $Date:  $
  */
-public class GBeanDataRegistry extends AbstractGBeanRegistry {
-
-    public void setDefaultDomain(String defaultDomain) {
-        this.defaultDomainName = defaultDomain;
-    }
+public class GBeanDataRegistry {
+    private final Map registry = new HashMap();
 
     public void preregister(ObjectName name) {
-        register(name, null);
+        registry.put(name, null);
     }
 
     public void register(GBeanData gbean) {
-        register(gbean.getName(), gbean);
+        registry.put(gbean.getName(), gbean);
     }
 
-    public GBeanData getGBeanInstance(ObjectName name) throws GBeanNotFoundException {
-        GBeanData gbeanData;
-        synchronized (this) {
-            gbeanData = (GBeanData) registry.get(name);
-        }
+    public synchronized GBeanData getGBeanInstance(ObjectName name) throws GBeanNotFoundException
{
+        GBeanData gbeanData = (GBeanData) registry.get(name);
         if (gbeanData == null) {
             throw new GBeanNotFoundException(name.getCanonicalName());
         }
@@ -61,4 +59,15 @@
     }
 
 
+    public Set listGBeans(ObjectName pattern) {
+        Set result = new HashSet();
+        for (Iterator i = registry.entrySet().iterator(); i.hasNext();) {
+            Map.Entry entry = (Map.Entry) i.next();
+            ObjectName name = (ObjectName) entry.getKey();
+            if (pattern.apply(name)) {
+                result.add(name);
+            }
+        }
+        return result;
+    }
 }

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanName.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanName.java?view=diff&r1=154940&r2=154941
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanName.java (original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanName.java Tue Feb
22 19:23:52 2005
@@ -19,8 +19,11 @@
 import java.io.Serializable;
 import java.util.Arrays;
 import java.util.HashMap;
+import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.Map;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
 
 
 /**
@@ -180,5 +183,24 @@
 
     private Object readResolve() {
         return new GBeanName(name);
+    }
+
+    // utility methods to support conversion from ObjectName to GBeanName
+
+    /**
+     * @deprecated
+     */
+    public ObjectName getObjectName() throws MalformedObjectNameException {
+        return new ObjectName(domain, new Hashtable(props));
+    }
+
+    /**
+     * @deprecated
+     */
+    public GBeanName(ObjectName name) {
+        this.name = name.toString();
+        this.domain = name.getDomain();
+        this.props = new HashMap(name.getKeyPropertyList());
+        this.hashCode = domain.hashCode() + 37 * props.hashCode();
     }
 }

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?view=diff&r1=154940&r2=154941
==============================================================================
--- 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
Tue Feb 22 19:23:52 2005
@@ -1237,10 +1237,17 @@
 
     }
 
+    public boolean equals(Object obj) {
+        if (obj == this) return true;
+        if (obj instanceof GBeanInstance == false) return false;
+        return objectName.equals(((GBeanInstance)obj).objectName);
+    }
+
+    public int hashCode() {
+        return objectName.hashCode();
+    }
+
     public String toString() {
-        if (objectName == null) {
-            return super.toString();
-        }
         return objectName.toString();
     }
 }

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?view=diff&r1=154940&r2=154941
==============================================================================
--- 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 Tue Feb
22 19:23:52 2005
@@ -37,6 +37,7 @@
 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.runtime.GBeanInstance;
 import org.apache.geronimo.kernel.config.Configuration;
 import org.apache.geronimo.kernel.config.ConfigurationManager;
@@ -290,12 +291,12 @@
     }
 
     public Object getAttribute(ObjectName objectName, String attributeName) throws GBeanNotFoundException,
NoSuchAttributeException, Exception {
-        GBeanInstance gbeanInstance = gbeanRegistry.getGBeanInstance(objectName);
+        GBeanInstance gbeanInstance = gbeanRegistry.getGBeanInstance(new GBeanName(objectName));
         return gbeanInstance.getAttribute(attributeName);
     }
 
     public void setAttribute(ObjectName objectName, String attributeName, Object attributeValue)
throws GBeanNotFoundException, NoSuchAttributeException, Exception {
-        GBeanInstance gbeanInstance = gbeanRegistry.getGBeanInstance(objectName);
+        GBeanInstance gbeanInstance = gbeanRegistry.getGBeanInstance(new GBeanName(objectName));
         gbeanInstance.setAttribute(attributeName, attributeValue);
     }
 
@@ -304,21 +305,21 @@
     }
 
     public Object invoke(ObjectName objectName, String methodName, Object[] args, String[]
types) throws GBeanNotFoundException, NoSuchOperationException, InternalKernelException, Exception
{
-        GBeanInstance gbeanInstance = gbeanRegistry.getGBeanInstance(objectName);
+        GBeanInstance gbeanInstance = gbeanRegistry.getGBeanInstance(new GBeanName(objectName));
         return gbeanInstance.invoke(methodName, args, types);
     }
 
     public boolean isLoaded(ObjectName name) {
-        return gbeanRegistry.isRegistered(name);
+        return gbeanRegistry.isRegistered(new GBeanName(name));
     }
 
     public GBeanInfo getGBeanInfo(ObjectName name) throws GBeanNotFoundException {
-        GBeanInstance gbeanInstance = gbeanRegistry.getGBeanInstance(name);
+        GBeanInstance gbeanInstance = gbeanRegistry.getGBeanInstance(new GBeanName(name));
         return gbeanInstance.getGBeanInfo();
     }
 
     public GBeanData getGBeanData(ObjectName name) throws GBeanNotFoundException, InternalKernelException
{
-        GBeanInstance gbeanInstance = gbeanRegistry.getGBeanInstance(name);
+        GBeanInstance gbeanInstance = gbeanRegistry.getGBeanInstance(new GBeanName(name));
         return gbeanInstance.getGBeanData();
     }
 
@@ -339,28 +340,37 @@
     }
 
     public void startGBean(ObjectName name) throws GBeanNotFoundException, InternalKernelException,
IllegalStateException {
-        GBeanInstance gbeanInstance = gbeanRegistry.getGBeanInstance(name);
+        GBeanInstance gbeanInstance = gbeanRegistry.getGBeanInstance(new GBeanName(name));
         gbeanInstance.start();
     }
 
     public void startRecursiveGBean(ObjectName name) throws GBeanNotFoundException, InternalKernelException,
IllegalStateException {
-        GBeanInstance gbeanInstance = gbeanRegistry.getGBeanInstance(name);
+        GBeanInstance gbeanInstance = gbeanRegistry.getGBeanInstance(new GBeanName(name));
         gbeanInstance.startRecursive();
     }
 
     public void stopGBean(ObjectName name) throws GBeanNotFoundException, InternalKernelException,
IllegalStateException {
-        GBeanInstance gbeanInstance = gbeanRegistry.getGBeanInstance(name);
+        GBeanInstance gbeanInstance = gbeanRegistry.getGBeanInstance(new GBeanName(name));
         gbeanInstance.stop();
     }
 
     public void unloadGBean(ObjectName name) throws GBeanNotFoundException, InternalKernelException,
IllegalStateException {
-        GBeanInstance gbeanInstance = gbeanRegistry.getGBeanInstance(name);
+        GBeanName gbeanName = new GBeanName(name);
+        GBeanInstance gbeanInstance = gbeanRegistry.getGBeanInstance(gbeanName);
         gbeanInstance.die();
-        gbeanRegistry.unregister(name);
+        gbeanRegistry.unregister(gbeanName);
     }
 
     public Set listGBeans(ObjectName pattern) {
-        return gbeanRegistry.listGBeans(pattern);
+        String domain = (pattern == null || pattern.isDomainPattern()) ? null : pattern.getDomain();
+        Map props = pattern == null ? null : pattern.getKeyPropertyList();
+        Set gbeans = gbeanRegistry.listGBeans(domain, props);
+        Set result = new HashSet(gbeans.size());
+        for (Iterator i = gbeans.iterator(); i.hasNext();) {
+            GBeanInstance instance = (GBeanInstance) i.next();
+            result.add(instance.getObjectNameObject());
+        }
+        return result;
     }
 
     public Set listGBeans(Set patterns) {
@@ -408,7 +418,7 @@
         GBeanInstance gbeanInstance = null;
         try {
             ObjectName configName = Configuration.getConfigurationObjectName(configID);
-            gbeanInstance = gbeanRegistry.getGBeanInstance(configName);
+            gbeanInstance = gbeanRegistry.getGBeanInstance(new GBeanName(configName));
         } catch (MalformedObjectNameException e) {
             throw new NoSuchConfigException(e);
         } catch (GBeanNotFoundException e) {
@@ -537,7 +547,7 @@
                 // ignore
             }
             try {
-                gbeanRegistry.unregister(CONFIGURATION_MANAGER_NAME);
+                gbeanRegistry.unregister(new GBeanName(CONFIGURATION_MANAGER_NAME));
             } catch (Exception e) {
                 // ignore
             }
@@ -550,7 +560,7 @@
     }
 
     public ClassLoader getClassLoaderFor(ObjectName name) throws GBeanNotFoundException {
-        GBeanInstance gbeanInstance = gbeanRegistry.getGBeanInstance(name);
+        GBeanInstance gbeanInstance = gbeanRegistry.getGBeanInstance(new GBeanName(name));
         return gbeanInstance.getClassLoader();
     }
 

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/jmx/JMXGBeanRegistry.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/jmx/JMXGBeanRegistry.java?view=diff&r1=154940&r2=154941
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/jmx/JMXGBeanRegistry.java
(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/jmx/JMXGBeanRegistry.java
Tue Feb 22 19:23:52 2005
@@ -17,106 +17,94 @@
 package org.apache.geronimo.kernel.jmx;
 
 import java.util.HashMap;
-import java.util.Set;
+import java.util.Iterator;
 import javax.management.InstanceAlreadyExistsException;
 import javax.management.InstanceNotFoundException;
 import javax.management.JMException;
 import javax.management.JMRuntimeException;
 import javax.management.MBeanInfo;
 import javax.management.MBeanServer;
-import javax.management.MBeanServerFactory;
 import javax.management.ObjectName;
 
+import org.apache.geronimo.gbean.GBeanName;
 import org.apache.geronimo.gbean.runtime.GBeanInstance;
 import org.apache.geronimo.gbean.runtime.LifecycleBroadcaster;
 import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
 import org.apache.geronimo.kernel.GBeanNotFoundException;
-import org.apache.geronimo.kernel.registry.GBeanRegistry;
 import org.apache.geronimo.kernel.InternalKernelException;
 import org.apache.geronimo.kernel.Kernel;
 import org.apache.geronimo.kernel.lifecycle.LifecycleListener;
+import org.apache.geronimo.kernel.registry.AbstractGBeanRegistry;
 
 /**
+ * An implementation of GBeanRegistry that also registers the GBeans with a JMX MBeanServer.
+ *
  * @version $Rev$ $Date$
  */
-public class JMXGBeanRegistry implements GBeanRegistry {
+public class JMXGBeanRegistry extends AbstractGBeanRegistry {
     private final HashMap registry = new HashMap();
     private Kernel kernel;
-    private MBeanServer mbServer;
+    private final MBeanServer mbServer;
+
+    public JMXGBeanRegistry(MBeanServer mbServer) {
+        this.mbServer = mbServer;
+    }
 
     public void start(Kernel kernel) {
+        super.start(kernel);
         this.kernel = kernel;
-        mbServer = MBeanServerFactory.createMBeanServer(kernel.getKernelName());
     }
 
-    public void stop() {
-        MBeanServerFactory.releaseMBeanServer(mbServer);
+    public synchronized void stop() {
+        this.kernel = null;
 
-        // todo destroy instances
-        synchronized(this) {
-            registry.clear();
+        // unregister all our GBean from the MBeanServer
+        for (Iterator i = registry.keySet().iterator(); i.hasNext();) {
+            GBeanName name = (GBeanName) i.next();
+            try {
+                mbServer.unregisterMBean(name.getObjectName());
+            } catch (Exception e) {
+                // ignore
+            }
         }
+        super.stop();
     }
 
-    public MBeanServer getMBeanServer() {
-        return mbServer;
-    }
-
-    public synchronized boolean isRegistered(ObjectName name) {
-        return registry.containsKey(name);
-    }
-
-    public void register(GBeanInstance gbeanInstance) throws GBeanAlreadyExistsException,
InternalKernelException {
+    public void register(GBeanInstance gbeanInstance) throws GBeanAlreadyExistsException
{
+        // create an MBean to wrap the plain GBean
         ObjectName name = gbeanInstance.getObjectNameObject();
         MBeanInfo mbeanInfo = JMXUtil.toMBeanInfo(gbeanInstance.getGBeanInfo());
         GBeanMBean gbeanMBean = new GBeanMBean(kernel, name, mbeanInfo);
+
+        // register the MBean with the JMX MBeanServer
         try {
             mbServer.registerMBean(gbeanMBean, name);
         } catch (InstanceAlreadyExistsException e) {
-            throw new GBeanAlreadyExistsException("A GBean is alreayd registered witht then
name " + name);
+            throw new GBeanAlreadyExistsException("An MBean is already registered under the
name " + name);
         } catch (Exception e) {
             throw new InternalKernelException("Error loading GBean " + name.getCanonicalName(),
unwrapJMException(e));
         }
 
-        synchronized (this) {
-            registry.put(name, gbeanInstance);
-        }
+        super.register(gbeanInstance);
 
+        // todo when can we get rid if this?
+        // fire the loaded event from the gbeanMBean.. it was already fired from the GBeanInstance
when it was created
         kernel.getLifecycleMonitor().addLifecycleListener(new LifecycleBridge(gbeanMBean),
name);
-
-        // fire the loaded event from the gbeanMBean.. it was already fired from
-        // the GBeanInstance when it was created
-        gbeanMBean.fireLoadedEvent();        
+        gbeanMBean.fireLoadedEvent();
     }
 
-    public void unregister(ObjectName name) throws GBeanNotFoundException, InternalKernelException
{
+    public void unregister(GBeanName name) throws GBeanNotFoundException, InternalKernelException
{
         try {
-             mbServer.unregisterMBean(name);
+            ObjectName objectName = name.getObjectName();
+            mbServer.unregisterMBean(objectName);
         } catch (InstanceNotFoundException e) {
-            throw new GBeanNotFoundException(name.getCanonicalName());
+            // ignore - something else may have unregistered us
+            // if there truely is no GBean then we will catch it below whwn we call the superclass
         } catch (Exception e) {
             throw new InternalKernelException("Error unloading GBean " + name, unwrapJMException(e));
         }
 
-        synchronized (this) {
-            registry.remove(name);
-        }
-    }
-
-    public synchronized GBeanInstance getGBeanInstance(ObjectName name) throws GBeanNotFoundException
{
-        GBeanInstance gbeanInstance = (GBeanInstance) registry.get(name);
-        if (gbeanInstance == null) {
-            throw new GBeanNotFoundException(name.getCanonicalName());
-        }
-        return gbeanInstance;
-    }
-
-    public Set listGBeans(ObjectName pattern) throws InternalKernelException {
-        try {
-            return mbServer.queryNames(pattern, null);
-        } catch (RuntimeException e) {
-            throw new InternalKernelException("Error while applying pattern " + pattern,
e);
-        }
+        super.unregister(name);
     }
 
     private Throwable unwrapJMException(Throwable cause) {

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/registry/AbstractGBeanRegistry.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/registry/AbstractGBeanRegistry.java?view=diff&r1=154940&r2=154941
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/registry/AbstractGBeanRegistry.java
(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/registry/AbstractGBeanRegistry.java
Tue Feb 22 19:23:52 2005
@@ -16,196 +16,74 @@
  */
 package org.apache.geronimo.kernel.registry;
 
-import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.regex.Pattern;
 import javax.management.ObjectName;
 
+import org.apache.geronimo.gbean.GBeanName;
+import org.apache.geronimo.gbean.runtime.GBeanInstance;
+import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
 import org.apache.geronimo.kernel.GBeanNotFoundException;
 import org.apache.geronimo.kernel.InternalKernelException;
+import org.apache.geronimo.kernel.Kernel;
 
 /**
- * @version $Rev:  $ $Date:  $
+ * @version $Rev$ $Date$
  */
-public class AbstractGBeanRegistry {
+public abstract class AbstractGBeanRegistry implements GBeanRegistry {
     protected final Map registry = new HashMap();
-    protected final Map domainIndex = new HashMap();
-    protected String defaultDomainName;
 
-    public void stop() {
-        // todo destroy instances
-        synchronized (this) {
-            registry.clear();
-            domainIndex.clear();
-        }
+    public void start(Kernel kernel) {
     }
 
-    public boolean isRegistered(ObjectName name) {
-        synchronized (this) {
-            return registry.containsKey(name);
-        }
+    public synchronized void stop() {
+        registry.clear();
     }
 
-    protected void register(ObjectName name, Object gbean) {
-        // do as much work as possible outside of the synchronized block
-        String domainName = name.getDomain();
-        // convert properties list to a HashMap as it is more efficient then the synchronized
Hashtable
-        Map properties = new HashMap(name.getKeyPropertyList());
-
-        synchronized (this) {
-            registry.put(name, gbean);
-
-            Map nameToProperties = (Map) domainIndex.get(domainName);
-            if (nameToProperties == null) {
-                nameToProperties = new HashMap();
-                domainIndex.put(domainName, nameToProperties);
-            }
-            nameToProperties.put(name, properties);
-        }
+    public synchronized boolean isRegistered(GBeanName name) {
+        return registry.containsKey(name);
     }
 
-    public void unregister(ObjectName name) throws GBeanNotFoundException, InternalKernelException
{
-        String domainName = name.getDomain();
-        synchronized (this) {
-            registry.remove(name);
-
-            // just leave the an empty nameToProperty map
-            Map nameToProperties = (Map) domainIndex.get(domainName);
-            if (nameToProperties != null) {
-                nameToProperties.remove(name);
-            }
+    public synchronized void register(GBeanInstance gbeanInstance) throws GBeanAlreadyExistsException
{
+        ObjectName objectName = gbeanInstance.getObjectNameObject();
+        GBeanName name = new GBeanName(objectName);
+        if (registry.containsKey(name)) {
+            throw new GBeanAlreadyExistsException("GBean already registered: " + name);
         }
+        registry.put(name, gbeanInstance);
     }
 
-    public Set listGBeans(ObjectName pattern) throws InternalKernelException {
-        if (pattern == null) {
-            synchronized (this) {
-                return new HashSet(registry.keySet());
-            }
-        }
-
-        String patternDomain = pattern.getDomain();
-        if (patternDomain.length() == 0) {
-            patternDomain = defaultDomainName;
-        }
-
-        // work with a copy of the registry key set
-        List nameToProperties;
-        if (!pattern.isDomainPattern()) {
-            synchronized (this) {
-                // create an array list big enough to match all names... extra space is better
than resizing
-                nameToProperties = new ArrayList(registry.size());
-
-                // find we are only matching one specific domain, so
-                // just grab it directly from the index
-                Map map = (Map) domainIndex.get(patternDomain);
-                if (map != null) {
-                    nameToProperties.addAll(map.entrySet());
-                }
-            }
-        } else if (patternDomain.equals("*")) {
-            // this is very commmon, so support it directly
-            synchronized (this) {
-                // create an array list big enough to match all names... extra space is better
than resizing
-                nameToProperties = new ArrayList(registry.size());
-
-                // find we are matching all domain, so just grab all of them directly
-                for (Iterator iterator = domainIndex.values().iterator(); iterator.hasNext();)
{
-                    Map map = (Map) iterator.next();
-
-                    // we can just copy the entry set directly into the list we don't
-                    // have to worry about duplicates as the maps are mutually exclusive
-                    nameToProperties.addAll(map.entrySet());
-                }
-            }
-        } else {
-            String perl5Pattern = domainPatternToPerl5(patternDomain);
-            Pattern domainPattern = Pattern.compile(perl5Pattern);
-
-            synchronized (this) {
-                // create an array list big enough to match all names... extra space is better
than resizing
-                nameToProperties = new ArrayList(registry.size());
-
-                // find all of the matching domains
-                for (Iterator iterator = domainIndex.entrySet().iterator(); iterator.hasNext();)
{
-                    Map.Entry entry = (Map.Entry) iterator.next();
-                    String domain = (String) entry.getKey();
-                    if (domainPattern.matcher(domain).matches()) {
-                        // we can just copy the entry set directly into the list we don't
-                        // have to worry about duplicates as the maps are mutually exclusive
-                        Map map = (Map) entry.getValue();
-                        nameToProperties.addAll(map.entrySet());
-                    }
-                }
-            }
-        }
-
-        if (nameToProperties.isEmpty()) {
-            return Collections.EMPTY_SET;
+    public synchronized void unregister(GBeanName name) throws GBeanNotFoundException, InternalKernelException
{
+        if (registry.remove(name) == null) {
+            throw new GBeanNotFoundException("No GBean registered: " + name);
         }
+    }
 
-        // convert the pattern property list to a HashMap as it is not synchronized
-        Map patternProperties = new HashMap(pattern.getKeyPropertyList());
-        patternProperties.remove("*");
-        boolean isMatchAll = patternProperties.isEmpty();
-        boolean isPropertyPattern = pattern.isPropertyPattern();
-
-        Set matchingNames = new HashSet();
-        for (Iterator iterator = nameToProperties.iterator(); iterator.hasNext();) {
-            Map.Entry entry = (Map.Entry) iterator.next();
-            Map properties = (Map) entry.getValue();
-
-            if (isMatchAll) {
-                matchingNames.add(entry.getKey());
-            } else if (isPropertyPattern) {
-                if (properties.entrySet().containsAll(patternProperties.entrySet())) {
-                    matchingNames.add(entry.getKey());
-                }
-
-            } else {
-                if (properties.entrySet().equals(patternProperties.entrySet())) {
-                    matchingNames.add(entry.getKey());
-                }
-            }
+    public synchronized GBeanInstance getGBeanInstance(GBeanName name) throws GBeanNotFoundException
{
+        GBeanInstance instance = (GBeanInstance) registry.get(name);
+        if (instance == null) {
+            throw new GBeanNotFoundException("No GBean registered: " + name);
         }
-        return matchingNames;
+        return instance;
     }
 
-    private static String domainPatternToPerl5(String pattern) {
-        char[] patternCharacters = pattern.toCharArray();
-        StringBuffer buffer = new StringBuffer(2 * patternCharacters.length);
-        for (int position = 0; position < patternCharacters.length; position++) {
-            char character = patternCharacters[position];
-            switch (character) {
-                case '*':
-                    // replace '*' with '.*'
-                    buffer.append(".*");
-                    break;
-                case '?':
-                    // replace '?' with '.'
-                    buffer.append('.');
-                    break;
-                default:
-                    // escape any perl5 characters with '\'
-                    if (isPerl5MetaCharacter(character)) {
-                        buffer.append('\\');
-                    }
-                    buffer.append(character);
-                    break;
+    public Set listGBeans(String domain, Map properties) {
+        // fairly dumb implementation that iterates the list of all registered GBeans
+        Map clone;
+        synchronized(this) {
+            clone = new HashMap(registry);
+        }
+        Set result = new HashSet(clone.size());
+        for (Iterator i = clone.entrySet().iterator(); i.hasNext();) {
+            Map.Entry entry = (Map.Entry) i.next();
+            GBeanName name = (GBeanName) entry.getKey();
+            if (name.matches(domain, properties)) {
+                result.add(entry.getValue());
             }
         }
-
-        return buffer.toString();
+        return result;
     }
-
-    private static boolean isPerl5MetaCharacter(char character) {
-        return ("'*?+[]()|^$.{}\\".indexOf(character) >= 0);
-    }
-
 }

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/registry/BasicGBeanRegistry.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/registry/BasicGBeanRegistry.java?view=diff&r1=154940&r2=154941
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/registry/BasicGBeanRegistry.java
(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/registry/BasicGBeanRegistry.java
Tue Feb 22 19:23:52 2005
@@ -19,6 +19,7 @@
 import javax.management.ObjectName;
 
 import org.apache.geronimo.gbean.runtime.GBeanInstance;
+import org.apache.geronimo.gbean.GBeanName;
 import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
 import org.apache.geronimo.kernel.GBeanNotFoundException;
 import org.apache.geronimo.kernel.InternalKernelException;
@@ -27,27 +28,5 @@
 /**
  * @version $Rev$ $Date$
  */
-public class BasicGBeanRegistry extends AbstractGBeanRegistry implements GBeanRegistry {
-
-    public void start(Kernel kernel) {
-        this.defaultDomainName = kernel.getKernelName();
-    }
-
-    public void register(GBeanInstance gbeanInstance) throws GBeanAlreadyExistsException,
InternalKernelException {
-        ObjectName name = gbeanInstance.getObjectNameObject();
-        register(name, gbeanInstance);
-
-    }
-
-    public GBeanInstance getGBeanInstance(ObjectName name) throws GBeanNotFoundException
{
-        GBeanInstance gbeanInstance;
-        synchronized (this) {
-            gbeanInstance = (GBeanInstance) registry.get(name);
-        }
-        if (gbeanInstance == null) {
-            throw new GBeanNotFoundException(name.getCanonicalName());
-        }
-        return gbeanInstance;
-    }
-
+public class BasicGBeanRegistry extends AbstractGBeanRegistry {
 }

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/registry/GBeanRegistry.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/registry/GBeanRegistry.java?view=diff&r1=154940&r2=154941
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/registry/GBeanRegistry.java
(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/registry/GBeanRegistry.java
Tue Feb 22 19:23:52 2005
@@ -17,29 +17,71 @@
 package org.apache.geronimo.kernel.registry;
 
 import java.util.Set;
+import java.util.Map;
 import javax.management.ObjectName;
 
+import org.apache.geronimo.gbean.GBeanName;
 import org.apache.geronimo.gbean.runtime.GBeanInstance;
-import org.apache.geronimo.kernel.Kernel;
 import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
-import org.apache.geronimo.kernel.InternalKernelException;
 import org.apache.geronimo.kernel.GBeanNotFoundException;
+import org.apache.geronimo.kernel.Kernel;
 
 /**
+ * Interface implemented by Registries that a Kernel can use to store and retrieve GBeanInstances.
  * @version $Rev$ $Date$
  */
 public interface GBeanRegistry {
+    /**
+     * Start the registry and associate it with a kernel.
+     *
+     * @param kernel the kernel to associate with
+     */
     void start(Kernel kernel);
 
+    /**
+     * Shut down the registry and unregister any GBeans
+     */
     void stop();
 
-    boolean isRegistered(ObjectName name);
-
-    void register(GBeanInstance gbeanInstance) throws GBeanAlreadyExistsException, InternalKernelException;
-
-    void unregister(ObjectName name) throws GBeanNotFoundException, InternalKernelException;
-
-    GBeanInstance getGBeanInstance(ObjectName name) throws GBeanNotFoundException;
-
-    Set listGBeans(ObjectName pattern) throws InternalKernelException;
+    /**
+     * See if there is a GBean registered with a specific name.
+     *
+     * @param name the name of the GBean to check for
+     * @return true if there is a GBean registered with that name
+     */
+    boolean isRegistered(GBeanName name);
+
+    /**
+     * Register a GBean instance.
+     *
+     * @param gbeanInstance the GBean to register
+     * @throws GBeanAlreadyExistsException if there is already a GBean registered with the
instance's name
+     */
+    void register(GBeanInstance gbeanInstance) throws GBeanAlreadyExistsException;
+
+    /**
+     * Unregister a GBean instance.
+     *
+     * @param name the name of the GBean to unregister
+     * @throws GBeanNotFoundException if there is no GBean registered with the supplied name
+     */
+    void unregister(GBeanName name) throws GBeanNotFoundException;
+
+    /**
+     * Return the GBeanInstance registered with the supplied name.
+     *
+     * @param name the name of the instance to return
+     * @return the GBeanInstance
+     * @throws GBeanNotFoundException if there is no GBean registered with the supplied name
+     */
+    GBeanInstance getGBeanInstance(GBeanName name) throws GBeanNotFoundException;
+
+    /**
+     * Search the registry for GBeans matching a name pattern.
+     *
+     * @param domain the domain to query in; null indicates all
+     * @param properties the properties the GBeans must have
+     * @return an unordered Set<GBeanInstance> of GBeans that matched the pattern
+     */
+    Set listGBeans(String domain, Map properties);
 }

Modified: geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/gbean/GBeanNameTest.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/gbean/GBeanNameTest.java?view=diff&r1=154940&r2=154941
==============================================================================
--- geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/gbean/GBeanNameTest.java (original)
+++ geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/gbean/GBeanNameTest.java Tue
Feb 22 19:23:52 2005
@@ -67,7 +67,7 @@
 
     public void testInvalidNames() {
         try {
-            new GBeanName(null);
+            new GBeanName((String) null);
             fail();
         } catch (NullPointerException e) {
         }

Modified: geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/main/Daemon.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/main/Daemon.java?view=diff&r1=154940&r2=154941
==============================================================================
--- geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/main/Daemon.java (original)
+++ geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/main/Daemon.java Tue
Feb 22 19:23:52 2005
@@ -27,6 +27,7 @@
 import java.util.List;
 import java.util.Set;
 import javax.management.ObjectName;
+import javax.management.MBeanServerFactory;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -132,7 +133,7 @@
             }
 
             // build a jms kernel
-            final Kernel kernel = new Kernel("geronimo", new JMXGBeanRegistry());
+            final Kernel kernel = new Kernel("geronimo", new JMXGBeanRegistry(MBeanServerFactory.createMBeanServer("geronimo")));
 
             // boot the kernel
             try {

Modified: geronimo/trunk/plugins/maven-geronimo-plugin/src/java/org/apache/geronimo/deployment/mavenplugin/StartServer.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/plugins/maven-geronimo-plugin/src/java/org/apache/geronimo/deployment/mavenplugin/StartServer.java?view=diff&r1=154940&r2=154941
==============================================================================
--- geronimo/trunk/plugins/maven-geronimo-plugin/src/java/org/apache/geronimo/deployment/mavenplugin/StartServer.java
(original)
+++ geronimo/trunk/plugins/maven-geronimo-plugin/src/java/org/apache/geronimo/deployment/mavenplugin/StartServer.java
Tue Feb 22 19:23:52 2005
@@ -26,9 +26,11 @@
 import java.util.List;
 import java.util.StringTokenizer;
 import javax.management.ObjectName;
+import javax.management.MBeanServerFactory;
 
 import org.apache.geronimo.gbean.GBeanData;
 import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.registry.BasicGBeanRegistry;
 import org.apache.geronimo.kernel.jmx.JMXGBeanRegistry;
 import org.apache.geronimo.kernel.config.ConfigurationManager;
 import org.apache.geronimo.kernel.log.GeronimoLogging;
@@ -106,7 +108,7 @@
         }
 
         // build a basic kernel without a configuration-store, our configuration store is
-        Kernel kernel = new Kernel(getKernelName(), new JMXGBeanRegistry());
+        Kernel kernel = new Kernel(getKernelName(), new BasicGBeanRegistry());
         kernel.boot();
 
         ConfigurationManager configurationManager = kernel.getConfigurationManager();



Mime
View raw message