6714797: InitialContext.close does not close NIO socket connections
Reviewed-by: asaha
diff --git a/corba/src/share/classes/com/sun/corba/se/impl/transport/CorbaConnectionCacheBase.java b/corba/src/share/classes/com/sun/corba/se/impl/transport/CorbaConnectionCacheBase.java
index d8608f2..0cbce53 100644
--- a/corba/src/share/classes/com/sun/corba/se/impl/transport/CorbaConnectionCacheBase.java
+++ b/corba/src/share/classes/com/sun/corba/se/impl/transport/CorbaConnectionCacheBase.java
@@ -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;
diff --git a/corba/src/share/classes/com/sun/corba/se/impl/transport/CorbaTransportManagerImpl.java b/corba/src/share/classes/com/sun/corba/se/impl/transport/CorbaTransportManagerImpl.java
index 5f56b56..fae2d15 100644
--- a/corba/src/share/classes/com/sun/corba/se/impl/transport/CorbaTransportManagerImpl.java
+++ b/corba/src/share/classes/com/sun/corba/se/impl/transport/CorbaTransportManagerImpl.java
@@ -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) {
diff --git a/corba/src/share/classes/com/sun/corba/se/impl/transport/SocketOrChannelConnectionImpl.java b/corba/src/share/classes/com/sun/corba/se/impl/transport/SocketOrChannelConnectionImpl.java
index e294067..913cd90 100644
--- a/corba/src/share/classes/com/sun/corba/se/impl/transport/SocketOrChannelConnectionImpl.java
+++ b/corba/src/share/classes/com/sun/corba/se/impl/transport/SocketOrChannelConnectionImpl.java
@@ -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;
diff --git a/corba/src/share/classes/com/sun/corba/se/pept/transport/ConnectionCache.java b/corba/src/share/classes/com/sun/corba/se/pept/transport/ConnectionCache.java
index d5bee7d..ac926d0 100644
--- a/corba/src/share/classes/com/sun/corba/se/pept/transport/ConnectionCache.java
+++ b/corba/src/share/classes/com/sun/corba/se/pept/transport/ConnectionCache.java
@@ -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.
diff --git a/corba/src/share/classes/com/sun/corba/se/spi/transport/CorbaConnection.java b/corba/src/share/classes/com/sun/corba/se/spi/transport/CorbaConnection.java
index b0e3f6f..c7ec1ac 100644
--- a/corba/src/share/classes/com/sun/corba/se/spi/transport/CorbaConnection.java
+++ b/corba/src/share/classes/com/sun/corba/se/spi/transport/CorbaConnection.java
@@ -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.