gcspy.interpreter.client
Class ClientInterpreter

java.lang.Object
  extended by gcspy.comm.CommandStream
      extended by gcspy.interpreter.Interpreter
          extended by gcspy.interpreter.client.ClientInterpreter

public class ClientInterpreter
extends Interpreter

The client interpreter

Author:
Tony Printezis, Richard Jones

Nested Class Summary
 
Nested classes/interfaces inherited from class gcspy.interpreter.Interpreter
Interpreter.BootstrapParameters
 
Field Summary
 
Fields inherited from class gcspy.interpreter.Interpreter
client, CONTROL_CMD, DEFAULT_MAX_LEN, EVENT_CMD, EVENT_COUNT_CMD, EVENT_FILTERS_CMD, eventCount, eventFilters, events, generalInfo, name, PAUSE_CMD, PAUSE_REQ_CMD, PLAY_ONE_CMD, RESTART_CMD, SHUTDOWN_CMD, SHUTDOWN_REQ_CMD, SPACE_CMD, SPACE_INFO_CMD, spaceNum, spaces, STREAM_CMD, SUMMARY_CMD
 
Fields inherited from class gcspy.comm.CommandStream
cmds, FIRST_AVAILABLE_CMD, max, output
 
Constructor Summary
ClientInterpreter()
          Create a new ClientInterpreter
 
Method Summary
 void addEventListener(EventListener eventListener)
          Add an event listener.
 void addPauseListener(PauseListener pauseListener)
          Add a pause listener
 void addSpaceListener(SpaceListener spaceListener)
          Add a space listener
 void callEventListeners(int eventID, int elapsedTime, int compensationTime)
          Call the event listeners for an event We need synchronization because the add/remove calla modify the number of elements in the list, and the iterator might throw a concurrent modification exception.
 void callPauseListeners()
          Tell all pause listeners to pause
 void callSpaceListeners(ClientSpace space)
          Call the space listeners for a space
 void connectToServer(java.lang.String server, int port, boolean pauseAtStart)
          Connect to the server
 void connectToServer(java.lang.String server, int port, boolean pauseAtStart, int maxLen)
          Connect to the server
 void enableEventListeners()
          Enable the event listeners
 ClientSpace getClientSpace(int i)
          Get a client space
 void mainLoop()
          The main clinet interpretet loop.
 void removeEventListener(EventListener eventListener)
          Remove an event listener We need synchronization because the remove call modifies the number of elements in the list, and iterators might throw a concurrent modification exception.
 void removeSpaceListener(EventListener spaceListener)
          Remove a space listener
 void sendEventFilters()
          Send the client's event filters
 void sendEventFilters(EventFilters eventFilters)
          Send the event filters
 void sendPauseReq()
          Send a pause request command
 void sendPlayOne()
          Send a play one command
 void sendRestart()
          Send a restart command
 void sendShutdownReq()
          Send a shut down request command
 
Methods inherited from class gcspy.interpreter.Interpreter
deserialise, deserialiseEverything, dump, dumpSpaces, getEventCount, getEventFilters, getEvents, getGeneralInfo, getName, getSpace, getSpaceNum, println, receiveBootInfo, sendBootInfo, sendSingleCommand, serialise, serialiseEverything, setEventCount, setGeneralInfo, setSpace, setupEventCount, setupEventFilters, setVerbose
 
Methods inherited from class gcspy.comm.CommandStream
execute, finish, finish, getCmd, putCmd, putCmd, setBufferedOutput, start, start
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClientInterpreter

public ClientInterpreter()
Create a new ClientInterpreter

Method Detail

getClientSpace

public ClientSpace getClientSpace(int i)
Get a client space

Parameters:
i - the space's ID
Returns:
The client space

addPauseListener

public void addPauseListener(PauseListener pauseListener)
Add a pause listener

Parameters:
pauseListener - The listener

callPauseListeners

public void callPauseListeners()
Tell all pause listeners to pause


enableEventListeners

public void enableEventListeners()
Enable the event listeners


addEventListener

public void addEventListener(EventListener eventListener)
Add an event listener. We need synchronization because the add call modifies the number of elements in the list, and iterators might throw a concurrent modification exception.

Parameters:
eventListener - the event listener

removeEventListener

public void removeEventListener(EventListener eventListener)
Remove an event listener We need synchronization because the remove call modifies the number of elements in the list, and iterators might throw a concurrent modification exception.

Parameters:
eventListener - the event listener

callEventListeners

public void callEventListeners(int eventID,
                               int elapsedTime,
                               int compensationTime)
Call the event listeners for an event We need synchronization because the add/remove calla modify the number of elements in the list, and the iterator might throw a concurrent modification exception.

Parameters:
eventID - The event's ID
elapsedTime - The elapsed time
compensationTime - The compensation time

addSpaceListener

public void addSpaceListener(SpaceListener spaceListener)
Add a space listener

Parameters:
spaceListener - the listener.

removeSpaceListener

public void removeSpaceListener(EventListener spaceListener)
Remove a space listener

Parameters:
spaceListener - the listener.

callSpaceListeners

public void callSpaceListeners(ClientSpace space)
Call the space listeners for a space

Parameters:
space - The space

sendPauseReq

public void sendPauseReq()
                  throws java.io.IOException
Send a pause request command

Throws:
java.io.IOException

sendRestart

public void sendRestart()
                 throws java.io.IOException
Send a restart command

Throws:
java.io.IOException

sendPlayOne

public void sendPlayOne()
                 throws java.io.IOException
Send a play one command

Throws:
java.io.IOException

sendShutdownReq

public void sendShutdownReq()
                     throws java.io.IOException
Send a shut down request command

Throws:
java.io.IOException

sendEventFilters

public void sendEventFilters()
                      throws java.io.IOException
Send the client's event filters

Throws:
java.io.IOException

sendEventFilters

public void sendEventFilters(EventFilters eventFilters)
                      throws java.io.IOException
Send the event filters

Parameters:
eventFilters - The evnet filters to send
Throws:
java.io.IOException

connectToServer

public void connectToServer(java.lang.String server,
                            int port,
                            boolean pauseAtStart)
                     throws java.io.IOException
Connect to the server

Parameters:
server - The server's host name
port - The port on which to connect
pauseAtStart - Whether the server should pause at the start
Throws:
java.io.IOException

connectToServer

public void connectToServer(java.lang.String server,
                            int port,
                            boolean pauseAtStart,
                            int maxLen)
                     throws java.io.IOException
Connect to the server

Parameters:
server - The server's host name
port - The port on which to connect
pauseAtStart - Whether the server should pause at the start
maxLen - The maximum length of the communication buffers
Throws:
java.io.IOException

mainLoop

public void mainLoop()
              throws java.io.IOException
The main clinet interpretet loop. It repeatedly receives commands and exectutes them

Throws:
java.io.IOException