6714797: InitialContext.close does not close NIO socket connections

Thu, 07 Oct 2010 00:59:40 -0700

author
skoppar
date
Thu, 07 Oct 2010 00:59:40 -0700
changeset 226
e0f7ed041196
parent 215
cff5a173ec1e
child 227
459c07278c3c

6714797: InitialContext.close does not close NIO socket connections
Reviewed-by: asaha

src/share/classes/com/sun/corba/se/impl/transport/CorbaConnectionCacheBase.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/corba/se/impl/transport/CorbaTransportManagerImpl.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/corba/se/impl/transport/SocketOrChannelConnectionImpl.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/corba/se/pept/transport/ConnectionCache.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/corba/se/spi/transport/CorbaConnection.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/corba/se/impl/transport/CorbaConnectionCacheBase.java	Mon Nov 15 10:47:48 2010 -0800
     1.2 +++ b/src/share/classes/com/sun/corba/se/impl/transport/CorbaConnectionCacheBase.java	Thu Oct 07 00:59:40 2010 -0700
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 2001, 2004, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -34,6 +34,7 @@
    1.11  
    1.12  import com.sun.corba.se.spi.logging.CORBALogDomains;
    1.13  import com.sun.corba.se.spi.orb.ORB;
    1.14 +import com.sun.corba.se.spi.transport.CorbaConnection;
    1.15  import com.sun.corba.se.spi.transport.CorbaConnectionCache;
    1.16  
    1.17  import com.sun.corba.se.impl.logging.ORBUtilSystemException;
    1.18 @@ -87,6 +88,14 @@
    1.19          }
    1.20      }
    1.21  
    1.22 +    public void close() {
    1.23 +        synchronized (backingStore()) {
    1.24 +            for (Object obj : values()) {
    1.25 +                ((CorbaConnection)obj).closeConnectionResources() ;
    1.26 +            }
    1.27 +        }
    1.28 +    }
    1.29 +
    1.30      public long numberOfIdleConnections()
    1.31      {
    1.32          long count = 0;
     2.1 --- a/src/share/classes/com/sun/corba/se/impl/transport/CorbaTransportManagerImpl.java	Mon Nov 15 10:47:48 2010 -0800
     2.2 +++ b/src/share/classes/com/sun/corba/se/impl/transport/CorbaTransportManagerImpl.java	Thu Oct 07 00:59:40 2010 -0700
     2.3 @@ -1,5 +1,5 @@
     2.4  /*
     2.5 - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
     2.6 + * Copyright (c) 2003, 2010 Oracle and/or its affiliates. All rights reserved.
     2.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.8   *
     2.9   * This code is free software; you can redistribute it and/or modify it
    2.10 @@ -38,6 +38,7 @@
    2.11  import org.omg.CORBA.CompletionStatus;
    2.12  
    2.13  import com.sun.corba.se.pept.transport.Acceptor;
    2.14 +import com.sun.corba.se.pept.transport.ConnectionCache;
    2.15  import com.sun.corba.se.pept.transport.ByteBufferPool;
    2.16  import com.sun.corba.se.pept.transport.ContactInfo;
    2.17  import com.sun.corba.se.pept.transport.InboundConnectionCache;
    2.18 @@ -49,6 +50,8 @@
    2.19  import com.sun.corba.se.spi.orb.ORB;
    2.20  import com.sun.corba.se.spi.transport.CorbaAcceptor;
    2.21  import com.sun.corba.se.spi.transport.CorbaTransportManager;
    2.22 +import com.sun.corba.se.pept.transport.Connection;
    2.23 +import com.sun.corba.se.pept.transport.ConnectionCache;
    2.24  
    2.25  // REVISIT - impl/poa specific:
    2.26  import com.sun.corba.se.impl.oa.poa.Policies;
    2.27 @@ -182,6 +185,12 @@
    2.28              if (orb.transportDebugFlag) {
    2.29                  dprint(".close->");
    2.30              }
    2.31 +            for (Object cc : outboundConnectionCaches.values()) {
    2.32 +                ((ConnectionCache)cc).close() ;
    2.33 +            }
    2.34 +            for (Object cc : inboundConnectionCaches.values()) {
    2.35 +                ((ConnectionCache)cc).close() ;
    2.36 +            }
    2.37              getSelector(0).close();
    2.38          } finally {
    2.39              if (orb.transportDebugFlag) {
     3.1 --- a/src/share/classes/com/sun/corba/se/impl/transport/SocketOrChannelConnectionImpl.java	Mon Nov 15 10:47:48 2010 -0800
     3.2 +++ b/src/share/classes/com/sun/corba/se/impl/transport/SocketOrChannelConnectionImpl.java	Thu Oct 07 00:59:40 2010 -0700
     3.3 @@ -811,6 +811,7 @@
     3.4                      dprint(".close: " + this, e);
     3.5                  }
     3.6              }
     3.7 +            closeConnectionResources();
     3.8          } finally {
     3.9              if (orb.transportDebugFlag) {
    3.10                  dprint(".close<-: " + this);
    3.11 @@ -818,6 +819,28 @@
    3.12          }
    3.13      }
    3.14  
    3.15 +    public void closeConnectionResources() {
    3.16 +           if (orb.transportDebugFlag) {
    3.17 +               dprint(".closeConnectionResources->: " + this);
    3.18 +           }
    3.19 +           Selector selector = orb.getTransportManager().getSelector(0);
    3.20 +           selector.unregisterForEvent(this);
    3.21 +           try {
    3.22 +             if (socketChannel != null)
    3.23 +              socketChannel.close() ;
    3.24 +                if (socket != null && !socket.isClosed())
    3.25 +                socket.close() ;
    3.26 +           } catch (IOException e) {
    3.27 +             if (orb.transportDebugFlag) {
    3.28 +                 dprint( ".closeConnectionResources: " + this, e ) ;
    3.29 +             }
    3.30 +           }
    3.31 +           if (orb.transportDebugFlag) {
    3.32 +               dprint(".closeConnectionResources<-: " + this);
    3.33 +           }
    3.34 +     }
    3.35 +
    3.36 +
    3.37      public Acceptor getAcceptor()
    3.38      {
    3.39          return acceptor;
     4.1 --- a/src/share/classes/com/sun/corba/se/pept/transport/ConnectionCache.java	Mon Nov 15 10:47:48 2010 -0800
     4.2 +++ b/src/share/classes/com/sun/corba/se/pept/transport/ConnectionCache.java	Thu Oct 07 00:59:40 2010 -0700
     4.3 @@ -41,6 +41,12 @@
     4.4      public long numberOfBusyConnections();
     4.5  
     4.6      public boolean reclaim();
     4.7 +
     4.8 +    /** Close all connections in the connection cache.
     4.9 +     * This is used as a final cleanup, and will result
    4.10 +     * in abrupt termination of any pending communications.
    4.11 +     */
    4.12 +    public void close();
    4.13  }
    4.14  
    4.15  // End of file.
     5.1 --- a/src/share/classes/com/sun/corba/se/spi/transport/CorbaConnection.java	Mon Nov 15 10:47:48 2010 -0800
     5.2 +++ b/src/share/classes/com/sun/corba/se/spi/transport/CorbaConnection.java	Thu Oct 07 00:59:40 2010 -0700
     5.3 @@ -163,6 +163,10 @@
     5.4      // REVISIT - MessageMediator parameter?
     5.5      public void serverRequestProcessingBegins();
     5.6      public void serverRequestProcessingEnds();
     5.7 +
     5.8 +    /** Clean up all connection resources.  Used when shutting down an ORB.
     5.9 +     */
    5.10 +    public void closeConnectionResources();
    5.11  }
    5.12  
    5.13  // End of file.

mercurial