Added a method for easily determining if there are active
connections. Early-return in the broadcast method if there are no connections. This prevents allocation of a message if it's just going to get dropped on the floor anyway. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8932 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
11e23de0ec
commit
48db901b5b
engine/src/networking/com/jme3/network
@ -103,6 +103,12 @@ public interface Server
|
||||
*/
|
||||
public Collection<HostedConnection> getConnections();
|
||||
|
||||
/**
|
||||
* Returns true if the server has active connections at the time of this
|
||||
* call.
|
||||
*/
|
||||
public boolean hasConnections();
|
||||
|
||||
/**
|
||||
* Adds a listener that will be notified when new hosted connections
|
||||
* arrive.
|
||||
|
@ -153,6 +153,9 @@ public class DefaultServer implements Server
|
||||
|
||||
public void broadcast( Filter<? super HostedConnection> filter, Message message )
|
||||
{
|
||||
if( connections.isEmpty() )
|
||||
return;
|
||||
|
||||
ByteBuffer buffer = MessageProtocol.messageToBuffer(message, null);
|
||||
|
||||
FilterAdapter adapter = filter == null ? null : new FilterAdapter(filter);
|
||||
@ -172,6 +175,11 @@ public class DefaultServer implements Server
|
||||
return connections.get(id);
|
||||
}
|
||||
|
||||
public boolean hasConnections()
|
||||
{
|
||||
return !connections.isEmpty();
|
||||
}
|
||||
|
||||
public Collection<HostedConnection> getConnections()
|
||||
{
|
||||
return Collections.unmodifiableCollection((Collection<HostedConnection>)connections.values());
|
||||
|
Loading…
x
Reference in New Issue
Block a user