gecco.communication.client
Class DataOutputExchangeHandler

java.lang.Object
  |
  +--gecco.communication.client.DataOutputExchangeHandler
All Implemented Interfaces:
Runnable

public class DataOutputExchangeHandler
extends Object
implements Runnable

A class that sends messages to the server

Author:
Niklas Hallenfur, Henrik Hägerström, Jon Åslund

Field Summary
private  ServerConnection connection
          Description of the Field
private  boolean die
          Description of the Field
private  ServerAmbassador i_am_working_for
          Description of the Field
private  MessageQueue messages_to_send
          Description of the Field
 
Constructor Summary
DataOutputExchangeHandler(MessageQueue q, ServerConnection sc, ServerAmbassador sa)
           
 
Method Summary
 void addMessageToQueue(Object message)
          Used by the ServerAmbassador to add messages to send
 void kill()
          called whenever someone wants this thread to die
 void run()
          Main processing method for the DataOutputExchangeHandler object
private  void sendAbortActionMessage(AbortActionMessage m)
          Sends a message that tells the server that a unit wants to abort an action
private  void sendAbortGameMessage()
          Sends a message that tells the server that this client wants to abort the game (disconnect)
private  void sendActionOnPositionMessage(ActionOnPositionMessage m)
          Sends a message that tells the server that a unit wants to perform an action with a position as target
private  void sendActionOnUnitMessage(ActionOnUnitMessage m)
          Sends a message that tells the server that a unit wants to perform an action with a unit as target
private  void sendActionOnVoidMessage(ActionMessage m)
          Sends a message that tells the server that a unit wants to perform an action with no target
private  void sendMessage(Object o)
          Called when there are messages to send in the queue.
private  void sendPingReplyMessage(PingReplyMessage m)
          Sends a reply to a received ping message from the server
private  void sendStartGameMessage()
          Sends a message that tells the server that this client (role) is ready to receive messages, and wants all its visible information
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

messages_to_send

private MessageQueue messages_to_send
Description of the Field

connection

private ServerConnection connection
Description of the Field

i_am_working_for

private ServerAmbassador i_am_working_for
Description of the Field

die

private boolean die
Description of the Field
Constructor Detail

DataOutputExchangeHandler

public DataOutputExchangeHandler(MessageQueue q,
                                 ServerConnection sc,
                                 ServerAmbassador sa)
Parameters:
q - the queue that will contain the messages to send
sc - the connection to send messages to
sa - the serverambassador who created this object
Method Detail

addMessageToQueue

public void addMessageToQueue(Object message)
Used by the ServerAmbassador to add messages to send
Parameters:
message - The feature to be added to the MessageToQueue attribute

run

public void run()
Main processing method for the DataOutputExchangeHandler object
Specified by:
run in interface Runnable

kill

public void kill()
called whenever someone wants this thread to die

sendMessage

private void sendMessage(Object o)
                  throws Exception
Called when there are messages to send in the queue. Checks the class of the message to send, and calls the appropriate method that sends that kind of message
Parameters:
o - Description of Parameter
Throws:
Exception - Description of Exception

sendPingReplyMessage

private void sendPingReplyMessage(PingReplyMessage m)
Sends a reply to a received ping message from the server
Parameters:
m - Description of Parameter

sendActionOnVoidMessage

private void sendActionOnVoidMessage(ActionMessage m)
Sends a message that tells the server that a unit wants to perform an action with no target
Parameters:
m - Description of Parameter

sendActionOnUnitMessage

private void sendActionOnUnitMessage(ActionOnUnitMessage m)
Sends a message that tells the server that a unit wants to perform an action with a unit as target
Parameters:
m - Description of Parameter

sendActionOnPositionMessage

private void sendActionOnPositionMessage(ActionOnPositionMessage m)
Sends a message that tells the server that a unit wants to perform an action with a position as target
Parameters:
m - Description of Parameter

sendAbortActionMessage

private void sendAbortActionMessage(AbortActionMessage m)
Sends a message that tells the server that a unit wants to abort an action
Parameters:
m - Description of Parameter

sendAbortGameMessage

private void sendAbortGameMessage()
                           throws Exception
Sends a message that tells the server that this client wants to abort the game (disconnect)
Throws:
Exception - Description of Exception

sendStartGameMessage

private void sendStartGameMessage()
                           throws Exception
Sends a message that tells the server that this client (role) is ready to receive messages, and wants all its visible information
Throws:
Exception - Description of Exception