# HG changeset patch # User skoppar # Date 1286438380 25200 # Node ID cf90ea1653fbf98f2b3a4d5a0a64127f14cb75dd # Parent 8c840d3ab24f8d0f422b991638acb44b6ab1d98c 6714797: InitialContext.close does not close NIO socket connections Reviewed-by: asaha diff -r 8c840d3ab24f -r cf90ea1653fb corba/src/share/classes/com/sun/corba/se/impl/transport/CorbaConnectionCacheBase.java --- a/corba/src/share/classes/com/sun/corba/se/impl/transport/CorbaConnectionCacheBase.java Wed Jul 05 17:28:07 2017 +0200 +++ b/corba/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; diff -r 8c840d3ab24f -r cf90ea1653fb corba/src/share/classes/com/sun/corba/se/impl/transport/CorbaTransportManagerImpl.java --- a/corba/src/share/classes/com/sun/corba/se/impl/transport/CorbaTransportManagerImpl.java Wed Jul 05 17:28:07 2017 +0200 +++ b/corba/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) { diff -r 8c840d3ab24f -r cf90ea1653fb corba/src/share/classes/com/sun/corba/se/impl/transport/SocketOrChannelConnectionImpl.java --- a/corba/src/share/classes/com/sun/corba/se/impl/transport/SocketOrChannelConnectionImpl.java Wed Jul 05 17:28:07 2017 +0200 +++ b/corba/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; diff -r 8c840d3ab24f -r cf90ea1653fb corba/src/share/classes/com/sun/corba/se/pept/transport/ConnectionCache.java --- a/corba/src/share/classes/com/sun/corba/se/pept/transport/ConnectionCache.java Wed Jul 05 17:28:07 2017 +0200 +++ b/corba/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. diff -r 8c840d3ab24f -r cf90ea1653fb corba/src/share/classes/com/sun/corba/se/spi/transport/CorbaConnection.java --- a/corba/src/share/classes/com/sun/corba/se/spi/transport/CorbaConnection.java Wed Jul 05 17:28:07 2017 +0200 +++ b/corba/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.