games.strategy.net
Class ClientMessenger

java.lang.Object
  extended by games.strategy.net.ClientMessenger
All Implemented Interfaces:
IMessenger, NIOSocketListener

public class ClientMessenger
extends java.lang.Object
implements IMessenger, NIOSocketListener


Constructor Summary
ClientMessenger(java.lang.String host, int port, java.lang.String name)
          Note, the name paramater passed in here may not match the name of the ClientMessenger after it has been constructed.
ClientMessenger(java.lang.String host, int port, java.lang.String name, IConnectionLogin login)
          Note, the name paramater passed in here may not match the name of the ClientMessenger after it has been constructed.
ClientMessenger(java.lang.String host, int port, java.lang.String name, IObjectStreamFactory streamFact)
          Note, the name paramater passed in here may not match the name of the ClientMessenger after it has been constructed.
ClientMessenger(java.lang.String host, int port, java.lang.String name, IObjectStreamFactory streamFact, IConnectionLogin login)
          Note, the name paramater passed in here may not match the name of the ClientMessenger after it has been constructed.
 
Method Summary
 void addErrorListener(IMessengerErrorListener listener)
          Listen for errors
 void addMessageListener(IMessageListener listener)
          Listen for messages.
 void broadcast(java.io.Serializable msg)
          Send a message to all nodes.
 INode getLocalNode()
          Get the local node
 INode getRemoteNode(java.nio.channels.SocketChannel channel)
          Get the remote node id for this channel, or null if the remote node id is not yet known.
 java.net.InetSocketAddress getRemoteServerSocketAddress()
          Get the socket address to which we talk to the server.
 INode getServerNode()
           
 boolean isConnected()
          test the connection.
 boolean isServer()
          Am I the server node?
 void messageReceived(MessageHeader msg, java.nio.channels.SocketChannel channel)
           
 void removeErrorListener(IMessengerErrorListener listener)
          Stop listening for errors.
 void removeMessageListener(IMessageListener listener)
          Stop listening to messages.
 void send(java.io.Serializable msg, INode to)
          Send a message to the given node.
 void shutDown()
          Shut the connection down.
 void socketError(java.nio.channels.SocketChannel channel, java.lang.Exception error)
          An error occured on the channel and it was shut down.
 void socketUnqaurantined(java.nio.channels.SocketChannel channel, QuarantineConversation converstaion2)
          This connection will leave quarantine.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClientMessenger

public ClientMessenger(java.lang.String host,
                       int port,
                       java.lang.String name,
                       IConnectionLogin login)
                throws java.io.IOException,
                       java.net.UnknownHostException,
                       CouldNotLogInException
Note, the name paramater passed in here may not match the name of the ClientMessenger after it has been constructed.

Throws:
java.io.IOException
java.net.UnknownHostException
CouldNotLogInException

ClientMessenger

public ClientMessenger(java.lang.String host,
                       int port,
                       java.lang.String name)
                throws java.io.IOException,
                       java.net.UnknownHostException,
                       CouldNotLogInException
Note, the name paramater passed in here may not match the name of the ClientMessenger after it has been constructed.

Throws:
java.io.IOException
java.net.UnknownHostException
CouldNotLogInException

ClientMessenger

public ClientMessenger(java.lang.String host,
                       int port,
                       java.lang.String name,
                       IObjectStreamFactory streamFact)
                throws java.io.IOException,
                       java.net.UnknownHostException,
                       CouldNotLogInException
Note, the name paramater passed in here may not match the name of the ClientMessenger after it has been constructed.

Throws:
java.io.IOException
java.net.UnknownHostException
CouldNotLogInException

ClientMessenger

public ClientMessenger(java.lang.String host,
                       int port,
                       java.lang.String name,
                       IObjectStreamFactory streamFact,
                       IConnectionLogin login)
                throws java.io.IOException,
                       java.net.UnknownHostException,
                       CouldNotLogInException
Note, the name paramater passed in here may not match the name of the ClientMessenger after it has been constructed.

Throws:
java.io.IOException
java.net.UnknownHostException
CouldNotLogInException
Method Detail

send

public void send(java.io.Serializable msg,
                 INode to)
Description copied from interface: IMessenger
Send a message to the given node. Returns immediately. If the message cannot be delivered, this method will not throw an exception, but will fail silently.

Specified by:
send in interface IMessenger

broadcast

public void broadcast(java.io.Serializable msg)
Description copied from interface: IMessenger
Send a message to all nodes.

Specified by:
broadcast in interface IMessenger

addMessageListener

public void addMessageListener(IMessageListener listener)
Description copied from interface: IMessenger
Listen for messages.

Specified by:
addMessageListener in interface IMessenger

removeMessageListener

public void removeMessageListener(IMessageListener listener)
Description copied from interface: IMessenger
Stop listening to messages.

Specified by:
removeMessageListener in interface IMessenger

addErrorListener

public void addErrorListener(IMessengerErrorListener listener)
Description copied from interface: IMessenger
Listen for errors

Specified by:
addErrorListener in interface IMessenger

removeErrorListener

public void removeErrorListener(IMessengerErrorListener listener)
Description copied from interface: IMessenger
Stop listening for errors.

Specified by:
removeErrorListener in interface IMessenger

isConnected

public boolean isConnected()
Description copied from interface: IMessenger
test the connection.

Specified by:
isConnected in interface IMessenger

shutDown

public void shutDown()
Description copied from interface: IMessenger
Shut the connection down.

Specified by:
shutDown in interface IMessenger

messageReceived

public void messageReceived(MessageHeader msg,
                            java.nio.channels.SocketChannel channel)
Specified by:
messageReceived in interface NIOSocketListener

getLocalNode

public INode getLocalNode()
Get the local node

Specified by:
getLocalNode in interface IMessenger
Specified by:
getLocalNode in interface NIOSocketListener

getServerNode

public INode getServerNode()
Specified by:
getServerNode in interface IMessenger
Returns:
local node if we are a server node.

isServer

public boolean isServer()
Description copied from interface: IMessenger
Am I the server node? There should only be one server node, and it should exist before other nodes.

Specified by:
isServer in interface IMessenger

socketUnqaurantined

public void socketUnqaurantined(java.nio.channels.SocketChannel channel,
                                QuarantineConversation converstaion2)
Description copied from interface: NIOSocketListener
This connection will leave quarantine. Messages on this channel will not be read until after this method returns, allowing for setup of the channel.

Specified by:
socketUnqaurantined in interface NIOSocketListener

socketError

public void socketError(java.nio.channels.SocketChannel channel,
                        java.lang.Exception error)
Description copied from interface: NIOSocketListener
An error occured on the channel and it was shut down.

Specified by:
socketError in interface NIOSocketListener

getRemoteNode

public INode getRemoteNode(java.nio.channels.SocketChannel channel)
Description copied from interface: NIOSocketListener
Get the remote node id for this channel, or null if the remote node id is not yet known. The node may be unknown if the channel is still quarantined

Specified by:
getRemoteNode in interface NIOSocketListener

getRemoteServerSocketAddress

public java.net.InetSocketAddress getRemoteServerSocketAddress()
Description copied from interface: IMessenger
Get the socket address to which we talk to the server. This may be different than getServerNode().getSocketAddress() since the server will report the socket that he thinks the server is running on, if the server is behind a firewall, or a NAT, then this socket will be different than the actual port we use.

Specified by:
getRemoteServerSocketAddress in interface IMessenger