com.mooapi.server
Class MooServer

java.lang.Object
  extended by com.mooapi.server.MooServer
All Implemented Interfaces:
CommandProcessor<AbstractClientCommand>

public class MooServer
extends java.lang.Object
implements CommandProcessor<AbstractClientCommand>


Constructor Summary
MooServer()
          Create a MooServer object, delegating initialization to the relevant property setters.
MooServer(IdProvider<java.lang.Integer> connectionIdProvider, IdProvider<java.lang.Integer> channelIdProvider, MooServerHandler mooServerHandler)
          Initialize this MooAPI server.
 
Method Summary
 void activateConnection(MooConnection connection)
          Activate a MooAPI connection.
 void clientCommandReceived(MooConnection connection, AbstractClientCommand command)
          Process an incoming command.
 MooChannel createChannel(java.lang.String channelName, MooConnection connection)
          Create a MooAPI channel with the specified name.
 void disconnect(MooConnection connection)
          Drop the MooAPI connection.
 MooChannel getChannel(int channelId)
          Get the MooAPI channel designated by the specified channel ID.
 MooChannel getChannel(java.lang.String channelName)
          Get the MooAPI channel designated by the specified channel name.
 IdProvider<java.lang.Integer> getChannelIdProvider()
          Get the channel ID provider.
 java.util.Map<java.lang.Integer,MooChannel> getChannelsById()
          Get the map of channels by ID.
 java.util.Map<java.lang.String,MooChannel> getChannelsByName()
          Get the map of channels by name.
 MooConnection getConnection(int connectionId)
          Get the MooAPI connection associated with the specified connection ID.
 MooConnection getConnection(org.apache.mina.common.IoSession session)
          Get the MooAPI connection associated with the specified Apache MINA session.
 IdProvider<java.lang.Integer> getConnectionIdProvider()
          Get the connection ID provider.
 java.util.Map<java.lang.Integer,MooConnection> getConnectionsById()
          Get the map of connections by ID.
 MooServerHandler getMooServerHandler()
          Get this server's event handler.
 java.lang.String getMotd()
          Get the message of the day.
 void process(MooConnection connection, AbstractClientCommand command)
          Send the specified command to the specified connection.
 boolean removeChannel(int channelId)
          Remove the MooAPI channel associated with the specified ID.
protected  boolean removeChannel(MooChannel channel)
          Remove the specified MooAPI channel.
 boolean removeChannel(java.lang.String channelName)
          Remove the MooAPI channel with the specified name.
 void setChannelIdProvider(IdProvider<java.lang.Integer> channelIdProvider)
          Set the channel ID provider.
 void setChannelsById(java.util.Map<java.lang.Integer,MooChannel> channelsById)
          Set the map of channels by ID.
 void setChannelsByName(java.util.Map<java.lang.String,MooChannel> channelsByName)
          Set the map of channels by name.
 void setConnectionIdProvider(IdProvider<java.lang.Integer> connectionIdProvider)
          Set the connection ID provider.
 void setConnectionsById(java.util.Map<java.lang.Integer,MooConnection> connectionsById)
          Set the map of connections by ID.
 void setMooServerHandler(MooServerHandler mooServerHandler)
          Set this server's event handler.
 void setMotd(java.lang.String motd)
          Set the message of the day.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MooServer

public MooServer(IdProvider<java.lang.Integer> connectionIdProvider,
                 IdProvider<java.lang.Integer> channelIdProvider,
                 MooServerHandler mooServerHandler)
Initialize this MooAPI server.

Parameters:
connectionIdProvider -
channelIdProvider -
mooServerHandler -

MooServer

public MooServer()
Create a MooServer object, delegating initialization to the relevant property setters.

Method Detail

getConnectionsById

public java.util.Map<java.lang.Integer,MooConnection> getConnectionsById()
Get the map of connections by ID.

Returns:
The map of connections by ID.

setConnectionsById

public void setConnectionsById(java.util.Map<java.lang.Integer,MooConnection> connectionsById)
Set the map of connections by ID. This map should be empty if the caller's purpose is initialization.

Parameters:
connectionsById - A map of connections by ID.

getConnectionIdProvider

public IdProvider<java.lang.Integer> getConnectionIdProvider()
Get the connection ID provider.

Returns:
The connection ID provider.

setConnectionIdProvider

public void setConnectionIdProvider(IdProvider<java.lang.Integer> connectionIdProvider)
Set the connection ID provider.

Parameters:
connectionIdProvider -

