[jboss-cvs] JBossAS SVN: r59918 - in trunk/ejb3/src/main/org/jboss/ejb3: remoting and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jan 22 10:19:27 EST 2007


Author: wolfc
Date: 2007-01-22 10:19:27 -0500 (Mon, 22 Jan 2007)
New Revision: 59918

Modified:
   trunk/ejb3/src/main/org/jboss/ejb3/Ejb3Deployment.java
   trunk/ejb3/src/main/org/jboss/ejb3/Ejb3Registry.java
   trunk/ejb3/src/main/org/jboss/ejb3/LocalProxy.java
   trunk/ejb3/src/main/org/jboss/ejb3/remoting/IsLocalInterceptor.java
Log:
EJBTHREE-840: forward-port

Modified: trunk/ejb3/src/main/org/jboss/ejb3/Ejb3Deployment.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/Ejb3Deployment.java	2007-01-22 14:01:53 UTC (rev 59917)
+++ trunk/ejb3/src/main/org/jboss/ejb3/Ejb3Deployment.java	2007-01-22 15:19:27 UTC (rev 59918)
@@ -66,7 +66,7 @@
 
    protected DeploymentUnit unit;
 
-   protected LinkedHashMap ejbContainers = new LinkedHashMap();
+   protected LinkedHashMap<ObjectName, Container> ejbContainers = new LinkedHashMap<ObjectName, Container>();
 
    protected boolean hasEntities;
    protected List<String> explicitEntityClasses = new ArrayList<String>();
@@ -506,8 +506,6 @@
          {
             ObjectName on = (ObjectName) o;
             kernelAbstraction.uninstall(on.getCanonicalName());
-            Container container = (Container) ejbContainers.get(on);
-            Ejb3Registry.unregister(container);
          }
          catch (Exception e)
          {
@@ -519,8 +517,18 @@
 
    public void destroy() throws Exception
    {
+      undeploy();
+      
       PolicyConfigurationFactory pcFactory = PolicyConfigurationFactory.getPolicyConfigurationFactory();
       PolicyConfiguration pc = pcFactory.getPolicyConfiguration(getJaccContextId(), true);
       pc.delete();
    }
+      
+   private void undeploy()
+   {
+      for(Container container : ejbContainers.values())
+      {
+         Ejb3Registry.unregister(container);
+      }
+   }
 }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/Ejb3Registry.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/Ejb3Registry.java	2007-01-22 14:01:53 UTC (rev 59917)
+++ trunk/ejb3/src/main/org/jboss/ejb3/Ejb3Registry.java	2007-01-22 15:19:27 UTC (rev 59918)
@@ -22,10 +22,15 @@
 package org.jboss.ejb3;
 
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.Map;
+
 import org.jboss.logging.Logger;
 
 /**
+ * Maintains an administration of all EJB3 container available.
+ * 
  * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
  * @version <tt>$Revision$</tt>
  */
@@ -33,26 +38,86 @@
 {
    private static final Logger log = Logger.getLogger(Ejb3Registry.class);
 
-   private static HashMap containers = new HashMap();
+   private static Map<String, Container> containers = new HashMap<String, Container>();
 
+   /**
+    * Find a potential container.
+    * 
+    * @param oid    the canonical object name of the container
+    * @return       the container or null if not found
+    */
+   public static Container findContainer(String oid)
+   {
+      return containers.get(oid);
+   }
+
+   /**
+    * Reports the existance of a container.
+    * 
+    * @param oid    the canonical object name of the container
+    * @return       true if found, false otherwise
+    */
+   public static boolean hasContainer(String oid)
+   {
+      return containers.containsKey(oid);
+   }
+   
+   private static final String oid(Container container)
+   {
+      return container.getObjectName().getCanonicalName();
+   }
+   
+   /**
+    * Registers a container.
+    * 
+    * @param container              the container to register
+    * @throws IllegalStateException if the container is already registered
+    */
    public static void register(Container container)
    {
-      containers.put(container.getObjectName().getCanonicalName(), container);
+      String oid = oid(container);
+      if(hasContainer(oid))
+         throw new IllegalStateException("Container " + oid + " + is already registered");
+      containers.put(oid, container);
    }
 
+   /**
+    * Unregisters a container.
+    * 
+    * @param container              the container to unregister
+    * @throws IllegalStateException if the container is not registered
+    */
    public static void unregister(Container container)
    {
-      containers.remove(container.getObjectName().getCanonicalName());
+      String oid = oid(container);
+      if(!hasContainer(oid))
+         throw new IllegalStateException("Container " + oid + " + is not registered");
+      containers.remove(oid);
    }
 
+   /**
+    * Returns the container specified by the given canocical object name.
+    * Never returns null.
+    * 
+    * @param oid                    the canonical object name of the container
+    * @return                       the container
+    * @throws IllegalStateException if the container is not registered
+    */
    public static Container getContainer(String oid)
    {
-      return (Container)containers.get(oid);
+      if(!hasContainer(oid))
+         throw new IllegalStateException("Container " + oid + " is not registered");
+      return containers.get(oid);
    }
 
-   public static Collection getContainers()
+   /**
+    * Returns an unmodifiable collection of the registered containers.
+    * 
+    * @return   the containers
+    */
+   public static Collection<Container> getContainers()
    {
-      return containers.values();
+      return Collections.unmodifiableCollection(containers.values());
    }
 
 }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/LocalProxy.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/LocalProxy.java	2007-01-22 14:01:53 UTC (rev 59917)
+++ trunk/ejb3/src/main/org/jboss/ejb3/LocalProxy.java	2007-01-22 15:19:27 UTC (rev 59918)
@@ -57,7 +57,7 @@
    protected Container getContainer()
    {
       if(container == null)
-         container = Ejb3Registry.getContainer(containerId);
+         container = Ejb3Registry.findContainer(containerId);
       if(container == null)
          log.warn("Container " + containerId + " is not yet available");
       return container;
@@ -67,7 +67,7 @@
    {
       this.containerId = in.readUTF();
       // TODO: one container is private, this won't have to be done anymore
-      this.container = Ejb3Registry.getContainer(containerId);
+      this.container = Ejb3Registry.findContainer(containerId);
    }
 
    public void writeExternal(ObjectOutput out) throws IOException

Modified: trunk/ejb3/src/main/org/jboss/ejb3/remoting/IsLocalInterceptor.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/remoting/IsLocalInterceptor.java	2007-01-22 14:01:53 UTC (rev 59917)
+++ trunk/ejb3/src/main/org/jboss/ejb3/remoting/IsLocalInterceptor.java	2007-01-22 15:19:27 UTC (rev 59918)
@@ -50,7 +50,7 @@
    public Object invoke(Invocation invocation) throws Throwable
    {
       Object oid = invocation.getMetaData(Dispatcher.DISPATCHER, Dispatcher.OID);
-      Container container = Ejb3Registry.getContainer(oid.toString());
+      Container container = Ejb3Registry.findContainer(oid.toString());
       if (container != null)
       {
          Invocation copy = (Invocation) new MarshalledObjectForLocalCalls(invocation).get();




More information about the jboss-cvs-commits mailing list