| Modifier and Type | Class and Description |
|---|---|
protected class |
DefaultServer.Connection |
protected class |
DefaultServer.FilterAdapter |
protected class |
DefaultServer.Redispatch |
| Constructor and Description |
|---|
DefaultServer(java.lang.String gameName,
int version,
Kernel reliable,
Kernel fast) |
| Modifier and Type | Method and Description |
|---|---|
int |
addChannel(int port)
Adds an alternate channel to the server, using the specified port.
|
void |
addConnectionListener(ConnectionListener listener)
Adds a listener that will be notified when new hosted connections
arrive.
|
void |
addMessageListener(MessageListener<? super HostedConnection> listener)
Adds a listener that will be notified when any message or object
is received from one of the clients.
|
void |
addMessageListener(MessageListener<? super HostedConnection> listener,
java.lang.Class... classes)
Adds a listener that will be notified when messages of the specified
types are received from one of the clients.
|
protected void |
addStandardServices() |
void |
broadcast(Filter<? super HostedConnection> filter,
Message message)
Sends the specified message to all connected clients that match
the filter.
|
void |
broadcast(int channel,
Filter<? super HostedConnection> filter,
Message message)
Sends the specified message over the specified alternate channel to all connected
clients that match the filter.
|
void |
broadcast(Message message)
Sends the specified message to all connected clients.
|
protected void |
checkChannel(int channel) |
void |
close()
Closes all client connections, stops and running processing threads, and
closes the host connection.
|
protected void |
connectionClosed(Endpoint p) |
protected void |
dispatch(HostedConnection source,
Message m) |
protected void |
fireConnectionAdded(HostedConnection conn) |
protected void |
fireConnectionRemoved(HostedConnection conn) |
protected int |
getChannel(KernelAdapter ka) |
protected HostedConnection |
getConnection(Endpoint endpoint) |
HostedConnection |
getConnection(int id)
Retrieves a hosted connection by ID.
|
java.util.Collection<HostedConnection> |
getConnections()
Retrieves a read-only collection of all currently connected connections.
|
java.lang.String |
getGameName()
Returns the 'game name' for this server.
|
HostedServiceManager |
getServices()
Returns the manager for hosted services.
|
int |
getVersion()
Returns the game-specific version of this server used for detecting
mismatched clients.
|
boolean |
hasConnections()
Returns true if the server has active connections at the time of this
call.
|
boolean |
isRunning()
Returns true if the server has been started.
|
protected void |
registerClient(KernelAdapter ka,
Endpoint p,
ClientRegistrationMessage m) |
protected void |
removeConnecting(Endpoint p) |
void |
removeConnectionListener(ConnectionListener listener)
Removes a previously registered connection listener.
|
void |
removeMessageListener(MessageListener<? super HostedConnection> listener)
Removes a previously registered wildcard listener.
|
void |
removeMessageListener(MessageListener<? super HostedConnection> listener,
java.lang.Class... classes)
Removes a previously registered type-specific listener from
the specified types.
|
void |
start()
Start the server so that it will began accepting new connections
and processing messages.
|
protected void addStandardServices()
public java.lang.String getGameName()
ServergetGameName in interface Serverpublic int getVersion()
ServergetVersion in interface Serverpublic HostedServiceManager getServices()
ServergetServices in interface Serverpublic int addChannel(int port)
ServeraddChannel in interface Serverprotected void checkChannel(int channel)
public void start()
Serverpublic boolean isRunning()
Serverpublic void close()
Serverpublic void broadcast(Message message)
Serverpublic void broadcast(Filter<? super HostedConnection> filter, Message message)
ServerExamples:
// Broadcast to connections: conn1, conn2, and conn3
server.broadcast( Filters.in( conn1, conn2, conn3 ), message );
// Broadcast to all connections exception source
server.broadcast( Filters.notEqualTo( source ), message );
public void broadcast(int channel,
Filter<? super HostedConnection> filter,
Message message)
ServerExamples:
// Broadcast to connections: conn1, conn2, and conn3
server.broadcast( Filters.in( conn1, conn2, conn3 ), message );
// Broadcast to all connections exception source
server.broadcast( Filters.notEqualTo( source ), message );
public HostedConnection getConnection(int id)
ServergetConnection in interface Serverpublic boolean hasConnections()
ServerhasConnections in interface Serverpublic java.util.Collection<HostedConnection> getConnections()
ServergetConnections in interface Serverpublic void addConnectionListener(ConnectionListener listener)
ServeraddConnectionListener in interface Serverpublic void removeConnectionListener(ConnectionListener listener)
ServerremoveConnectionListener in interface Serverpublic void addMessageListener(MessageListener<? super HostedConnection> listener)
ServerNote about MessageListener multithreading: on the server, message events may be delivered by more than one thread depending on the server implementation used. Listener implementations should treat their shared data structures accordingly and set them up for multithreaded access. The only threading guarantee is that for a single HostedConnection, there will only ever be one thread at a time and the messages will always be delivered to that connection in the order that they were delivered. This is the only restriction placed upon server message dispatch pool implementations.
addMessageListener in interface Serverpublic void addMessageListener(MessageListener<? super HostedConnection> listener, java.lang.Class... classes)
ServeraddMessageListener in interface Serverpublic void removeMessageListener(MessageListener<? super HostedConnection> listener)
ServerremoveMessageListener in interface Serverpublic void removeMessageListener(MessageListener<? super HostedConnection> listener, java.lang.Class... classes)
ServerremoveMessageListener in interface Serverprotected void dispatch(HostedConnection source, Message m)
protected void fireConnectionAdded(HostedConnection conn)
protected void fireConnectionRemoved(HostedConnection conn)
protected int getChannel(KernelAdapter ka)
protected void registerClient(KernelAdapter ka, Endpoint p, ClientRegistrationMessage m)
protected HostedConnection getConnection(Endpoint endpoint)
protected void removeConnecting(Endpoint p)
protected void connectionClosed(Endpoint p)