geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r389963 - in /geronimo/branches/1.1: applications/console-standard/src/java/org/apache/geronimo/console/certmanager/ applications/console-standard/src/java/org/apache/geronimo/console/certmanager/actions/ applications/console-standard/src/j...
Date Thu, 30 Mar 2006 02:05:09 GMT
Author: dain
Date: Wed Mar 29 18:05:04 2006
New Revision: 389963

URL: http://svn.apache.org/viewcvs?rev=389963&view=rev
Log:
Added identity hashmap from service instance to GBeanInstance in registry so service name
can be obtained from the acutal object.  Server can not boot with no proxy on and we get about
a 15% reduction in startup time.

Removed more usages of ObjectName

Added:
    geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/InstanceRegistry.java
Modified:
    geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/certmanager/CertManagerPortlet.java
    geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/certmanager/actions/GenerateKeyPair.java
    geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/certmanager/actions/ViewKeyStore.java
    geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/certmanager/actions/ViewKeyStoreEntryDetail.java
    geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/util/KernelHelper.java
    geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/util/ObjectNameConstants.java
    geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/util/SERealmGroupHelper.java
    geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java
    geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java
    geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/KernelGBean.java
    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
    geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/jmx/KernelDelegate.java
    geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/jmx/MBeanServerDelegate.java
    geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/kernel/GBeanTest.java
    geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/SilentStartupMonitor.java

Modified: geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/certmanager/CertManagerPortlet.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/certmanager/CertManagerPortlet.java?rev=389963&r1=389962&r2=389963&view=diff
==============================================================================
--- geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/certmanager/CertManagerPortlet.java
(original)
+++ geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/certmanager/CertManagerPortlet.java
Wed Mar 29 18:05:04 2006
@@ -19,7 +19,6 @@
 
 import java.io.IOException;
 import java.util.Enumeration;
-import javax.management.ObjectName;
 import javax.portlet.ActionRequest;
 import javax.portlet.ActionResponse;
 import javax.portlet.GenericPortlet;
@@ -39,6 +38,7 @@
 import org.apache.geronimo.console.certmanager.actions.ViewKeyStore;
 import org.apache.geronimo.console.certmanager.actions.ViewKeyStoreEntryDetail;
 import org.apache.geronimo.console.util.ObjectNameConstants;
+import org.apache.geronimo.gbean.AbstractName;
 
 public class CertManagerPortlet extends GenericPortlet {
 
@@ -56,7 +56,7 @@
         this.ctx.log("Certificate manager portlet initialized");
     }
 
