diff --git a/jme3-networking/src/main/java/com/jme3/network/base/DefaultClient.java b/jme3-networking/src/main/java/com/jme3/network/base/DefaultClient.java index b297a933b..82c9f70cd 100644 --- a/jme3-networking/src/main/java/com/jme3/network/base/DefaultClient.java +++ b/jme3-networking/src/main/java/com/jme3/network/base/DefaultClient.java @@ -100,6 +100,7 @@ public class DefaultClient implements Client } protected void addStandardServices() { + log.fine("Adding standard services..."); services.addService(new ClientSerializerRegistrationsService()); } @@ -222,6 +223,9 @@ public class DefaultClient implements Client public void send( Message message ) { + if( log.isLoggable(Level.FINER) ) { + log.log(Level.FINER, "send({0})", message); + } if( message.isReliable() || channels.get(CH_UNRELIABLE) == null ) { send(CH_RELIABLE, message, true); } else { @@ -231,6 +235,9 @@ public class DefaultClient implements Client public void send( int channel, Message message ) { + if( log.isLoggable(Level.FINER) ) { + log.log(Level.FINER, "send({0}, {1})", new Object[]{channel, message}); + } if( channel >= 0 ) { // Make sure we aren't still connecting. Channels // won't be valid until we are fully connected since @@ -287,9 +294,11 @@ public class DefaultClient implements Client if( !isRunning ) return; - // Let the services get a chance to stop before we - // kill the connection. - services.stop(); + if( services.isStarted() ) { + // Let the services get a chance to stop before we + // kill the connection. + services.stop(); + } // Send a close message diff --git a/jme3-networking/src/main/java/com/jme3/network/base/DefaultServer.java b/jme3-networking/src/main/java/com/jme3/network/base/DefaultServer.java index 2b9add2ef..d7ee17033 100644 --- a/jme3-networking/src/main/java/com/jme3/network/base/DefaultServer.java +++ b/jme3-networking/src/main/java/com/jme3/network/base/DefaultServer.java @@ -108,6 +108,7 @@ public class DefaultServer implements Server } protected void addStandardServices() { + log.fine("Adding standard services..."); services.addService(new ServerSerializerRegistrationsService()); } @@ -221,6 +222,10 @@ public class DefaultServer implements Server public void broadcast( Filter filter, Message message ) { + if( log.isLoggable(Level.FINER) ) { + log.log(Level.FINER, "broadcast({0}, {1})", new Object[]{filter, message}); + } + if( connections.isEmpty() ) return; @@ -239,6 +244,10 @@ public class DefaultServer implements Server public void broadcast( int channel, Filter filter, Message message ) { + if( log.isLoggable(Level.FINER) ) { + log.log(Level.FINER, "broadcast({0}, {1}. {2})", new Object[]{channel, filter, message}); + } + if( connections.isEmpty() ) return; @@ -540,6 +549,9 @@ public class DefaultServer implements Server public void send( Message message ) { + if( log.isLoggable(Level.FINER) ) { + log.log(Level.FINER, "send({0})", message); + } ByteBuffer buffer = MessageProtocol.messageToBuffer(message, null); if( message.isReliable() || channels[CH_UNRELIABLE] == null ) { channels[CH_RELIABLE].send( buffer ); @@ -550,6 +562,9 @@ public class DefaultServer implements Server public void send( int channel, Message message ) { + if( log.isLoggable(Level.FINER) ) { + log.log(Level.FINER, "send({0}, {1})", new Object[]{channel, message}); + } checkChannel(channel); ByteBuffer buffer = MessageProtocol.messageToBuffer(message, null); channels[channel+CH_FIRST].send(buffer); diff --git a/jme3-networking/src/main/java/com/jme3/network/serializing/Serializer.java b/jme3-networking/src/main/java/com/jme3/network/serializing/Serializer.java index d4c054403..7e6b18849 100644 --- a/jme3-networking/src/main/java/com/jme3/network/serializing/Serializer.java +++ b/jme3-networking/src/main/java/com/jme3/network/serializing/Serializer.java @@ -45,6 +45,7 @@ import java.nio.ByteBuffer; import java.util.*; import java.util.jar.Attributes; import java.util.logging.Level; +import java.util.logging.LogManager; import java.util.logging.Logger; /** @@ -403,6 +404,10 @@ public abstract class Serializer { if (reg == null) { throw new SerializerException( "Class not registered:" + type ); } + + if( log.isLoggable(Level.FINER) ) { + log.log(Level.FINER, "writing class:{0} with ID:{1}", new Object[]{type, reg.getId()}); + } buffer.putShort(reg.getId()); return reg; } diff --git a/jme3-networking/src/main/java/com/jme3/network/service/AbstractService.java b/jme3-networking/src/main/java/com/jme3/network/service/AbstractService.java index 370b1c5af..3123e8c82 100644 --- a/jme3-networking/src/main/java/com/jme3/network/service/AbstractService.java +++ b/jme3-networking/src/main/java/com/jme3/network/service/AbstractService.java @@ -106,6 +106,6 @@ public abstract class AbstractService implements Servi @Override public String toString() { - return getClass().getName() + "[serviceManager.class=" + serviceManager.getClass() + "]"; + return getClass().getName() + "[serviceManager.class=" + (serviceManager != null ? serviceManager.getClass() : "") + "]"; } } diff --git a/jme3-networking/src/main/java/com/jme3/network/service/ServiceManager.java b/jme3-networking/src/main/java/com/jme3/network/service/ServiceManager.java index b8ee7d3c4..605c7e642 100644 --- a/jme3-networking/src/main/java/com/jme3/network/service/ServiceManager.java +++ b/jme3-networking/src/main/java/com/jme3/network/service/ServiceManager.java @@ -34,6 +34,8 @@ package com.jme3.network.service; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; +import java.util.logging.Level; +import java.util.logging.Logger; /** * The base service manager class from which the HostedServiceManager @@ -44,6 +46,8 @@ import java.util.concurrent.CopyOnWriteArrayList; */ public abstract class ServiceManager { + static final Logger log = Logger.getLogger(ServiceManager.class.getName()); + private List> services = new CopyOnWriteArrayList>(); private volatile boolean started = false; @@ -76,6 +80,9 @@ public abstract class ServiceManager { return; } for( Service s : services ) { + if( log.isLoggable(Level.FINE) ) { + log.log(Level.FINE, "Starting service:{0}", s); + } s.start(); } started = true; @@ -96,6 +103,9 @@ public abstract class ServiceManager { throw new IllegalStateException(getClass().getSimpleName() + " not started."); } for( Service s : services ) { + if( log.isLoggable(Level.FINE) ) { + log.log(Level.FINE, "Stopping service:{0}", s); + } s.stop(); } started = false; @@ -106,9 +116,18 @@ public abstract class ServiceManager { * has already been started then the service will also be started. */ public > void addService( S s ) { + if( log.isLoggable(Level.FINE) ) { + log.log(Level.FINE, "addService({0})", s); + } services.add(s); + if( log.isLoggable(Level.FINE) ) { + log.log(Level.FINE, "Initializing service:{0}", s); + } s.initialize(getParent()); if( started ) { + if( log.isLoggable(Level.FINE) ) { + log.log(Level.FINE, "Starting service:{0}", s); + } s.start(); } } @@ -120,10 +139,19 @@ public abstract class ServiceManager { * the service will be terminated. */ public > void removeService( S s ) { + if( log.isLoggable(Level.FINE) ) { + log.log(Level.FINE, "removeService({0})", s); + } if( started ) { + if( log.isLoggable(Level.FINE) ) { + log.log(Level.FINE, "Stopping service:{0}", s); + } s.stop(); } services.remove(s); + if( log.isLoggable(Level.FINE) ) { + log.log(Level.FINE, "Terminating service:{0}", s); + } s.terminate(getParent()); }