gecco.communication.client
Class DataInputExchangeHandler

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

public class DataInputExchangeHandler
extends Object
implements Runnable

A class that listens for incoming messages from the server, and tells the client about them.

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

Field Summary
private  Client client
          Description of the Field
private  ServerConnection connection
          Description of the Field
private  DataOutputExchangeHandler DEHOutput
          Description of the Field
private  boolean die
          Description of the Field
private  ServerAmbassador i_am_working_for
          Description of the Field
 
Constructor Summary
DataInputExchangeHandler(ServerConnection sc, Client cl, ServerAmbassador sa, DataOutputExchangeHandler DEHOutput)
           
 
Method Summary
private  void getActionBlocked()
          an action is no longer valid for a certain unit, get which action and which unit
private  void getActionCompleted()
          Gets the handle of an action that has been completed
private  void getActionFailed()
          Gets the handle and an error message for an action that failed
private  int getInt(byte[] byteArray, int index)
          A helper function that makes unsigned casting from byte to int
private  void getMapPointInvisible()
          get which map point is no longer visible.
private  void getMapPointsInvisible()
          gets an array of Points that are no longer visible
private  void getMapUpdate()
          get an update of a map point.
private  void getMapUpdates()
          Gets an array of positions and new colors for mappoints.
private  void getUnitDeleted()
          gets which unit has been deleted (not necessarily destroyed)
private  void getUnitDestroyed()
          a unit has been destroyed, get which one
private  void getUnitMessage()
          gets a message about a certain unit
private  void getUnitPositionUpdate()
          Get a message from the server that updates the position of a unit
private  void getUnitPropertyUpdate()
          Get a message from the server that updates the properties of a unit
private  void getUnitVisible()
          Get a message that a new unit is visible to the client, gets the unit's properties and action, type, etc.
 void kill()
          called whenever someone wants this thread to die
private  void receiveMessage(int leadingInteger)
          Called when there are messages to receive from the server.
 void run()
          Main processing method for the DataInputExchangeHandler object
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

connection

private ServerConnection connection
Description of the Field

client

private Client client
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

DEHOutput

private DataOutputExchangeHandler DEHOutput
Description of the Field
Constructor Detail

DataInputExchangeHandler

public DataInputExchangeHandler(ServerConnection sc,
                                Client cl,
                                ServerAmbassador sa,
                                DataOutputExchangeHandler DEHOutput)
Parameters:
sc - connection to server containing the stream to write to
cl - the Client to send incoming messages to
sa - the ServerAmbassador this thread is working for DEHOutput the object to send PingReplyMessage:s to
DEHOutput - Description of Parameter
Method Detail

run

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

kill

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

getUnitPositionUpdate

private void getUnitPositionUpdate()
                            throws Exception
Get a message from the server that updates the position of a unit
Throws:
Exception - Description of Exception

getUnitPropertyUpdate

private void getUnitPropertyUpdate()
                            throws Exception
Get a message from the server that updates the properties of a unit
Throws:
Exception - Description of Exception

getUnitVisible

private void getUnitVisible()
                     throws Exception
Get a message that a new unit is visible to the client, gets the unit's properties and action, type, etc.
Throws:
Exception - Description of Exception

getMapUpdate

private void getMapUpdate()
                   throws Exception
get an update of a map point. (not used, getMapUpdates is used instead
Throws:
Exception - Description of Exception

getActionBlocked

private void getActionBlocked()
                       throws Exception
an action is no longer valid for a certain unit, get which action and which unit
Throws:
Exception - Description of Exception

getUnitDeleted

private void getUnitDeleted()
                     throws Exception
gets which unit has been deleted (not necessarily destroyed)
Throws:
Exception - Description of Exception

getUnitMessage

private void getUnitMessage()
                     throws Exception
gets a message about a certain unit
Throws:
Exception - Description of Exception

getUnitDestroyed

private void getUnitDestroyed()
                       throws Exception
a unit has been destroyed, get which one
Throws:
Exception - Description of Exception

getMapPointInvisible

private void getMapPointInvisible()
                           throws Exception
get which map point is no longer visible. getMapPointsInvisible is the preferred method to use
Throws:
Exception - Description of Exception

getMapPointsInvisible

private void getMapPointsInvisible()
                            throws Exception
gets an array of Points that are no longer visible
Throws:
Exception - Description of Exception

getInt

private int getInt(byte[] byteArray,
                   int index)
A helper function that makes unsigned casting from byte to int
Parameters:
byteArray - Description of Parameter
index - Description of Parameter
Returns:
The Int value

getMapUpdates

private void getMapUpdates()
                    throws Exception
Gets an array of positions and new colors for mappoints.
Throws:
Exception - Description of Exception

getActionCompleted

private void getActionCompleted()
                         throws Exception
Gets the handle of an action that has been completed
Throws:
Exception - Description of Exception

getActionFailed

private void getActionFailed()
                      throws Exception
Gets the handle and an error message for an action that failed
Throws:
Exception - Description of Exception

receiveMessage

private void receiveMessage(int leadingInteger)
                     throws Exception
Called when there are messages to receive from the server. Checks the type of message to get, and calls the appropriate method that gets that kind of message
Parameters:
leadingInteger - Description of Parameter
Throws:
Exception - Description of Exception