You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by da...@apache.org on 2006/04/21 01:21:17 UTC

svn commit: r395730 - in /geronimo/branches/1.1/modules/kernel/src: java/org/apache/geronimo/gbean/ java/org/apache/geronimo/kernel/basic/ test/org/apache/geronimo/gbean/

Author: dain
Date: Thu Apr 20 16:21:15 2006
New Revision: 395730

URL: http://svn.apache.org/viewcvs?rev=395730&view=rev
Log:
GERONIMO-1809 Remove GBeanName

Removed:
    geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanName.java
    geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/gbean/GBeanNameTest.java
Modified:
    geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicKernel.java
    geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicRegistry.java

Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicKernel.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicKernel.java?rev=395730&r1=395729&r2=395730&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicKernel.java (original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicKernel.java Thu Apr 20 16:21:15 2006
@@ -21,14 +21,13 @@
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedList;
-import java.util.Map;
 import java.util.Set;
 import javax.management.ObjectName;
+
 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.AbstractNameQuery;
 import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.gbean.runtime.GBeanInstance;
@@ -170,7 +169,7 @@
     }
 
     public Object getAttribute(ObjectName objectName, String attributeName) throws GBeanNotFoundException, NoSuchAttributeException, Exception {
-        GBeanInstance gbeanInstance = registry.getGBeanInstance(createGBeanName(objectName));
+        GBeanInstance gbeanInstance = registry.getGBeanInstance(objectName);
         return gbeanInstance.getAttribute(attributeName);
     }
 
@@ -193,7 +192,7 @@
     }
 
     public void setAttribute(ObjectName objectName, String attributeName, Object attributeValue) throws GBeanNotFoundException, NoSuchAttributeException, Exception {
-        GBeanInstance gbeanInstance = registry.getGBeanInstance(createGBeanName(objectName));
+        GBeanInstance gbeanInstance = registry.getGBeanInstance(objectName);
         gbeanInstance.setAttribute(attributeName, attributeValue);
     }
 
@@ -236,7 +235,7 @@
     }
 
     public Object invoke(ObjectName objectName, String methodName, Object[] args, String[] types) throws GBeanNotFoundException, NoSuchOperationException, InternalKernelException, Exception {
-        GBeanInstance gbeanInstance = registry.getGBeanInstance(createGBeanName(objectName));
+        GBeanInstance gbeanInstance = registry.getGBeanInstance(objectName);
         return gbeanInstance.invoke(methodName, args, types);
     }
 
@@ -259,7 +258,7 @@
     }
 
     public boolean isLoaded(ObjectName name) {
-        return registry.isRegistered(createGBeanName(name));
+        return registry.isRegistered(name);
     }
 
     public boolean isLoaded(AbstractName name) {
@@ -301,7 +300,7 @@
     }
 
     public Object getGBean(ObjectName name) throws GBeanNotFoundException, InternalKernelException, IllegalStateException  {
-        GBeanInstance gbeanInstance = registry.getGBeanInstance(createGBeanName(name));
+        GBeanInstance gbeanInstance = registry.getGBeanInstance(name);
         if (gbeanInstance.getState() != State.RUNNING_INDEX) {
             throw new IllegalStateException("GBean is not running: " + name);
         }
@@ -317,7 +316,7 @@
     }
 
     public GBeanInfo getGBeanInfo(ObjectName name) throws GBeanNotFoundException {
-        GBeanInstance gbeanInstance = registry.getGBeanInstance(createGBeanName(name));
+        GBeanInstance gbeanInstance = registry.getGBeanInstance(name);
         return gbeanInstance.getGBeanInfo();
     }
 
@@ -340,7 +339,7 @@
     }
 
     public GBeanData getGBeanData(ObjectName name) throws GBeanNotFoundException, InternalKernelException {
-        GBeanInstance gbeanInstance = registry.getGBeanInstance(createGBeanName(name));
+        GBeanInstance gbeanInstance = registry.getGBeanInstance(name);
         return gbeanInstance.getGBeanData();
     }
 
@@ -473,7 +472,7 @@
     }
 
     public int getGBeanState(ObjectName name) throws GBeanNotFoundException {
-        GBeanInstance gbeanInstance = registry.getGBeanInstance(createGBeanName(name));
+        GBeanInstance gbeanInstance = registry.getGBeanInstance(name);
         return gbeanInstance.getState();
     }
 
