From 197ed33c9e6a6e9f84adad75649407a2d4c5a986 Mon Sep 17 00:00:00 2001 From: Paul Speed Date: Sun, 22 Nov 2015 05:23:24 -0500 Subject: [PATCH] Added some missing @Overrides and finals. --- .../com/jme3/network/base/DefaultClient.java | 34 ++++++++--- .../com/jme3/network/base/DefaultServer.java | 56 ++++++++++++++----- .../jme3/network/base/MessageProtocol.java | 2 +- .../jme3/network/service/ServiceManager.java | 2 +- 4 files changed, 72 insertions(+), 22 deletions(-) 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 82c9f70cd..9881830a8 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 @@ -67,18 +67,18 @@ public class DefaultClient implements Client private static final int CH_UNRELIABLE = 1; private static final int CH_FIRST = 2; - private ThreadLocal dataBuffer = new ThreadLocal(); + private final ThreadLocal dataBuffer = new ThreadLocal(); private int id = -1; private boolean isRunning = false; - private CountDownLatch connecting = new CountDownLatch(1); + private final CountDownLatch connecting = new CountDownLatch(1); private String gameName; private int version; - private MessageListenerRegistry messageListeners = new MessageListenerRegistry(); - private List stateListeners = new CopyOnWriteArrayList(); - private List> errorListeners = new CopyOnWriteArrayList>(); - private Redispatch dispatcher = new Redispatch(); - private List channels = new ArrayList(); + private final MessageListenerRegistry messageListeners = new MessageListenerRegistry(); + private final List stateListeners = new CopyOnWriteArrayList(); + private final List> errorListeners = new CopyOnWriteArrayList>(); + private final Redispatch dispatcher = new Redispatch(); + private final List channels = new ArrayList(); private ConnectorFactory connectorFactory; @@ -129,6 +129,7 @@ public class DefaultClient implements Client throw new IllegalStateException( "Client is not started." ); } + @Override public void start() { if( isRunning ) @@ -180,6 +181,7 @@ public class DefaultClient implements Client } } + @Override public boolean isStarted() { return isRunning; } @@ -196,31 +198,37 @@ public class DefaultClient implements Client } } + @Override public boolean isConnected() { return id != -1 && isRunning; } + @Override public int getId() { return id; } + @Override public String getGameName() { return gameName; } + @Override public int getVersion() { return version; } + @Override public ClientServiceManager getServices() { return services; } + @Override public void send( Message message ) { if( log.isLoggable(Level.FINER) ) { @@ -233,6 +241,7 @@ public class DefaultClient implements Client } } + @Override public void send( int channel, Message message ) { if( log.isLoggable(Level.FINER) ) { @@ -282,6 +291,7 @@ public class DefaultClient implements Client channels.get(channel).write(buffer); } + @Override public void close() { checkRunning(); @@ -322,41 +332,49 @@ public class DefaultClient implements Client services.terminate(); } + @Override public void addClientStateListener( ClientStateListener listener ) { stateListeners.add( listener ); } + @Override public void removeClientStateListener( ClientStateListener listener ) { stateListeners.remove( listener ); } + @Override public void addMessageListener( MessageListener listener ) { messageListeners.addMessageListener( listener ); } + @Override public void addMessageListener( MessageListener listener, Class... classes ) { messageListeners.addMessageListener( listener, classes ); } + @Override public void removeMessageListener( MessageListener listener ) { messageListeners.removeMessageListener( listener ); } + @Override public void removeMessageListener( MessageListener listener, Class... classes ) { messageListeners.removeMessageListener( listener, classes ); } + @Override public void addErrorListener( ErrorListener listener ) { errorListeners.add( listener ); } + @Override public void removeErrorListener( ErrorListener listener ) { errorListeners.remove( listener ); @@ -470,11 +488,13 @@ public class DefaultClient implements Client protected class Redispatch implements MessageListener, ErrorListener { + @Override public void messageReceived( Object source, Message m ) { dispatch( m ); } + @Override public void handleError( Object source, Throwable t ) { // Only doing the DefaultClient.this to make the code 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 d7ee17033..5c62733e8 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 @@ -66,26 +66,26 @@ public class DefaultServer implements Server private static final int CH_FIRST = 2; private boolean isRunning = false; - private AtomicInteger nextId = new AtomicInteger(0); + private final AtomicInteger nextId = new AtomicInteger(0); private String gameName; private int version; - private KernelFactory kernelFactory = KernelFactory.DEFAULT; + private final KernelFactory kernelFactory = KernelFactory.DEFAULT; private KernelAdapter reliableAdapter; private KernelAdapter fastAdapter; - private List channels = new ArrayList(); - private List alternatePorts = new ArrayList(); - private Redispatch dispatcher = new Redispatch(); - private Map connections = new ConcurrentHashMap(); - private Map endpointConnections + private final List channels = new ArrayList(); + private final List alternatePorts = new ArrayList(); + private final Redispatch dispatcher = new Redispatch(); + private final Map connections = new ConcurrentHashMap(); + private final Map endpointConnections = new ConcurrentHashMap(); // Keeps track of clients for whom we've only received the UDP // registration message - private Map connecting = new ConcurrentHashMap(); + private final Map connecting = new ConcurrentHashMap(); - private MessageListenerRegistry messageListeners + private final MessageListenerRegistry messageListeners = new MessageListenerRegistry(); - private List connectionListeners = new CopyOnWriteArrayList(); + private final List connectionListeners = new CopyOnWriteArrayList(); private HostedServiceManager services; @@ -112,21 +112,25 @@ public class DefaultServer implements Server services.addService(new ServerSerializerRegistrationsService()); } + @Override public String getGameName() { return gameName; } + @Override public int getVersion() { return version; } + @Override public HostedServiceManager getServices() { return services; } + @Override public int addChannel( int port ) { if( isRunning ) @@ -165,6 +169,7 @@ public class DefaultServer implements Server } } + @Override public void start() { if( isRunning ) @@ -186,11 +191,13 @@ public class DefaultServer implements Server services.start(); } + @Override public boolean isRunning() { return isRunning; } + @Override public void close() { if( !isRunning ) @@ -215,11 +222,13 @@ public class DefaultServer implements Server } } + @Override public void broadcast( Message message ) { broadcast( null, message ); } + @Override public void broadcast( Filter filter, Message message ) { if( log.isLoggable(Level.FINER) ) { @@ -242,6 +251,7 @@ public class DefaultServer implements Server } } + @Override public void broadcast( int channel, Filter filter, Message message ) { if( log.isLoggable(Level.FINER) ) { @@ -260,46 +270,55 @@ public class DefaultServer implements Server channels.get(channel+CH_FIRST).broadcast( adapter, buffer, true, false ); } + @Override public HostedConnection getConnection( int id ) { return connections.get(id); } + @Override public boolean hasConnections() { return !connections.isEmpty(); } + @Override public Collection getConnections() { return Collections.unmodifiableCollection((Collection)connections.values()); } + @Override public void addConnectionListener( ConnectionListener listener ) { connectionListeners.add(listener); } + @Override public void removeConnectionListener( ConnectionListener listener ) { connectionListeners.remove(listener); } + @Override public void addMessageListener( MessageListener listener ) { messageListeners.addMessageListener( listener ); } + @Override public void addMessageListener( MessageListener listener, Class... classes ) { messageListeners.addMessageListener( listener, classes ); } + @Override public void removeMessageListener( MessageListener listener ) { messageListeners.removeMessageListener( listener ); } + @Override public void removeMessageListener( MessageListener listener, Class... classes ) { messageListeners.removeMessageListener( listener, classes ); @@ -493,12 +512,12 @@ public class DefaultServer implements Server protected class Connection implements HostedConnection { - private int id; + private final int id; private boolean closed; private Endpoint[] channels; private int setChannelCount = 0; - private Map sessionData = new ConcurrentHashMap(); + private final Map sessionData = new ConcurrentHashMap(); public Connection( int channelCount ) { @@ -532,21 +551,25 @@ public class DefaultServer implements Server return setChannelCount == channels.length; } + @Override public Server getServer() { return DefaultServer.this; } + @Override public int getId() { return id; } + @Override public String getAddress() { return channels[CH_RELIABLE] == null ? null : channels[CH_RELIABLE].getAddress(); } + @Override public void send( Message message ) { if( log.isLoggable(Level.FINER) ) { @@ -560,6 +583,7 @@ public class DefaultServer implements Server } } + @Override public void send( int channel, Message message ) { if( log.isLoggable(Level.FINER) ) { @@ -588,6 +612,7 @@ public class DefaultServer implements Server fireConnectionRemoved( this ); } + @Override public void close( String reason ) { // Send a reason @@ -608,6 +633,7 @@ public class DefaultServer implements Server } } + @Override public Object setAttribute( String name, Object value ) { if( value == null ) @@ -616,11 +642,13 @@ public class DefaultServer implements Server } @SuppressWarnings("unchecked") + @Override public T getAttribute( String name ) { return (T)sessionData.get(name); } + @Override public Set attributeNames() { return Collections.unmodifiableSet(sessionData.keySet()); @@ -636,6 +664,7 @@ public class DefaultServer implements Server protected class Redispatch implements MessageListener { + @Override public void messageReceived( HostedConnection source, Message m ) { dispatch( source, m ); @@ -644,13 +673,14 @@ public class DefaultServer implements Server protected class FilterAdapter implements Filter { - private Filter delegate; + private final Filter delegate; public FilterAdapter( Filter delegate ) { this.delegate = delegate; } + @Override public boolean apply( Endpoint input ) { HostedConnection conn = getConnection( input ); diff --git a/jme3-networking/src/main/java/com/jme3/network/base/MessageProtocol.java b/jme3-networking/src/main/java/com/jme3/network/base/MessageProtocol.java index 6751ecc3f..bd85ececc 100644 --- a/jme3-networking/src/main/java/com/jme3/network/base/MessageProtocol.java +++ b/jme3-networking/src/main/java/com/jme3/network/base/MessageProtocol.java @@ -53,7 +53,7 @@ import java.util.LinkedList; */ public class MessageProtocol { - private LinkedList messages = new LinkedList(); + private final LinkedList messages = new LinkedList(); private ByteBuffer current; private int size; private Byte carry; 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 605c7e642..afcfd73c2 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 @@ -48,7 +48,7 @@ public abstract class ServiceManager { static final Logger log = Logger.getLogger(ServiceManager.class.getName()); - private List> services = new CopyOnWriteArrayList>(); + private final List> services = new CopyOnWriteArrayList>(); private volatile boolean started = false; protected ServiceManager() {