changeset 231:e0f7ed041196

6714797: InitialContext.close does not close NIO socket connections Reviewed-by: asaha
author skoppar
date Thu, 07 Oct 2010 00:59:40 -0700
parents cff5a173ec1e
children 459c07278c3c
files src/share/classes/com/sun/corba/se/impl/transport/CorbaConnectionCacheBase.java src/share/classes/com/sun/corba/se/impl/transport/CorbaTransportManagerImpl.java src/share/classes/com/sun/corba/se/impl/transport/SocketOrChannelConnectionImpl.java src/share/classes/com/sun/corba/se/pept/transport/ConnectionCache.java src/share/classes/com/sun/corba/se/spi/transport/CorbaConnection.java
diffstat 5 files changed, 53 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/corba/se/impl/transport/CorbaConnectionCacheBase.java	Mon Nov 15 10:47:48 2010 -0800
+++ b/src/share/classes/com/sun/corba/se/impl/transport/CorbaConnectionCacheBase.java	Thu Oct 07 00:59:40 2010 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2010, 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
@@ -34,6 +34,7 @@
 
 import com.sun.corba.se.spi.logging.CORBALogDomains;
 import com.sun.corba.se.spi.orb.ORB;
+import com.sun.corba.se.spi.transport.CorbaConnection;
 import com.sun.corba.se.spi.transport.CorbaConnectionCache;
 
 import com.sun.corba.se.impl.logging.ORBUtilSystemException;
@@ -87,6 +88,14 @@
         }
     }
 
+    public void close() {
+        synchronized (backingStore()) {
+            for (Object obj : values()) {
+                ((CorbaConnection)obj).closeConnectionResources() ;
+            }
+        }
+    }
+
     public long numberOfIdleConnections()
     {
         long count = 0;
--- a/src/share/classes/com/sun/corba/se/impl/transport/CorbaTransportManagerImpl.java	Mon Nov 15 10:47:48 2010 -0800
+++ b/src/share/classes/com/sun/corba/se/impl/transport/CorbaTransportManagerImpl.java	Thu Oct 07 00:59:40 2010 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2010 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
@@ -38,6 +38,7 @@
 import org.omg.CORBA.CompletionStatus;
 
 import com.sun.corba.se.pept.transport.Acceptor;
+import com.sun.corba.se.pept.transport.ConnectionCache;
 import com.sun.corba.se.pept.transport.ByteBufferPool;
 import com.sun.corba.se.pept.transport.ContactInfo;
 import com.sun.corba.se.pept.transport.InboundConnectionCache;
@@ -49,6 +50,8 @@
 import com.sun.corba.se.spi.orb.ORB;
 import com.sun.corba.se.spi.transport.CorbaAcceptor;
 import com.sun.corba.se.spi.transport.CorbaTransportManager;
+import com.sun.corba.se.pept.transport.Connection;
+import com.sun.corba.se.pept.transport.ConnectionCache;
 
 // REVISIT - impl/poa specific:
 import com.sun.corba.se.impl.oa.poa.Policies;
@@ -182,6 +185,12 @@
             if (orb.transportDebugFlag) {
                 dprint(".close->");
             }
+            for (Object cc : outboundConnectionCaches.values()) {
+                ((ConnectionCache)cc).close() ;
+            }
+            for (Object cc : inboundConnectionCaches.values()) {
+                ((ConnectionCache)cc).close() ;
+            }
             getSelector(0).close();
         } finally {
             if (orb.transportDebugFlag) {
--- a/src/share/classes/com/sun/corba/se/impl/transport/SocketOrChannelConnectionImpl.java	Mon Nov 15 10:47:48 2010 -0800
+++ b/src/share/classes/com/sun/corba/se/impl/transport/SocketOrChannelConnectionImpl.java	Thu Oct 07 00:59:40 2010 -0700
@@ -811,6 +811,7 @@
                     dprint(".close: " + this, e);
                 }
             }
+            closeConnectionResources();
         } finally {
             if (orb.transportDebugFlag) {
                 dprint(".close<-: " + this);
@@ -818,6 +819,28 @@
         }
     }
 
+    public void closeConnectionResources() {
+           if (orb.transportDebugFlag) {
+               dprint(".closeConnectionResources->: " + this);
+           }
+           Selector selector = orb.getTransportManager().getSelector(0);
+           selector.unregisterForEvent(this);
+           try {
+             if (socketChannel != null)
+              socketChannel.close() ;
+                if (socket != null && !socket.isClosed())
+                socket.close() ;
+           } catch (IOException e) {
+             if (orb.transportDebugFlag) {
+                 dprint( ".closeConnectionResources: " + this, e ) ;
+             }
+           }
+           if (orb.transportDebugFlag) {
+               dprint(".closeConnectionResources<-: " + this);
+           }
+     }
+
+
     public Acceptor getAcceptor()
     {
         return acceptor;
--- a/src/share/classes/com/sun/corba/se/pept/transport/ConnectionCache.java	Mon Nov 15 10:47:48 2010 -0800
+++ b/src/share/classes/com/sun/corba/se/pept/transport/ConnectionCache.java	Thu Oct 07 00:59:40 2010 -0700
@@ -41,6 +41,12 @@
     public long numberOfBusyConnections();
 
     public boolean reclaim();
+
+    /** Close all connections in the connection cache.
+     * This is used as a final cleanup, and will result
+     * in abrupt termination of any pending communications.
+     */
+    public void close();
 }
 
 // End of file.
--- a/src/share/classes/com/sun/corba/se/spi/transport/CorbaConnection.java	Mon Nov 15 10:47:48 2010 -0800
+++ b/src/share/classes/com/sun/corba/se/spi/transport/CorbaConnection.java	Thu Oct 07 00:59:40 2010 -0700
@@ -163,6 +163,10 @@
     // REVISIT - MessageMediator parameter?
     public void serverRequestProcessingBegins();
     public void serverRequestProcessingEnds();
+
+    /** Clean up all connection resources.  Used when shutting down an ORB.
+     */
+    public void closeConnectionResources();
 }
 
 // End of file.