-    public ObjectName getKeyStoreObjectName() {
+    public AbstractName getKeyStoreObjectName() {
         return ObjectNameConstants.KEYSTORE_OBJ_NAME;
     }
 

Modified: geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/certmanager/actions/GenerateKeyPair.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/certmanager/actions/GenerateKeyPair.java?rev=389963&r1=389962&r2=389963&view=diff
==============================================================================
--- geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/certmanager/actions/GenerateKeyPair.java
(original)
+++ geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/certmanager/actions/GenerateKeyPair.java
Wed Mar 29 18:05:04 2006
@@ -21,7 +21,6 @@
 import java.util.Iterator;
 import java.util.List;
 
-import javax.management.ObjectName;
 import javax.portlet.ActionRequest;
 import javax.portlet.ActionResponse;
 import javax.portlet.PortletException;
@@ -31,6 +30,7 @@
 
 import org.apache.geronimo.console.certmanager.CertManagerPortlet;
 import org.apache.geronimo.kernel.KernelRegistry;
+import org.apache.geronimo.gbean.AbstractName;
 
 public class GenerateKeyPair {
     public static void action(CertManagerPortlet portlet,
@@ -98,15 +98,15 @@
                     "/WEB-INF/view/certmanager/generateKeyPairNormal.jsp");
         } else {
             try {
-                ObjectName objname = portlet.getKeyStoreObjectName();
+                AbstractName name = portlet.getKeyStoreObjectName();
 
                 String keyStoreType = (String) KernelRegistry.getSingleKernel()
-                        .getAttribute(objname, "keyStoreType");
+                        .getAttribute(name, "keyStoreType");
                 String keyStoreProvider = (String) KernelRegistry
-                        .getSingleKernel().getAttribute(objname,
+                        .getSingleKernel().getAttribute(name,
                                 "keyStoreProvider");
                 String keyStoreLocation = (String) KernelRegistry
-                        .getSingleKernel().getAttribute(objname,
+                        .getSingleKernel().getAttribute(name,
                                 "keyStoreLocation");
 
                 request.setAttribute("org.apache.geronimo.console.keystore.type",
@@ -117,7 +117,7 @@
                         keyStoreLocation);
 
                 List storelist = (List) KernelRegistry.getSingleKernel()
-                        .invoke(objname, "getKeyStoreEntries");
+                        .invoke(name, "getKeyStoreEntries");
 
                 Iterator iter = storelist.iterator();
                 while (iter.hasNext()) {

Modified: geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/certmanager/actions/ViewKeyStore.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/certmanager/actions/ViewKeyStore.java?rev=389963&r1=389962&r2=389963&view=diff
==============================================================================
--- geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/certmanager/actions/ViewKeyStore.java
(original)
+++ geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/certmanager/actions/ViewKeyStore.java
Wed Mar 29 18:05:04 2006
@@ -21,7 +21,6 @@
 import java.util.Iterator;
 import java.util.List;
 
-import javax.management.ObjectName;
 import javax.portlet.ActionRequest;
 import javax.portlet.ActionResponse;
 import javax.portlet.PortletException;
@@ -31,6 +30,7 @@
 
 import org.apache.geronimo.console.certmanager.CertManagerPortlet;
 import org.apache.geronimo.kernel.KernelRegistry;
+import org.apache.geronimo.gbean.AbstractName;
 
 public class ViewKeyStore {
     public static void action(CertManagerPortlet portlet,
@@ -46,14 +46,14 @@
         PortletRequestDispatcher rd = null;
 
         try {
-            ObjectName objname = portlet.getKeyStoreObjectName();
+            AbstractName name = portlet.getKeyStoreObjectName();
 
             String keyStoreType = (String) KernelRegistry.getSingleKernel()
-                    .getAttribute(objname, "keyStoreType");
+                    .getAttribute(name, "keyStoreType");
             String keyStoreProvider = (String) KernelRegistry.getSingleKernel()
-                    .getAttribute(objname, "keyStoreProvider");
+                    .getAttribute(name, "keyStoreProvider");
             String keyStoreLocation = (String) KernelRegistry.getSingleKernel()
-                    .getAttribute(objname, "keyStoreLocation");
+                    .getAttribute(name, "keyStoreLocation");
 
             request.setAttribute("org.apache.geronimo.console.keystore.type", keyStoreType);
             request.setAttribute("org.apache.geronimo.console.keystore.provider",
@@ -62,7 +62,7 @@
                     keyStoreLocation);
 
             List storelist = (List) KernelRegistry.getSingleKernel().invoke(
-                    objname, "getKeyStoreEntries");
+                    name, "getKeyStoreEntries");
 
             Iterator iter = storelist.iterator();
             while (iter.hasNext()) {

Modified: geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/certmanager/actions/ViewKeyStoreEntryDetail.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/certmanager/actions/ViewKeyStoreEntryDetail.java?rev=389963&r1=389962&r2=389963&view=diff
==============================================================================
--- geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/certmanager/actions/ViewKeyStoreEntryDetail.java
(original)
+++ geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/certmanager/actions/ViewKeyStoreEntryDetail.java
Wed Mar 29 18:05:04 2006
@@ -19,7 +19,6 @@
 
 import java.io.IOException;
 import java.security.cert.Certificate;
-import javax.management.ObjectName;
 import javax.portlet.PortletException;
 import javax.portlet.PortletRequestDispatcher;
 import javax.portlet.RenderRequest;
@@ -29,6 +28,7 @@
 import org.apache.geronimo.console.core.keystore.KeyEntryInfo;
 import org.apache.geronimo.console.util.ObjectNameConstants;
 import org.apache.geronimo.kernel.KernelRegistry;
+import org.apache.geronimo.gbean.AbstractName;
 
 public class ViewKeyStoreEntryDetail {
 
@@ -43,9 +43,9 @@
 
         try {
             // entry info
-            ObjectName objname = ObjectNameConstants.KEYSTORE_OBJ_NAME;
+            AbstractName name = ObjectNameConstants.KEYSTORE_OBJ_NAME;
             KeyEntryInfo kinfo = (KeyEntryInfo) KernelRegistry
-                    .getSingleKernel().invoke(objname, "getKeyEntryInfo",
+                    .getSingleKernel().invoke(name, "getKeyEntryInfo",
                             new Object[] { alias },
                             new String[] { "java.lang.String" });
 
@@ -53,7 +53,7 @@
 
             // get keystore certificate chain by the alias
             Certificate[] chain = (Certificate[]) KernelRegistry
-                    .getSingleKernel().invoke(objname, "getCertificateChain",
+                    .getSingleKernel().invoke(name, "getCertificateChain",
                             new Object[] { alias },
                             new String[] { "java.lang.String" });
 

Modified: geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/util/KernelHelper.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/util/KernelHelper.java?rev=389963&r1=389962&r2=389963&view=diff
==============================================================================
--- geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/util/KernelHelper.java
(original)
+++ geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/util/KernelHelper.java
Wed Mar 29 18:05:04 2006
@@ -21,19 +21,20 @@
 
 import org.apache.geronimo.kernel.Kernel;
 import org.apache.geronimo.kernel.KernelRegistry;
+import org.apache.geronimo.gbean.AbstractName;
 
 public class KernelHelper {
 
     protected static Kernel kernel = KernelRegistry.getSingleKernel();
 
-    protected static Object invoke(ObjectName mBeanName, String function)
+    protected static Object invoke(AbstractName mBeanName, String function)
             throws Exception {
         Object[] NO_ARGS = new Object[0];
         String[] NO_PARAMS = new String[0];
         return invoke(mBeanName, function, NO_ARGS, NO_PARAMS);
     }
 
-    protected static Object invoke(ObjectName mBeanName, String function,
+    protected static Object invoke(AbstractName mBeanName, String function,
             Object[] args, String[] types) throws Exception {
         Object ret = null;
         ret = kernel.invoke(mBeanName, function, args, types);

Modified: geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/util/ObjectNameConstants.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/util/ObjectNameConstants.java?rev=389963&r1=389962&r2=389963&view=diff
==============================================================================
--- geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/util/ObjectNameConstants.java
(original)
+++ geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/util/ObjectNameConstants.java
Wed Mar 29 18:05:04 2006
@@ -17,38 +17,43 @@
 
 package org.apache.geronimo.console.util;
 
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.AbstractNameQuery;
+import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
 import org.apache.geronimo.kernel.Kernel;
 import org.apache.geronimo.kernel.KernelRegistry;
 
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-import java.util.Set;
-
 public final class ObjectNameConstants {
 
     // Security object names
-    public static final ObjectName SE_REALM_MBEAN_NAME;
-    public static final ObjectName DEPLOYER_OBJECT_NAME;
-    public static final ObjectName KEYSTORE_OBJ_NAME;
+    public static final AbstractName SE_REALM_MBEAN_NAME;
+    public static final AbstractName DEPLOYER_OBJECT_NAME;
+    public static final AbstractName KEYSTORE_OBJ_NAME;
 
     static {
         Kernel kernel = KernelRegistry.getSingleKernel();
-        try {
-            SE_REALM_MBEAN_NAME = getUniquename("*:J2EEModule=null,j2eeType=GBean,name=PropertiesLoginManager,*",
kernel);
-            DEPLOYER_OBJECT_NAME = getUniquename("*:J2EEApplication=null,j2eeType=Deployer,name=Deployer,*",
kernel);
-            KEYSTORE_OBJ_NAME = getUniquename("*:J2EEModule=null,j2eeType=GBean,name=KeyStore,*",
kernel);
-        } catch (MalformedObjectNameException e) {
-            throw new RuntimeException(e);
-        }
+        SE_REALM_MBEAN_NAME = getUniquename("PropertiesLoginManager", "GBean", kernel);
+        DEPLOYER_OBJECT_NAME = getUniquename("Deployer", "Deployer", kernel);
+        KEYSTORE_OBJ_NAME = getUniquename("KeyStore", "GBean", kernel);
     }
 
-    private static ObjectName getUniquename(String queryPattern, Kernel kernel) throws MalformedObjectNameException
{
-        ObjectName query = ObjectName.getInstance(queryPattern);
+    private static AbstractName getUniquename(String name, String type, Kernel kernel) {
+        Map properties = new HashMap(2);
+        properties.put(NameFactory.J2EE_NAME, name);
+        properties.put(NameFactory.J2EE_TYPE, type);
+        AbstractNameQuery query = new AbstractNameQuery(null, properties);
         Set results = kernel.listGBeans(query);
+        if (results.isEmpty()) {
+            throw new RuntimeException("No services found with name " + name + " and type
" + type);
+        }
         if (results.size() != 1) {
-            throw new RuntimeException("Invalid query: " + queryPattern + ", returns: " +
results);
+            throw new RuntimeException("More than one service was found with name " + name
+ " and type " + type + ", returns: " + results);
         }
-        return (ObjectName) results.iterator().next();
+        return (AbstractName) results.iterator().next();
     }
 
 }

Modified: geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/util/SERealmGroupHelper.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/util/SERealmGroupHelper.java?rev=389963&r1=389962&r2=389963&view=diff
==============================================================================
--- geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/util/SERealmGroupHelper.java
(original)
+++ geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/util/SERealmGroupHelper.java
Wed Mar 29 18:05:04 2006
@@ -54,9 +54,6 @@
 
             kernel.stopGBean(ObjectNameConstants.SE_REALM_MBEAN_NAME);
             kernel.startGBean(ObjectNameConstants.SE_REALM_MBEAN_NAME);
-//            kernel.stopGBean(ObjectNameConstants.SE_REALM_IMMUTABLE_MBEAN_NAME);
-//            kernel.startGBean(ObjectNameConstants.SE_REALM_IMMUTABLE_MBEAN_NAME);
-
         } catch (Exception e) {
         }
     }

Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java?rev=389963&r1=389962&r2=389963&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java
(original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java
Wed Mar 29 18:05:04 2006
@@ -194,6 +194,8 @@
      */
     private boolean shouldFail = false;
 
+    private InstanceRegistry instanceRegistry;
+
     /**
      * Construct a GBeanMBean using the supplied GBeanData and class loader
      *
@@ -401,6 +403,10 @@
         manageableStore = null;
     }
 
+    public void setInstanceRegistry(InstanceRegistry instanceRegistry) {
+        this.instanceRegistry = instanceRegistry;
+    }
+
     /**
      * Gets the name of the GBean as defined in the gbean info.
      *
@@ -926,13 +932,18 @@
                 ((GBeanLifecycle) instance).doStart();
             }
 
+
             // all done... we are now fully running
             synchronized (this) {
                 checkIfShouldFail();
+                if (instanceRegistry != null) {
+                    instanceRegistry.instanceCreated(instance, this);
+                }
                 instanceState = RUNNING;
                 this.notifyAll();
             }
 
+
             return true;
         } catch (Throwable t) {
             // something went wrong... we need to destroy this instance
@@ -1094,6 +1105,9 @@
 
             target = null;
             instanceState = DESTROYED;
+            if (instanceRegistry != null) {
+                instanceRegistry.instanceDestroyed(instance);
+            }
             startTime = 0;
         }
 

Added: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/InstanceRegistry.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/InstanceRegistry.java?rev=389963&view=auto
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/InstanceRegistry.java
(added)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/InstanceRegistry.java
Wed Mar 29 18:05:04 2006
@@ -0,0 +1,27 @@
+/**
+ *
+ * Copyright 2005 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.runtime;
+
+import org.apache.geronimo.gbean.AbstractName;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface InstanceRegistry {
+    void instanceCreated(Object instance, GBeanInstance gbeanInstance);
+    void instanceDestroyed(Object instance);
+}

Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java?rev=389963&r1=389962&r2=389963&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java (original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java Wed
Mar 29 18:05:04 2006
@@ -355,14 +355,6 @@
     /**
      * @deprecated Use AbstractName version instead
      */
-    void startGBean(ObjectName name) throws GBeanNotFoundException, InternalKernelException,
IllegalStateException;
-    /**
-     * @deprecated Use AbstractName version instead
-     */
-    void stopGBean(ObjectName name) throws GBeanNotFoundException, InternalKernelException,
IllegalStateException;
-    /**
-     * @deprecated Use AbstractName version instead
-     */
     int getGBeanState(ObjectName name) throws GBeanNotFoundException;
     /**
      * @deprecated Use AbstractName version instead

Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/KernelGBean.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/KernelGBean.java?rev=389963&r1=389962&r2=389963&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/KernelGBean.java
(original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/KernelGBean.java
Wed Mar 29 18:05:04 2006
@@ -102,10 +102,6 @@
         return kernel.getGBean(shortName, type);
     }
 
-    public void startGBean(ObjectName name) throws GBeanNotFoundException, InternalKernelException,
IllegalStateException {
-        kernel.startGBean(name);
-    }
-
     public void startGBean(AbstractName name) throws GBeanNotFoundException, InternalKernelException,
IllegalStateException {
         kernel.startGBean(name);
     }
@@ -152,10 +148,6 @@
 
     public boolean isRunning(String shortName, Class type) {
         return kernel.isRunning(shortName, type);
-    }
-
-    public void stopGBean(ObjectName name) throws GBeanNotFoundException, InternalKernelException,
IllegalStateException {
-        kernel.stopGBean(name);
     }
 
     public void stopGBean(AbstractName name) throws GBeanNotFoundException, InternalKernelException,
IllegalStateException {

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=389963&r1=389962&r2=389963&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
Wed Mar 29 18:05:04 2006
@@ -23,7 +23,6 @@
 import java.util.LinkedList;
 import java.util.Map;
 import java.util.Set;
-import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -369,11 +368,6 @@
         registry.register(gbeanInstance);
     }
 
-    public void startGBean(ObjectName name) throws GBeanNotFoundException, InternalKernelException,
IllegalStateException {
-        GBeanInstance gbeanInstance = registry.getGBeanInstance(createGBeanName(name));
-        gbeanInstance.start();
-    }
-
     public void startGBean(AbstractName name) throws GBeanNotFoundException, InternalKernelException,
IllegalStateException {
         GBeanInstance gbeanInstance = registry.getGBeanInstance(name);
         gbeanInstance.start();
@@ -436,11 +430,6 @@
         }
     }
 
-    public void stopGBean(ObjectName name) throws GBeanNotFoundException, InternalKernelException,
IllegalStateException {
-        GBeanInstance gbeanInstance = registry.getGBeanInstance(createGBeanName(name));
-        gbeanInstance.stop();
-    }
-
     public void stopGBean(AbstractName name) throws GBeanNotFoundException, InternalKernelException,
IllegalStateException {
         GBeanInstance gbeanInstance = registry.getGBeanInstance(name);
         gbeanInstance.stop();
@@ -550,20 +539,8 @@
         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 listGBeans(AbstractNameQuery refInfoQuery) {
-        Set gbeans = registry.listGBeans(refInfoQuery);
+    public Set listGBeans(AbstractNameQuery query) {
+        Set gbeans = registry.listGBeans(query);
         Set result = new HashSet(gbeans.size());
         for (Iterator i = gbeans.iterator(); i.hasNext();) {
             GBeanInstance instance = (GBeanInstance) i.next();
@@ -574,14 +551,9 @@
 
     public Set listGBeansByInterface(String[] interfaces) {
         Set gbeans = new HashSet();
-        Set all;
-        try {
-            all = listGBeans(ObjectName.getInstance("*:*"));
-        } catch (MalformedObjectNameException e) {
-            throw new IllegalStateException("How can *:* be an invalid pattern");
-        }
+        Set all = listGBeans((AbstractNameQuery)null);
         for (Iterator it = all.iterator(); it.hasNext();) {
-            ObjectName name = (ObjectName) it.next();
+            AbstractName name = (AbstractName) it.next();
             try {
                 GBeanInfo info = getGBeanInfo(name);
                 Set intfs = info.getInterfaces();
@@ -598,15 +570,32 @@
     }
 
     public AbstractName getAbstractNameFor(Object service) {
-        // todo we need to keep an identity map for non proxied references
-        if(!running) {return null;}
-        return proxyManager.getProxyTarget(service);
+        if(!running) {
+            return null;
+        }
+
+        // check if service is a proxy
+        AbstractName name = proxyManager.getProxyTarget(service);
+        if (name != null) {
+            return name;
+        }
+
+        // try the registry
+        GBeanInstance gbeanInstance = registry.getGBeanInstanceByInstance(service);
+        if (gbeanInstance != null) {
+            return gbeanInstance.getAbstractName();
+        }
+
+        // didn't fing the name
+        return null;
     }
 
     public String getShortNameFor(Object service) {
-        // todo we need to keep an identity map for non proxied references
         AbstractName name = getAbstractNameFor(service);
-        return (String) name.getName().get("name");
+        if (name != null) {
+            return (String) name.getName().get("name");
+        }
+        return null;
     }
 
     /**

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=389963&r1=389962&r2=389963&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
Wed Mar 29 18:05:04 2006
@@ -22,6 +22,7 @@
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Collections;
+import java.util.IdentityHashMap;
 
 import javax.management.ObjectName;
 import javax.management.MalformedObjectNameException;
@@ -34,13 +35,15 @@
 import org.apache.geronimo.gbean.AbstractNameQuery;
 import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.gbean.runtime.GBeanInstance;
+import org.apache.geronimo.gbean.runtime.InstanceRegistry;
 
 /**
  * @version $Rev: 386505 $ $Date$
  */
-public class BasicRegistry {
+public class BasicRegistry implements InstanceRegistry {
     private final Map objectNameRegistry = new HashMap();
     private final Map infoRegistry = new HashMap();
+    private final IdentityHashMap instanceRegistry = new IdentityHashMap();
     private String kernelName = "";
 
     /**
@@ -87,6 +90,7 @@
         }
         objectNameRegistry.put(name, gbeanInstance);
         infoRegistry.put(gbeanInstance.getAbstractName(), gbeanInstance);
+        gbeanInstance.setInstanceRegistry(this);
     }
 
     /**
@@ -105,6 +109,7 @@
             }
         }
         infoRegistry.remove(gbeanInstance.getAbstractName());
+        gbeanInstance.setInstanceRegistry(null);
     }
 
     public synchronized void unregister(AbstractName abstractName) throws GBeanNotFoundException
{
@@ -114,6 +119,18 @@
         }
         GBeanName name = createGBeanName(gbeanInstance.getObjectNameObject());
         objectNameRegistry.remove(name);
+    }
+
+    public synchronized void instanceCreated(Object instance, GBeanInstance gbeanInstance)
{
+        instanceRegistry.put(instance, gbeanInstance);
+    }
+
+    public synchronized void instanceDestroyed(Object instance) {
+        instanceRegistry.remove(instance);
+    }
+
+    public synchronized GBeanInstance getGBeanInstanceByInstance(Object instance) {
+        return (GBeanInstance) instanceRegistry.get(instance);
     }
 
     /**

Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/jmx/KernelDelegate.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/jmx/KernelDelegate.java?rev=389963&r1=389962&r2=389963&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/jmx/KernelDelegate.java
(original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/jmx/KernelDelegate.java
Wed Mar 29 18:05:04 2006
@@ -136,18 +136,6 @@
         }
     }
 
-    public void startGBean(ObjectName name) throws GBeanNotFoundException {
-        try {
-            invokeKernel("startGBean", new Object[] {name}, new String[] {ObjectName.class.getName()});
-        } catch (GBeanNotFoundException e) {
-            throw e;
-        } catch (RuntimeException e) {
-            throw e;
-        } catch (Exception e) {
-            throw new InternalKernelException(e);
-        }
-    }
-
     public void startGBean(AbstractName name) throws GBeanNotFoundException, InternalKernelException,
IllegalStateException {
         try {
             invokeKernel("startGBean", new Object[] {name}, new String[] {AbstractName.class.getName()});
@@ -285,18 +273,6 @@
     }
 
 
-    public void stopGBean(ObjectName name) throws GBeanNotFoundException {
-        try {
-            invokeKernel("stopGBean", new Object[] {name}, new String[] {ObjectName.class.getName()});
-        } catch (GBeanNotFoundException e) {
-            throw e;
-        } catch (RuntimeException e) {
-            throw e;
-        } catch (Exception e) {
-            throw new InternalKernelException(e);
-        }
-    }
-
     public void stopGBean(AbstractName name) throws GBeanNotFoundException, InternalKernelException,
IllegalStateException {
         try {
             invokeKernel("stopGBean", new Object[] {name}, new String[] {AbstractName.class.getName()});
@@ -910,7 +886,17 @@
     }
 
     public AbstractName getAbstractNameFor(Object service) {
-        return proxyManager.getProxyTarget(service);
+        AbstractName name = proxyManager.getProxyTarget(service);
+        if (name != null) {
+            return name;
+        }
+        try {
+            return (AbstractName) invokeKernel("getAbstractNameFor", new Object[] {service},
new String[] {Object.class.getName()});
+        } catch (RuntimeException e) {
+            throw e;
+        } catch (Exception e) {
+            throw new InternalKernelException(e);
+        }
     }
 
     public String getShortNameFor(Object service) {

Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/jmx/MBeanServerDelegate.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/jmx/MBeanServerDelegate.java?rev=389963&r1=389962&r2=389963&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/jmx/MBeanServerDelegate.java
(original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/jmx/MBeanServerDelegate.java
Wed Mar 29 18:05:04 2006
@@ -41,6 +41,7 @@
 import javax.management.loading.ClassLoaderRepository;
 
 import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.AbstractNameQuery;
 import org.apache.geronimo.kernel.GBeanNotFoundException;
 import org.apache.geronimo.kernel.InternalKernelException;
 import org.apache.geronimo.kernel.NoSuchAttributeException;
@@ -97,7 +98,7 @@
     }
 
     public Integer getMBeanCount() {
-        return new Integer(kernel.listGBeans((ObjectName)null).size());
+        return new Integer(kernel.listGBeans((AbstractNameQuery)null).size());
     }
 
     public MBeanInfo getMBeanInfo(ObjectName name) throws InstanceNotFoundException, ReflectionException
{

Modified: geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/kernel/GBeanTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/kernel/GBeanTest.java?rev=389963&r1=389962&r2=389963&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/kernel/GBeanTest.java
(original)
+++ geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/kernel/GBeanTest.java
Wed Mar 29 18:05:04 2006
@@ -214,22 +214,26 @@
         // abstract name
         MockGBean mockGBean = (MockGBean) kernel.getGBean(gbean.getAbstractName());
         assertEquals(123, mockGBean.getFinalInt());
-        assertNull(kernel.getAbstractNameFor(mockGBean));
+        assertEquals(gbean.getAbstractName(), kernel.getAbstractNameFor(mockGBean));
+        assertEquals("name", kernel.getShortNameFor(mockGBean));
 
         // short name
         mockGBean = (MockGBean) kernel.getGBean("name");
         assertEquals(123, mockGBean.getFinalInt());
-        assertNull(kernel.getAbstractNameFor(mockGBean));
+        assertEquals(gbean.getAbstractName(), kernel.getAbstractNameFor(mockGBean));
+        assertEquals("name", kernel.getShortNameFor(mockGBean));
 
         // type
         mockGBean = (MockGBean) kernel.getGBean(MockGBean.class);
         assertEquals(123, mockGBean.getFinalInt());
-        assertNull(kernel.getAbstractNameFor(mockGBean));
+        assertEquals(gbean.getAbstractName(), kernel.getAbstractNameFor(mockGBean));
+        assertEquals("name", kernel.getShortNameFor(mockGBean));
 
         // short name and type
         mockGBean = (MockGBean) kernel.getGBean("name", MockGBean.class);
         assertEquals(123, mockGBean.getFinalInt());
-        assertNull(kernel.getAbstractNameFor(mockGBean));
+        assertEquals(gbean.getAbstractName(), kernel.getAbstractNameFor(mockGBean));
+        assertEquals("name", kernel.getShortNameFor(mockGBean));
     }
 
     public void testInvoke() throws Exception {
@@ -401,7 +405,7 @@
 
         MockGBean mockGBean1 = (MockGBean) kernel.getGBean(gbean1.getAbstractName());
         MockGBean mockGBean2 = (MockGBean) kernel.getGBean(gbean2.getAbstractName());
-        // this can only be tested of no proxy is on
+        // this can only be tested if no proxy is on
 //        assertSame(mockGBean2.getMockEndpoint(), mockGBean1);
     }
 

Modified: geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/SilentStartupMonitor.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/SilentStartupMonitor.java?rev=389963&r1=389962&r2=389963&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/SilentStartupMonitor.java
(original)
+++ geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/main/SilentStartupMonitor.java
Wed Mar 29 18:05:04 2006
@@ -1,17 +1,16 @@
 package org.apache.geronimo.system.main;
 
-import java.util.Set;
 import java.util.Iterator;
+import java.util.Set;
 
-import org.apache.geronimo.kernel.Kernel;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.AbstractNameQuery;
 import org.apache.geronimo.kernel.GBeanNotFoundException;
-import org.apache.geronimo.kernel.repository.Artifact;
+import org.apache.geronimo.kernel.Kernel;
 import org.apache.geronimo.kernel.management.State;
-import org.apache.commons.logging.LogFactory;
-import org.apache.commons.logging.Log;
-
-import javax.management.ObjectName;
-import javax.management.MalformedObjectNameException;
+import org.apache.geronimo.kernel.repository.Artifact;
 
 /**
  * @version $Rev$ $Date$
@@ -45,15 +44,14 @@
 
     public void startupFinished() {
         try {
-            Set gbeans = kernel.listGBeans(ObjectName.getInstance("*:*"));
+            Set gbeans = kernel.listGBeans((AbstractNameQuery)null);
             for (Iterator it = gbeans.iterator(); it.hasNext();) {
-                ObjectName name = (ObjectName) it.next();
+                AbstractName name = (AbstractName) it.next();
                 int state = kernel.getGBeanState(name);
                 if (state != State.RUNNING_INDEX) {
                     log.warn("Unable to start "+name+" ("+State.fromInt(state).getName()+")");
                 }
             }
-        } catch (MalformedObjectNameException e) {
         } catch (GBeanNotFoundException e) {
         }
         System.out.println("Geronimo startup complete");



Mime
View raw message