games.strategy.net
Interface IMessenger

All Known Subinterfaces:
IServerMessenger
All Known Implementing Classes:
ClientMessenger, DummyMessenger, ServerMessenger

public interface IMessenger

A simple way to connect multiple socket end points. An IMessenger listens for incoming messages, and sends them to all registered listeners. Messages are recieved and sent in order. Note that message listeners are multi threaded, in that they process messages from multiple nodes at the same time, but no more than 1 message from any particular node at a time.


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
 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 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.
 

Method Detail

send

void send(java.io.Serializable msg,
          INode to)
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.


broadcast

void broadcast(java.io.Serializable msg)
Send a message to all nodes.


addMessageListener

void addMessageListener(IMessageListener listener)
Listen for messages.


removeMessageListener

void removeMessageListener(IMessageListener listener)
Stop listening to messages.


addErrorListener

void addErrorListener(IMessengerErrorListener listener)
Listen for errors


removeErrorListener

void removeErrorListener(IMessengerErrorListener listener)
Stop listening for errors.


getLocalNode

INode getLocalNode()
Get the local node


isConnected

boolean isConnected()
test the connection.


shutDown

void shutDown()
Shut the connection down.


isServer

boolean isServer()
Am I the server node? There should only be one server node, and it should exist before other nodes.


getServerNode

INode getServerNode()
Returns:
local node if we are a server node.

getRemoteServerSocketAddress

java.net.InetSocketAddress getRemoteServerSocketAddress()
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.