Added a bunch of lower level logging that can be

used to either watch traffic or debug serialization
issues, etc..
Went ahead and instrumented the service manager while
I was at it... and fixed a potential NPE in the AbstractService's
toString() method.
Fixed a bug in the DefaultClient where it couldn't be shutdown
if attempted before the services had been started.
cleanup_build_scripts
Paul Speed 9 years ago
parent 022899c199
commit 388a8a8bd7
  1. 9
      jme3-networking/src/main/java/com/jme3/network/base/DefaultClient.java
  2. 15
      jme3-networking/src/main/java/com/jme3/network/base/DefaultServer.java
  3. 5
      jme3-networking/src/main/java/com/jme3/network/serializing/Serializer.java
  4. 2
      jme3-networking/src/main/java/com/jme3/network/service/AbstractService.java
  5. 28
      jme3-networking/src/main/java/com/jme3/network/service/ServiceManager.java

@ -100,6 +100,7 @@ public class DefaultClient implements Client
} }
protected void addStandardServices() { protected void addStandardServices() {
log.fine("Adding standard services...");
services.addService(new ClientSerializerRegistrationsService()); services.addService(new ClientSerializerRegistrationsService());
} }
@ -222,6 +223,9 @@ public class DefaultClient implements Client
public void send( Message message ) 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 ) { if( message.isReliable() || channels.get(CH_UNRELIABLE) == null ) {
send(CH_RELIABLE, message, true); send(CH_RELIABLE, message, true);
} else { } else {
@ -231,6 +235,9 @@ public class DefaultClient implements Client
public void send( int channel, Message message ) 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 ) { if( channel >= 0 ) {
// Make sure we aren't still connecting. Channels // Make sure we aren't still connecting. Channels
// won't be valid until we are fully connected since // won't be valid until we are fully connected since
@ -287,9 +294,11 @@ public class DefaultClient implements Client
if( !isRunning ) if( !isRunning )
return; return;
if( services.isStarted() ) {
// Let the services get a chance to stop before we // Let the services get a chance to stop before we
// kill the connection. // kill the connection.
services.stop(); services.stop();
}
// Send a close message // Send a close message

@ -108,6 +108,7 @@ public class DefaultServer implements Server
} }
protected void addStandardServices() { protected void addStandardServices() {
log.fine("Adding standard services...");
services.addService(new ServerSerializerRegistrationsService()); services.addService(new ServerSerializerRegistrationsService());
} }
@ -221,6 +222,10 @@ public class DefaultServer implements Server
public void broadcast( Filter<? super HostedConnection> filter, Message message ) public void broadcast( Filter<? super HostedConnection> filter, Message message )
{ {
if( log.isLoggable(Level.FINER) ) {
log.log(Level.FINER, "broadcast({0}, {1})", new Object[]{filter, message});
}
if( connections.isEmpty() ) if( connections.isEmpty() )
return; return;
@ -239,6 +244,10 @@ public class DefaultServer implements Server
public void broadcast( int channel, Filter<? super HostedConnection> filter, Message message ) public void broadcast( int channel, Filter<? super HostedConnection> filter, Message message )
{ {
if( log.isLoggable(Level.FINER) ) {
log.log(Level.FINER, "broadcast({0}, {1}. {2})", new Object[]{channel, filter, message});
}
if( connections.isEmpty() ) if( connections.isEmpty() )
return; return;
@ -540,6 +549,9 @@ public class DefaultServer implements Server
public void send( Message message ) public void send( Message message )
{ {
if( log.isLoggable(Level.FINER) ) {
log.log(Level.FINER, "send({0})", message);
}
ByteBuffer buffer = MessageProtocol.messageToBuffer(message, null); ByteBuffer buffer = MessageProtocol.messageToBuffer(message, null);
if( message.isReliable() || channels[CH_UNRELIABLE] == null ) { if( message.isReliable() || channels[CH_UNRELIABLE] == null ) {
channels[CH_RELIABLE].send( buffer ); channels[CH_RELIABLE].send( buffer );
@ -550,6 +562,9 @@ public class DefaultServer implements Server
public void send( int channel, Message message ) 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); checkChannel(channel);
ByteBuffer buffer = MessageProtocol.messageToBuffer(message, null); ByteBuffer buffer = MessageProtocol.messageToBuffer(message, null);
channels[channel+CH_FIRST].send(buffer); channels[channel+CH_FIRST].send(buffer);

@ -45,6 +45,7 @@ import java.nio.ByteBuffer;
import java.util.*; import java.util.*;
import java.util.jar.Attributes; import java.util.jar.Attributes;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger; import java.util.logging.Logger;
/** /**
@ -403,6 +404,10 @@ public abstract class Serializer {
if (reg == null) { if (reg == null) {
throw new SerializerException( "Class not registered:" + type ); 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()); buffer.putShort(reg.getId());
return reg; return reg;
} }

@ -106,6 +106,6 @@ public abstract class AbstractService<S extends ServiceManager> implements Servi
@Override @Override
public String toString() { public String toString() {
return getClass().getName() + "[serviceManager.class=" + serviceManager.getClass() + "]"; return getClass().getName() + "[serviceManager.class=" + (serviceManager != null ? serviceManager.getClass() : "") + "]";
} }
} }

@ -34,6 +34,8 @@ package com.jme3.network.service;
import java.util.List; import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
/** /**
* The base service manager class from which the HostedServiceManager * The base service manager class from which the HostedServiceManager
@ -44,6 +46,8 @@ import java.util.concurrent.CopyOnWriteArrayList;
*/ */
public abstract class ServiceManager<T> { public abstract class ServiceManager<T> {
static final Logger log = Logger.getLogger(ServiceManager.class.getName());
private List<Service<T>> services = new CopyOnWriteArrayList<Service<T>>(); private List<Service<T>> services = new CopyOnWriteArrayList<Service<T>>();
private volatile boolean started = false; private volatile boolean started = false;
@ -76,6 +80,9 @@ public abstract class ServiceManager<T> {
return; return;
} }
for( Service<T> s : services ) { for( Service<T> s : services ) {
if( log.isLoggable(Level.FINE) ) {
log.log(Level.FINE, "Starting service:{0}", s);
}
s.start(); s.start();
} }
started = true; started = true;
@ -96,6 +103,9 @@ public abstract class ServiceManager<T> {
throw new IllegalStateException(getClass().getSimpleName() + " not started."); throw new IllegalStateException(getClass().getSimpleName() + " not started.");
} }
for( Service<T> s : services ) { for( Service<T> s : services ) {
if( log.isLoggable(Level.FINE) ) {
log.log(Level.FINE, "Stopping service:{0}", s);
}
s.stop(); s.stop();
} }
started = false; started = false;
@ -106,9 +116,18 @@ public abstract class ServiceManager<T> {
* has already been started then the service will also be started. * has already been started then the service will also be started.
*/ */
public <S extends Service<T>> void addService( S s ) { public <S extends Service<T>> void addService( S s ) {
if( log.isLoggable(Level.FINE) ) {
log.log(Level.FINE, "addService({0})", s);
}
services.add(s); services.add(s);
if( log.isLoggable(Level.FINE) ) {
log.log(Level.FINE, "Initializing service:{0}", s);
}
s.initialize(getParent()); s.initialize(getParent());
if( started ) { if( started ) {
if( log.isLoggable(Level.FINE) ) {
log.log(Level.FINE, "Starting service:{0}", s);
}
s.start(); s.start();
} }
} }
@ -120,10 +139,19 @@ public abstract class ServiceManager<T> {
* the service will be terminated. * the service will be terminated.
*/ */
public <S extends Service<T>> void removeService( S s ) { public <S extends Service<T>> void removeService( S s ) {
if( log.isLoggable(Level.FINE) ) {
log.log(Level.FINE, "removeService({0})", s);
}
if( started ) { if( started ) {
if( log.isLoggable(Level.FINE) ) {
log.log(Level.FINE, "Stopping service:{0}", s);
}
s.stop(); s.stop();
} }
services.remove(s); services.remove(s);
if( log.isLoggable(Level.FINE) ) {
log.log(Level.FINE, "Terminating service:{0}", s);
}
s.terminate(getParent()); s.terminate(getParent());
} }

Loading…
Cancel
Save