corba/src/share/classes/com/sun/corba/se/impl/transport/CorbaResponseWaitingRoomImpl.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2001, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -23,11 +23,14 @@
  * questions.
  */
 
 package com.sun.corba.se.impl.transport;
 
-import java.util.Hashtable;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
 
 import org.omg.CORBA.CompletionStatus;
 import org.omg.CORBA.SystemException;
 
 import com.sun.corba.se.pept.encoding.InputObject;

@@ -66,19 +69,20 @@
     private ORB orb;
     private ORBUtilSystemException wrapper ;
 
     private CorbaConnection connection;
     // Maps requestId to an OutCallDesc.
-    private Hashtable out_calls = null; // REVISIT - use int hastable/map
+    final private Map<Integer, OutCallDesc> out_calls;
 
     public CorbaResponseWaitingRoomImpl(ORB orb, CorbaConnection connection)
     {
         this.orb = orb;
         wrapper = ORBUtilSystemException.get( orb,
             CORBALogDomains.RPC_TRANSPORT ) ;
         this.connection = connection;
-        out_calls = new Hashtable();
+        out_calls =
+            Collections.synchronizedMap(new HashMap<Integer, OutCallDesc>());
     }
 
     ////////////////////////////////////////////////////
     //
     // pept.transport.ResponseWaitingRoom

@@ -137,11 +141,11 @@
             }
 
             return null;
         }
 
-        OutCallDesc call = (OutCallDesc)out_calls.get(requestId);
+        OutCallDesc call = out_calls.get(requestId);
         if (call == null) {
             throw wrapper.nullOutCall(CompletionStatus.COMPLETED_MAYBE);
         }
 
         synchronized(call.done) {

@@ -195,11 +199,11 @@
     {
         CDRInputObject inputObject = (CDRInputObject) is;
         LocateReplyOrReplyMessage header = (LocateReplyOrReplyMessage)
             inputObject.getMessageHeader();
         Integer requestId = new Integer(header.getRequestId());
-        OutCallDesc call = (OutCallDesc) out_calls.get(requestId);
+        OutCallDesc call = out_calls.get(requestId);
 
         if (orb.transportDebugFlag) {
             dprint(".responseReceived: id/"
                    + requestId  + ": "
                    + header);

@@ -246,11 +250,10 @@
         }
     }
 
     public int numberRegistered()
     {
-        // Note: Hashtable.size() is not synchronized
         return out_calls.size();
     }
 
     //////////////////////////////////////////////////
     //

@@ -262,16 +265,23 @@
 
         if (orb.transportDebugFlag) {
             dprint(".signalExceptionToAllWaiters: " + systemException);
         }
 
-        OutCallDesc call;
-        java.util.Enumeration e = out_calls.elements();
-        while(e.hasMoreElements()) {
-            call = (OutCallDesc) e.nextElement();
+        synchronized (out_calls) {
+            if (orb.transportDebugFlag) {
+                dprint(".signalExceptionToAllWaiters: out_calls size :" + 
+                       out_calls.size());
+            }
 
-            synchronized(call.done){
+            for (OutCallDesc call : out_calls.values()) { 
+                if (orb.transportDebugFlag) {
+                    dprint(".signalExceptionToAllWaiters: signaling " + 
+                            call);
+                }
+                synchronized(call.done) {
+                    try {
                 // anything waiting for BufferManagerRead's fragment queue
                 // needs to be cancelled
                 CorbaMessageMediator corbaMsgMediator =
                              (CorbaMessageMediator)call.messageMediator;
                 CDRInputObject inputObject =

@@ -282,21 +292,26 @@
                     BufferManagerReadStream bufferManager =
                         (BufferManagerReadStream)inputObject.getBufferManager();
                     int requestId = corbaMsgMediator.getRequestId();
                     bufferManager.cancelProcessing(requestId);
                 }
+                    } catch (Exception e) {
+                    } finally {
+                        // attempt to wake up waiting threads in all cases
                 call.inputObject = null;
                 call.exception = systemException;
-                call.done.notify();
+                        call.done.notifyAll();
             }
         }
     }
+        }
+    }
 
     public MessageMediator getMessageMediator(int requestId)
     {
         Integer id = new Integer(requestId);
-        OutCallDesc call = (OutCallDesc) out_calls.get(id);
+        OutCallDesc call = out_calls.get(id);
         if (call == null) {
             // This can happen when getting early reply fragments for a
             // request which has completed (e.g., client marshaling error).
             return null;
         }