Index: src/org/jacorb/poa/AOM.java
===================================================================
RCS file: /cvs/JacORB/src/org/jacorb/poa/AOM.java,v
retrieving revision 1.35
retrieving revision 1.37
diff -u -r1.35 -r1.37
--- src/org/jacorb/poa/AOM.java	3 May 2009 21:36:17 -0000	1.35
+++ src/org/jacorb/poa/AOM.java	1 Dec 2009 17:32:22 -0000	1.37
@@ -21,8 +21,13 @@
  */
 
 import java.util.Enumeration;
+import java.util.HashSet;
 import java.util.Hashtable;
+import java.util.Iterator;
 import java.util.Vector;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
 import org.slf4j.Logger;
 import org.jacorb.poa.except.POAInternalError;
 import org.jacorb.poa.util.ByteArrayKey;
@@ -41,7 +46,7 @@
  * The data can be retrieved using getServant() or getObjectId().
  *
  * @author Reimo Tiedemann, FU Berlin
- * @version $Id: AOM.java,v 1.35 2009-05-03 21:36:17 andre.spiegel Exp $
+ * @version $Id: AOM.java,v 1.37 2009-12-01 17:32:22 alexander.bykov Exp $
  */
 
 public class AOM
@@ -68,8 +73,31 @@
      * <code>deactivationListLock</code> is a lock to protect two consecutive
      * operations on the list, used in remove().
      */
-    private final byte[]              deactivationListLock = new byte[0];
+    private final byte [] deactivationListLock = new byte[0];
+
+    private BlockingQueue removalQueue = new LinkedBlockingQueue();
 
+    class RemovalStruct
+    {
+        ByteArrayKey oidbak;
+        RequestController requestController;
+        ServantActivator servantActivator;
+        POA poa;
+        boolean cleanupInProgress;
+
+        public RemovalStruct (ByteArrayKey oidbak,
+                              RequestController requestController,
+                              ServantActivator servantActivator,
+                              POA poa,
+                              boolean cleanupInProgress)
+        {
+            this.oidbak = oidbak;
+            this.requestController = requestController;
+            this.servantActivator = servantActivator;
+            this.poa = poa;
+            this.cleanupInProgress = cleanupInProgress;
+        }
+    }
 
     protected AOM (boolean _unique, Logger _logger)
     {
@@ -80,6 +108,31 @@
         {
             servantMap = new Hashtable();
         }
+
+        Thread thread = new Thread ("AOMRemoval")
+        {
+            public void run()
+            {
+                while (true)
+                {
+                    try
+                    {
+                        RemovalStruct rs = (RemovalStruct) removalQueue.take();
+                        _remove (rs.oidbak,
+                                 rs.requestController,
+                                 rs.servantActivator,
+                                 rs.poa,
+                                 rs.cleanupInProgress);
+                    }
+                    catch (InterruptedException ie)
+                    {
+                    }
+                }
+            }
+        };
+
+        thread.setDaemon (true);
+        thread.start();
     }
 
 
@@ -365,21 +418,19 @@
         final POA poa_ = poa;
         final boolean cleanupInProgress_ = cleanupInProgress;
 
-        Thread thread = new Thread("AOM_RemovalThread")
-        {
-            public void run()
-            {
-                _remove(
-                    oid_,
-                    requestController_,
-                    servantActivator_,
-                    poa_,
-                    cleanupInProgress_
-                       );
-            }
-        };
+        RemovalStruct rs = new RemovalStruct (oidbak,
+                                              requestController,
+                                              servantActivator,
+                                              poa,
+                                              cleanupInProgress);
 
-        thread.start();
+        try
+        {
+            removalQueue.put (rs);
+        }
+        catch (InterruptedException ie)
+        {
+        }
     }
 
 
@@ -393,14 +444,13 @@
      * @param poa a <code>POA</code> value
      * @param cleanupInProgress a <code>boolean</code> value
      */