getChannelsById

public java.util.Map<java.lang.Integer,MooChannel> getChannelsById()
Get the map of channels by ID.

Returns:
The map of channels by ID.

setChannelsById

public void setChannelsById(java.util.Map<java.lang.Integer,MooChannel> channelsById)
Set the map of channels by ID. This map should be empty if the caller's purpose is initialization.

Parameters:
channelsById - A map of channels by ID.

getChannelsByName

public java.util.Map<java.lang.String,MooChannel> getChannelsByName()
Get the map of channels by name.

Returns:
The map of channels by name.

setChannelsByName

public void setChannelsByName(java.util.Map<java.lang.String,MooChannel> channelsByName)
Set the map of channels by name. This map should be empty if the caller's purpose is initialization.

Parameters:
channelsByName - A map of channels by name.

getChannelIdProvider

public IdProvider<java.lang.Integer> getChannelIdProvider()
Get the channel ID provider.

Returns:
The channel ID provider.

setChannelIdProvider

public void setChannelIdProvider(IdProvider<java.lang.Integer> channelIdProvider)
Set the channel ID provider.

Parameters:
channelIdProvider - The channel ID provider.

getMooServerHandler

public MooServerHandler getMooServerHandler()
Get this server's event handler.

Returns:
This server's event handler.

setMooServerHandler

public void setMooServerHandler(MooServerHandler mooServerHandler)
Set this server's event handler.

Parameters:
mooServerHandler - An event handler.

getMotd

public java.lang.String getMotd()
Get the message of the day.

Returns:
The message of the day.

setMotd

public void setMotd(java.lang.String motd)
Set the message of the day.

Parameters:
motd - The message of the day.

getConnection

public MooConnection getConnection(org.apache.mina.common.IoSession session)
Get the MooAPI connection associated with the specified Apache MINA session.

Parameters:
session - An Apache MINA session (ie. connection).
Returns:
The associated MooAPI connection.

disconnect

public void disconnect(MooConnection connection)
Drop the MooAPI connection.

Parameters:
connection - A MooAPI connection.

getChannel

public MooChannel getChannel(int channelId)
Get the MooAPI channel designated by the specified channel ID.

Parameters:
channelId - A channel ID.
Returns:
The associated MooAPI channel.

getChannel

public MooChannel getChannel(java.lang.String channelName)
Get the MooAPI channel designated by the specified channel name.

Parameters:
channelName - A channel name.
Returns:
The associated MooAPI channel.

createChannel

public MooChannel createChannel(java.lang.String channelName,
                                MooConnection connection)

Create a MooAPI channel with the specified name.

If a channel with the specified name already exists, return that channel instead of creating a new one.

Parameters:
channelName - The name of the channel to create.
connection - The connection that initiated channel creation.
Returns:
The created MooAPI channel.

removeChannel

protected boolean removeChannel(MooChannel channel)
Remove the specified MooAPI channel.

Parameters:
channel - The MooAPI channel to remove.
Returns:
channel != null.

removeChannel

public boolean removeChannel(int channelId)
Remove the MooAPI channel associated with the specified ID.

Parameters:
channelId - The ID of the MooAPI channel to remove.
Returns:
true if the channel existed and could therefore be removed, otherwise false.

removeChannel

public boolean removeChannel(java.lang.String channelName)
Remove the MooAPI channel with the specified name.

Parameters:
channelName - The name of the MooAPI channel to remove.
Returns:
true if the channel existed and could therefore be removed, otherwise false.

getConnection

public MooConnection getConnection(int connectionId)
Get the MooAPI connection associated with the specified connection ID.

Parameters:
connectionId - A connection ID.
Returns:
The associated MooAPI connection.

activateConnection

public void activateConnection(MooConnection connection)
Activate a MooAPI connection.

Parameters:
connection - An initialized MooAPI connection.

clientCommandReceived

public void clientCommandReceived(MooConnection connection,
                                  AbstractClientCommand command)
Process an incoming command. This forwards the command to the server handler, which in turn may forward the command to the input processor interface, which in turn will forward the command to the source's connection object.

Parameters:
connection - The connection from which the command is received.
command - The input command.

process

public void process(MooConnection connection,
                    AbstractClientCommand command)
Send the specified command to the specified connection. This method is thread-safe.

Specified by:
process in interface CommandProcessor<AbstractClientCommand>
Parameters:
connection - The connection.
command - The command.


Copyright © 2009. All Rights Reserved.