@@ -514,13 +513,8 @@
     }
 
     public Set listGBeans(ObjectName pattern) {
-        String domain = (pattern == null || pattern.isDomainPattern()) ? null : pattern.getDomain();
-        if (domain != null && domain.length() == 0) {
-            domain = kernelName;
-        }
+        Set gbeans = registry.listGBeans(pattern);
 
-        Map props = pattern == null ? null : pattern.getKeyPropertyList();
-        Set gbeans = registry.listGBeans(domain, props);
         Set result = new HashSet(gbeans.size());
         for (Iterator i = gbeans.iterator(); i.hasNext();) {
             GBeanInstance instance = (GBeanInstance) i.next();
@@ -697,7 +691,7 @@
     }
 
     public ClassLoader getClassLoaderFor(ObjectName name) throws GBeanNotFoundException {
-        GBeanInstance gbeanInstance = registry.getGBeanInstance(createGBeanName(name));
+        GBeanInstance gbeanInstance = registry.getGBeanInstance(name);
         return gbeanInstance.getClassLoader();
     }
 
@@ -718,14 +712,6 @@
         GBeanInstance gbeanInstance = registry.getGBeanInstance(shortName, type);
         return gbeanInstance.getClassLoader();
     }
-
-    private GBeanName createGBeanName(ObjectName objectName) {
-        if (objectName.getDomain().length() == 0) {
-            return new GBeanName(kernelName, objectName.getKeyPropertyList());
-        }
-        return new GBeanName(objectName);
-    }
-
 
     /**
      * @deprecated Experimental feature

Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicRegistry.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicRegistry.java?rev=395730&r1=395729&r2=395730&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicRegistry.java (original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicRegistry.java Thu Apr 20 16:21:15 2006
@@ -16,26 +16,23 @@
  */
 package org.apache.geronimo.kernel.basic;
 
-import java.util.Map;
+import java.util.Collections;
 import java.util.HashMap;
-import java.util.Set;
 import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Collections;
 import java.util.IdentityHashMap;
-
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
 import javax.management.ObjectName;
 import javax.management.MalformedObjectNameException;
 
-import org.apache.geronimo.kernel.Kernel;
-import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
-import org.apache.geronimo.kernel.GBeanNotFoundException;
-import org.apache.geronimo.kernel.InternalKernelException;
-import org.apache.geronimo.gbean.GBeanName;
-import org.apache.geronimo.gbean.AbstractNameQuery;
 import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.AbstractNameQuery;
 import org.apache.geronimo.gbean.runtime.GBeanInstance;
 import org.apache.geronimo.gbean.runtime.InstanceRegistry;
+import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
+import org.apache.geronimo.kernel.Kernel;
 
 /**
  * @version $Rev: 386505 $ $Date$
@@ -58,8 +55,10 @@
     /**
      * Shut down the objectNameRegistry and unregister any GBeans
      */
