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
3.0
PSp..om 13 years ago
parent 010b9e0670
commit 5ed66f47e7
  1. 3
      engine/src/networking/com/jme3/network/base/ConnectorAdapter.java
  2. 8
      engine/src/networking/com/jme3/network/base/DefaultServer.java
  3. 2
      engine/src/networking/com/jme3/network/base/KernelAdapter.java
  4. 3
      engine/src/networking/com/jme3/network/kernel/tcp/NioEndpoint.java
  5. 12
      engine/src/networking/com/jme3/network/kernel/tcp/SelectorKernel.java
  6. 8
      engine/src/networking/com/jme3/network/kernel/udp/UdpKernel.java

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

@ -398,7 +398,11 @@ public class DefaultServer implements Server
protected void connectionClosed( Endpoint 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 );

@ -136,6 +136,8 @@ public class KernelAdapter extends Thread
// on behalf of this endpoing
messageBuffers.remove(p);
log.log( Level.FINE, "Buffers size:{0}", messageBuffers.size() );
server.connectionClosed(p);
}

@ -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 );

@ -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
@ -343,7 +345,9 @@ public class SelectorKernel extends AbstractKernel
{
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();

@ -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 ) );

Loading…
Cancel
Save