-    private void _remove( byte[] oid,
+    private void _remove( ByteArrayKey oidbak,
                           RequestController requestController,
                           ServantActivator servantActivator,
                           POA poa,
                           boolean cleanupInProgress)
     {
-        ByteArrayKey oidbak = new ByteArrayKey( oid );
-        Servant servant = null;
+        final byte[] oid = oidbak.getBytes();
 
         if (!objectMap.containsKey(oidbak))
         {
@@ -412,125 +462,132 @@
         // wait for request completion on this object (see freeObject below)
         if ( requestController != null)
         {
-            requestController.waitForObjectCompletion(oid);
+            requestController.waitForObjectCompletion(oidbak);
         }
 
-        synchronized (this)
+        try
+        {
+            actualRemove(oidbak, servantActivator, poa, cleanupInProgress, oid);
+        }
+        finally
         {
-            if ((servant = (Servant)objectMap.get(oidbak)) == null)
+            if (requestController != null)
             {
-                return;
+                requestController.freeObject(oid);
             }
+        }
+    }
 
-            /* object deactivation */
 
-            objectMap.remove(oidbak);
+    private synchronized void actualRemove(ByteArrayKey oidbak, ServantActivator servantActivator, POA poa, boolean cleanupInProgress, final byte[] oid)
+    {
+        Servant servant;
 
-            if (unique)
-            {
-                servantMap.remove(servant);
-            }
+        if ((servant = (Servant)objectMap.get(oidbak)) == null)
+        {
+            return;
+        }
 
-            // Wait to remove the oid from the deactivationList here so that the
-            // object map can be cleared out first. This ensures we don't
-            // reactivate an object we're currently deactivating.
-            deactivationList.removeElement(oidbak);
+        /* object deactivation */
 
-            if (logger.isInfoEnabled())
-            {
-                logger.info("oid: " + POAUtil.convert(oid) +
-                            "object is deactivated");
-            }
-
-            // notify an aom listener
-            if (aomListener != null)
-            {
-                aomListener.objectDeactivated(oid, servant, objectMap.size());
-            }
+        objectMap.remove(oidbak);
 
-            if (servantActivator == null)
-            {
-                requestController.freeObject(oid);
-                // Tell anyone waiting we're done now.
-                notifyAll();
-                return;
-            }
+        if (unique)
+        {
+            servantMap.remove(servant);
+        }
 
-            /* servant etherealization */
+        // Wait to remove the oid from the deactivationList here so that the
+        // object map can be cleared out first. This ensures we don't
+        // reactivate an object we're currently deactivating.
+        deactivationList.removeElement(oidbak);
 
-            /* all invocations of incarnate on the servant manager are
-               serialized,  all  invocations   of  etherealize  on  the
-               servant manager are serialized, invocations of incarnate
-               and etherialize are mutually exclusive */
+        if (logger.isInfoEnabled())
+        {
+            logger.info("oid: " + POAUtil.convert(oid) +
+                        "object is deactivated");
+        }
 
-            while (!incarnationList.isEmpty() || !etherealisationList.isEmpty())
-            {
-                try
-                {
-                    wait();
-                }
-                catch (InterruptedException e)
-                {
-                }
-            }
-            etherealisationList.addElement(oidbak);
+        // notify an aom listener
+        if (aomListener != null)
+        {
+            aomListener.objectDeactivated(oid, servant, objectMap.size());
+        }
 
-            try
-            {
-                servantActivator.etherealize
-                (
-                    oid,
-                    poa,
-                    servant,
-                    cleanupInProgress,
-                    contains(servant)
-                );
+        if (servantActivator == null)
+        {
+            // Tell anyone waiting we're done now.
+            notifyAll();
+            return;
+        }
 
-                if (logger.isInfoEnabled())
-                {
-                    logger.info("oid: " + POAUtil.convert(oid) +
-                                "servant is etherealized");
-                }
+        /* servant etherealization */
 
-                // notify an aom listener
+        /* all invocations of incarnate on the servant manager are
+           serialized,  all  invocations   of  etherealize  on  the
+           servant manager are serialized, invocations of incarnate
+           and etherialize are mutually exclusive */
 
-                if (aomListener != null)
-                {
-                    aomListener.servantEtherialized(oid, servant);
-                }
+        while (!incarnationList.isEmpty() || !etherealisationList.isEmpty())
+        {
+            try
+            {
+                wait();
             }
-            catch (org.omg.CORBA.SystemException e)
+            catch (InterruptedException e)
             {
-                if (logger.isWarnEnabled())
-                {
-                    logger.info("oid: " + POAUtil.convert(oid) +
-                                "exception occurred during servant etherialisation: " + e.getMessage()
-                                );
-                }
             }
-            finally
+        }
+        etherealisationList.addElement(oidbak);
+
+        try
+        {
+            servantActivator.etherealize
+            (
+                oid,
+                poa,
+                servant,
+                cleanupInProgress,
+                contains(servant)
+            );
+
+            if (logger.isInfoEnabled())
             {
-                etherealisationList.removeElement(oidbak);
-                notifyAll();
+                logger.info("oid: " + POAUtil.convert(oid) +
+                            "servant is etherealized");
             }
 
-            // unregister the object from deactivation list
-            if (requestController != null)
+            // notify an aom listener
+
+            if (aomListener != null)
             {
-                requestController.freeObject(oid);
+                aomListener.servantEtherialized(oid, servant);
             }
         }
+        catch (org.omg.CORBA.SystemException e)
+        {
+            if (logger.isWarnEnabled())
+            {
+                logger.info("oid: " + POAUtil.convert(oid) +
+                            "exception occurred during servant etherialisation: " + e.getMessage()
+                           );
+            }
+        }
+        finally
+        {
+            etherealisationList.removeElement(oidbak);
+            notifyAll();
+        }
     }
 
     protected void removeAll( ServantActivator servant_activator,
                               POA poa,
                               boolean cleanup_in_progress )
     {
-        byte[] oid;
-        Enumeration en = objectMap.keys();
-        while (en.hasMoreElements())
+        final Iterator i = new HashSet(objectMap.keySet()).iterator();
+        while (i.hasNext())
         {
-            oid = ((ByteArrayKey) en.nextElement()).getBytes();
+            final ByteArrayKey oid = (ByteArrayKey) i.next();
             _remove(oid, null, servant_activator, poa, cleanup_in_progress);
         }
     }
Index: src/org/jacorb/poa/RequestController.java
===================================================================
RCS file: /web/www.jacorb.org/cvs/jacorb/JacORB/src/org/jacorb/poa/RequestController.java,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- src/org/jacorb/poa/RequestController.java	3 May 2009 21:36:17 -0000	1.38
+++ src/org/jacorb/poa/RequestController.java	1 Dec 2009 17:32:22 -0000	1.39
@@ -38,7 +38,7 @@
  * requests out from the queue and will see that the necessary steps are taken.
  *
  * @author Reimo Tiedemann
- * @version $Id: RequestController.java,v 1.38 2009-05-03 21:36:17 andre.spiegel Exp $
+ * @version $Id: RequestController.java,v 1.39 2009-12-01 17:32:22 alexander.bykov Exp $
  */
 
 public final class RequestController
@@ -535,10 +535,8 @@
      * those invocations.
      */
 
-    synchronized void waitForObjectCompletion( byte[] oid )
+    synchronized void waitForObjectCompletion( ByteArrayKey oidbak )
     {
-        ByteArrayKey oidbak = new ByteArrayKey( oid );
-
         while (activeRequestTable.contains(oidbak))
         {
             try
@@ -551,7 +549,7 @@
         }
         if (logger.isDebugEnabled())
         {
-            logger.debug( POAUtil.convert(oid) +
+            logger.debug( POAUtil.convert(oidbak.getBytes ()) +
                           "all active processors for this object have finished");
 
         }

