Jelajahi Sumber

Redoing some of the isConnected checking and connection
close logging to be less verbose... and to not print out
logged infos that look like warnings about "connections
already being closed."
While I was at it, I added so FINE logging about the
sizes of the maps when the elements are removed to make
sure everything is being cleaned up properly.


git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8944 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

PSp..om 14 tahun lalu
induk
melakukan
5ed66f47e7

+ 6 - 3
engine/src/networking/com/jme3/network/base/ConnectorAdapter.java

@@ -120,9 +120,12 @@ public class ConnectorAdapter extends Thread
 
         // Kill the writer service
         writer.shutdown();
-        
-        // Kill the connector
-        connector.close();
+ 
+        if( connector.isConnected() )
+            {       
+            // Kill the connector
+            connector.close();
+            }
     }
  
     protected void dispatch( Message m )

+ 8 - 2
engine/src/networking/com/jme3/network/base/DefaultServer.java

@@ -398,7 +398,11 @@ public class DefaultServer implements Server
 
     protected void connectionClosed( Endpoint p )
     {
-        log.log( Level.INFO, "Connection closed:{0}.", p );
+        if( p.isConnected() ) {
+            log.log( Level.INFO, "Connection closed:{0}.", p );
+        } else {
+            log.log( Level.FINE, "Connection closed:{0}.", p );
+        }
         
         // Try to find the endpoint in all ways that it might
         // exist.  Note: by this point the raw network channel is 
@@ -424,7 +428,9 @@ public class DefaultServer implements Server
         
         // Better not to fire events while we hold a lock
         // so always do this outside the synch block.
-        if( removed != null ) {
+        // Note: checking removed.closed just to avoid spurious log messages
+        //       since in general we are called back for every endpoint closing.
+        if( removed != null && !removed.closed ) {
         
             log.log( Level.INFO, "Client closed:{0}.", removed );
             

+ 2 - 0
engine/src/networking/com/jme3/network/base/KernelAdapter.java

@@ -135,6 +135,8 @@ public class KernelAdapter extends Thread
         // Remove any message buffer we've been accumulating 
         // on behalf of this endpoing
         messageBuffers.remove(p);
+
+        log.log( Level.FINE, "Buffers size:{0}", messageBuffers.size() );
     
         server.connectionClosed(p);
     }

+ 3 - 0
engine/src/networking/com/jme3/network/kernel/tcp/NioEndpoint.java

@@ -89,6 +89,9 @@ public class NioEndpoint implements Endpoint
         }
     
         try {
+            // Note: even though we may be disconnected from the socket.isConnected()
+            // standpoint, it's still safest to tell the kernel so that it can be sure
+            // to stop managing us gracefully.
             kernel.closeEndpoint(this);
         } catch( IOException e ) {
             throw new KernelException( "Error closing endpoint for socket:" + socket, e );

+ 9 - 5
engine/src/networking/com/jme3/network/kernel/tcp/SelectorKernel.java

@@ -160,6 +160,7 @@ public class SelectorKernel extends AbstractKernel
     protected void removeEndpoint( NioEndpoint p, SocketChannel c )
     {
         endpoints.remove( p.getId() );
+        log.log( Level.FINE, "Endpoints size:{0}", endpoints.size() );
 
         // Enqueue an endpoint event for the listeners
         addEvent( EndpointEvent.createRemove( this, p ) );
@@ -180,7 +181,7 @@ public class SelectorKernel extends AbstractKernel
      */
     protected void closeEndpoint( NioEndpoint p ) throws IOException
     {
-        log.log( Level.INFO, "Closing endpoint:{0}.", p );
+        //log.log( Level.INFO, "Closing endpoint:{0}.", p );
             
         thread.cancel(p);
     }
@@ -322,13 +323,14 @@ public class SelectorKernel extends AbstractKernel
 
         protected void cancel( NioEndpoint p ) throws IOException
         {
-            log.log( Level.INFO, "Closing endpoint:{0}.", p );
             SelectionKey key = endpointKeys.remove(p);
             if( key == null ) {
-                log.log( Level.INFO, "Endpoint already closed:{0}.", p );
+                //log.log( Level.INFO, "Endpoint already closed:{0}.", p );
                 return;  // already closed it
             }                
+            log.log( Level.FINE, "Endpoint keys size:{0}", endpointKeys.size() );
 
+            log.log( Level.INFO, "Closing endpoint:{0}.", p );
             SocketChannel c = (SocketChannel)key.channel();
 
             // Note: key.cancel() is specifically thread safe.  One of
@@ -341,9 +343,11 @@ public class SelectorKernel extends AbstractKernel
 
         protected void cancel( SelectionKey key, SocketChannel c ) throws IOException
         {
-            NioEndpoint p = (NioEndpoint)key.attachment();
+            NioEndpoint p = (NioEndpoint)key.attachment();            
             log.log( Level.INFO, "Closing channel endpoint:{0}.", p );
-            endpointKeys.remove(p);
+            Object o = endpointKeys.remove(p);
+
+            log.log( Level.FINE, "Endpoint keys size:{0}", endpointKeys.size() );
 
             key.cancel();
             c.close();

+ 5 - 3
engine/src/networking/com/jme3/network/kernel/udp/UdpKernel.java

@@ -162,10 +162,12 @@ public class UdpKernel extends AbstractKernel
      */
     protected void closeEndpoint( UdpEndpoint p ) throws IOException
     {
-        log.log( Level.INFO, "Closing endpoint:{0}.", p );
-            
         // Just book-keeping to do here.
-        socketEndpoints.remove( p.getRemoteAddress() );
+        if( socketEndpoints.remove( p.getRemoteAddress() ) == null )
+            return;
+
+        log.log( Level.INFO, "Closing endpoint:{0}.", p );            
+        log.log( Level.FINE, "Socket endpoints size:{0}", socketEndpoints.size() );
 
         addEvent( EndpointEvent.createRemove( this, p ) );