com.mooapi.server
Class MooConnection

java.lang.Object
  extended by com.mooapi.server.MooConnection

public final class MooConnection
extends java.lang.Object

This class implements MooAPI connections.

Author:
Steve Taylor

Constructor Summary
MooConnection(int id, java.lang.String ipAddress, org.apache.mina.common.IoSession ioSession, MooServer server)
          Create a MooAPI connection.
 
Method Summary
 void disconnect()
          Disconnect cleanly from all channels
 java.lang.Object getAttachment()
          Get this connection's attachment.
 int getId()
          Get this connection's ID.
 java.lang.String getIpAddress()
          Get this connection's IP address.
 java.lang.String getName()
          Get this connection's name.
 org.apache.mina.common.IoSession getPeer()
          Get this connection's peer, which is a MINA connection.
 void join(MooChannel channel)
          Add a channel to this connection's channel list
 void leave(MooChannel channel)
          Remove a channel from this connection's channel list
 void leaveAll()
          Leave all channels.
 void processCommand(AbstractClientCommand inputCommand)
          Process a command from this connection.
 void sendChannelJoinDetails(MooChannel channel)
          Notify this connection that it has joined a channel.
 void sendConnectionInfo(MooConnection connection, MooChannel channel)
          Notify this connection of an existing connection in the specified channel.
 void sendConnectionJoin(MooConnection connection, MooChannel channel)
          Notify this connection of a new connection in the specified channel.
 void sendConnectionLeft(MooConnection connection, MooChannel channel)
          Notify this MooConnection that another MooConnection has left a MooChannel to which they are both subscribed.
<T extends AbstractMessage>
void
sendMessage(MooConnection source, MooChannel channel, short subchannel, T message)
          Send a message from a MooAPI connection.
<T extends AbstractMessage>
void
sendMessageFromServer(T message, short subchannel)
          Send message from the server (i.e.
 void sendMotd(java.lang.String motd)
          Send the message of the day.
 void sendNameChange(MooConnection connection)
          Notify this MooConnection that another MooConnection changed its name.
 void sendUserId()
          Send the ID of this connection.
 void setAttachment(java.lang.Object attachment)
          Set this connection's attachment.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MooConnection

public MooConnection(int id,
                     java.lang.String ipAddress,
                     org.apache.mina.common.IoSession ioSession,
                     MooServer server)
Create a MooAPI connection.

Parameters:
id - The connection ID.
ipAddress - The connection's IP address.
ioSession - The connection's MINA connection.
server - The MooAPI server.
Method Detail

getId

public int getId()
Get this connection's ID.

Returns:
This connection's ID.

getName

public java.lang.String getName()
Get this connection's name.

Returns:
This connection's name.

getIpAddress

public java.lang.String getIpAddress()
Get this connection's IP address.

Returns:
This connection's IP address.

getPeer

public org.apache.mina.common.IoSession getPeer()
Get this connection's peer, which is a MINA connection.

Returns:
This connection's peer.

getAttachment

public java.lang.Object getAttachment()
Get this connection's attachment.

Returns:
This connection's attachment.

setAttachment

public void setAttachment(java.lang.Object attachment)
Set this connection's attachment.

Parameters:
attachment - An object.

sendMessage

public <T extends AbstractMessage> void sendMessage(MooConnection source,
                                                    MooChannel channel,
                                                    short subchannel,
                                                    T message)
Send a message from a MooAPI connection.

Parameters:
source - The sender of the message.
channel - The MooChannel that carries the message.
subchannel - The subchannel that carries the message.
text - The message text.

sendMotd

public void sendMotd(java.lang.String motd)
Send the message of the day.

Parameters:
motd - The message of the day

sendUserId

public void sendUserId()
Send the ID of this connection.


sendConnectionInfo

public void sendConnectionInfo(MooConnection connection,
                               MooChannel channel)
Notify this connection of an existing connection in the specified channel.

Parameters:
connection - A MooAPI connection.
channel - A channel to which this and the specified connections are both subscribed.

sendConnectionJoin

public void sendConnectionJoin(MooConnection connection,
                               MooChannel channel)
Notify this connection of a new connection in the specified channel.

Parameters:
connection - A new connection in the specified channel.
channel - A channel to which this and the specified connections are both subscribed.

sendChannelJoinDetails

public void sendChannelJoinDetails(MooChannel channel)
Notify this connection that it has joined a channel.

Parameters:
channel - The channel this connection has joined.

sendConnectionLeft

public void sendConnectionLeft(MooConnection connection,
                               MooChannel channel)
Notify this MooConnection that another MooConnection has left a MooChannel to which they are both subscribed.

Parameters:
connection - The MooConnection that unsubscribed.
channel - The MooChannel from which the {@code MooConnection} unsubscribed.

sendNameChange

public void sendNameChange(MooConnection connection)
Notify this MooConnection that another MooConnection changed its name.

Parameters:
connection - The MooConnection that changed its name.

sendMessageFromServer

public <T extends AbstractMessage> void sendMessageFromServer(T message,
                                                              short subchannel)
Send message from the server (i.e. send message from user 0 on channel 0)

Parameters:
text - The message from the server.
subchannel - The subchannel of the message.

join

public void join(MooChannel channel)
Add a channel to this connection's channel list

Parameters:
channel - The channel to join

leave

public void leave(MooChannel channel)
Remove a channel from this connection's channel list

Parameters:
channel - The channel to leave

leaveAll

public void leaveAll()
Leave all channels.


disconnect

public void disconnect()
Disconnect cleanly from all channels


processCommand

public void processCommand(AbstractClientCommand inputCommand)
Process a command from this connection. This method determines the command type then dispatches it to the appropriate processor.

Parameters:
inputCommand - The command from this connection.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2009. All Rights Reserved.