-    public synchronized void stop() {
-        objectNameRegistry.clear();
+    public void stop() {
+        synchronized (this) {
+            objectNameRegistry.clear();
+        }
         kernelName = "";
     }
 
@@ -69,8 +68,8 @@
      * @param name the name of the GBean to check for
      * @return true if there is a GBean registered with that name
      */
-    public synchronized boolean isRegistered(GBeanName name) {
-        return objectNameRegistry.containsKey(name);
+    public synchronized boolean isRegistered(ObjectName name) {
+        return objectNameRegistry.containsKey(normalizeObjectName(name));
     }
 
     public synchronized boolean isRegistered(AbstractName refInfo) {
@@ -84,7 +83,7 @@
      * @throws GBeanAlreadyExistsException if there is already a GBean registered with the instance's name
      */
     public synchronized void register(GBeanInstance gbeanInstance) throws GBeanAlreadyExistsException {
-        GBeanName name = createGBeanName(gbeanInstance.getObjectNameObject());
+        ObjectName name = normalizeObjectName(gbeanInstance.getObjectNameObject());
         if (objectNameRegistry.containsKey(name)) {
             throw new GBeanAlreadyExistsException("GBean already registered: " + name);
         }
@@ -93,32 +92,12 @@
         gbeanInstance.setInstanceRegistry(this);
     }
 
-    /**
-     * 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
-     */
-    public synchronized void unregister(GBeanName name) throws GBeanNotFoundException, InternalKernelException {
-        GBeanInstance gbeanInstance = (GBeanInstance) objectNameRegistry.remove(name);
-        if (gbeanInstance == null) {
-            try {
-                throw new GBeanNotFoundException(name.getObjectName());
-            } catch (MalformedObjectNameException e) {
-                throw new InternalKernelException(e);
-            }
-        }
-        infoRegistry.remove(gbeanInstance.getAbstractName());
-        gbeanInstance.setInstanceRegistry(null);
-    }
-
     public synchronized void unregister(AbstractName abstractName) throws GBeanNotFoundException {
         GBeanInstance gbeanInstance = (GBeanInstance) infoRegistry.remove(abstractName);
         if (gbeanInstance == null) {
             throw new GBeanNotFoundException(abstractName);
         }
-        GBeanName name = createGBeanName(gbeanInstance.getObjectNameObject());
-        objectNameRegistry.remove(name);
+        objectNameRegistry.remove(gbeanInstance.getObjectNameObject());
     }
 
     public synchronized void instanceCreated(Object instance, GBeanInstance gbeanInstance) {
@@ -140,14 +119,10 @@
      * @return the GBeanInstance
      * @throws GBeanNotFoundException if there is no GBean registered with the supplied name
      */
-    public synchronized GBeanInstance getGBeanInstance(GBeanName name) throws GBeanNotFoundException {
-        GBeanInstance instance = (GBeanInstance) objectNameRegistry.get(name);
+    public synchronized GBeanInstance getGBeanInstance(ObjectName name) throws GBeanNotFoundException {
+        GBeanInstance instance = (GBeanInstance) objectNameRegistry.get(normalizeObjectName(name));
         if (instance == null) {
-            try {
-                throw new GBeanNotFoundException(name.getObjectName());
-            } catch (MalformedObjectNameException e) {
-                throw new InternalKernelException(e);
-            }
+            throw new GBeanNotFoundException(name);
         }
         return instance;
     }
@@ -183,9 +158,9 @@
                 throw new GBeanNotFoundException("More then one GBean was found with shortName '" + shortName + "'", Collections.singleton(nameQuery));
             }
             if (shortName == null) {
-                throw new GBeanNotFoundException("More then one GBean was found with type '" + type.getName()+ "'", Collections.singleton(nameQuery));
+                throw new GBeanNotFoundException("More then one GBean was found with type '" + type.getName() + "'", Collections.singleton(nameQuery));
             }
-            throw new GBeanNotFoundException("More then one GBean was found with shortName '" + shortName + "' and type '" + type.getName()+ "'", Collections.singleton(nameQuery));
+            throw new GBeanNotFoundException("More then one GBean was found with shortName '" + shortName + "' and type '" + type.getName() + "'", Collections.singleton(nameQuery));
         }
 
         GBeanInstance instance = (GBeanInstance) instances.iterator().next();
@@ -196,11 +171,12 @@
     /**
      * Search the objectNameRegistry for GBeans matching a name pattern.
      *
-     * @param domain     the domain to query in; null indicates all
-     * @param properties the properties the GBeans must have
+     * @param pattern the object name pattern to search for
      * @return an unordered Set<GBeanInstance> of GBeans that matched the pattern
      */
-    public Set listGBeans(String domain, Map properties) {
+    public Set listGBeans(ObjectName pattern) {
+        pattern = normalizeObjectName(pattern);
+
         // fairly dumb implementation that iterates the list of all registered GBeans
         Map clone;
         synchronized (this) {
@@ -209,8 +185,8 @@
         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)) {
+            ObjectName name = (ObjectName) entry.getKey();
+            if (pattern == null || pattern.apply(name)) {
                 result.add(entry.getValue());
             }
         }
@@ -234,10 +210,14 @@
         return result;
     }
 
-    private GBeanName createGBeanName(ObjectName objectName) {
-        if (objectName.getDomain().length() == 0) {
-            return new GBeanName(kernelName, objectName.getKeyPropertyList());
+    private ObjectName normalizeObjectName(ObjectName objectName) {
+        if (objectName != null && objectName.getDomain().length() == 0) {
+            try {
+                return new ObjectName(kernelName, objectName.getKeyPropertyList());
+            } catch (MalformedObjectNameException e) {
+                throw new AssertionError(e);
+            }
         }
-        return new GBeanName(objectName);
+        return objectName;
     }
 }