java.lang.Object
org.zazof.jteg.MessageManager
- All Implemented Interfaces:
- java.lang.Runnable
- public class MessageManager
- extends java.lang.Object
- implements java.lang.Runnable
This class is responsible for:
- Processing incoming messages from the server in a protocolindependent way
- Converting information from this application to the string that is accurate for the active protocol
- Managing the listeners that are interested in one or more messages coming from the server
Ideally, only this class should have contact with the TEGServer
Implements the Singleton pattern.
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
listeners
private java.util.Vector listeners
instance
private static MessageManager instance
$currentThread
private java.lang.Thread $currentThread
$isRunning
private boolean $isRunning
$connected
private boolean $connected
$entryPoint
private Message $entryPoint
$builder
private MessageChainBuilder $builder
DEBUG
private static boolean DEBUG
$server
private TEGServer $server
MessageManager
private MessageManager()
getInstance
public static MessageManager getInstance()
startThread
public void startThread()
run
public void run()
- Description copied from interface:
java.lang.Runnable
- This method will be called by whoever wishes to run your class
implementing Runnable. Note that there are no restrictions on what
you are allowed to do in the run method, except that you cannot
throw a checked exception.
- Specified by:
run in interface java.lang.Runnable
addMessageListener
public void addMessageListener(MessageListener ml)
removeMessageListener
public void removeMessageListener(MessageListener ml)
notifyAllListeners
public void notifyAllListeners(Message m)
makeConnectionWithServer
public void makeConnectionWithServer(java.lang.String server,
int port)
throws java.io.IOException,
ServerException
- Makes the actual connection with server on the specified port. Before sending any message
to the TEG server, this method should be called.
disconnect
public void disconnect()
- Disconnect from the server, if we are connected. Otherwise, nothing happens.
sendToServer
public void sendToServer(java.lang.String[] messageParts)
throws UnknownMessageException,
ServerException
- This method will build the correct messagestring to the server based on the 'parts'
that are supplied as a parameter in a StringArray. It will then send this message
to the server.
broadCastInternalMessage
public void broadCastInternalMessage(java.lang.String[] messageParts)
throws UnknownMessageException
- This method will broadcast a specific message to all those interested in an InformationMessage
This method may be used for reducing coupling between domain & GUI layer.
askPlayerStatus
public void askPlayerStatus()
throws ServerException
- This method will ask the playerstatus to the server.
decodeMessage
private Message decodeMessage(java.lang.String message)
throws UnknownMessageException
init
private void init()