gcspy.interpreter.server
Class ServerInterpreter

java.lang.Object
  extended by gcspy.comm.CommandStream
      extended by gcspy.interpreter.Interpreter
          extended by gcspy.interpreter.server.ServerInterpreter
All Implemented Interfaces:
java.lang.Runnable

public class ServerInterpreter
extends Interpreter
implements java.lang.Runnable

The server interpreter

Author:
Tony Printezis

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
ServerInterpreter(java.lang.String name, boolean collectStats)
          Create a new server interpreter
ServerInterpreter(java.lang.String name, boolean collectStats, Events events, int spaceNum)
          Create a new server interpreter
 
Method Summary
 int addServerSpace(ServerSpace space)
          Add a server space to the interpreter
 void countingEventBoundary(int eventID)
          Indicate an event boundary and update counters if necessary
 void eventBoundary(int eventID, int elapsedTime, int compensationTime)
          Indicate an event boundary
 ServerSpace getServerSpace(int i)
          Get a server space
protected  void internalSetup()
          Set up a connection.
 void run()
          Start the main interpreter thread loop
 void safepoint()
          Indicate a safe point
 void sendControl(int spaceID, byte[] control)
          Send a control stream for a space
 void sendEvent(int eventID, int elapsedTime, int compensationTime)
          Send an event
 void sendEventCount()
          Send the event count
 void sendPause()
          Send a PAUSE comand
 void sendShutdown()
          Senf a SHUT_DOWN command
 void sendSpace(Space space)
          Send a space
 void sendSpaceInfo(int spaceID, java.lang.String spaceInfo)
          Send the space information
 void sendStream(int spaceID, int streamID, int dataType, java.lang.Object data)
          Send a stream for a space
 void sendStream(int spaceID, int streamID, int dataType, java.lang.Object data, int len)
          Send a stream for a space
 void sendSummary(int spaceID, int streamID, int[] summary)
          Send the summary
 boolean shouldTransmit(int eventID)
          Should this event be transmitted?
 void startCompensationTimer()
          Start the compensation timer
 void startServer(int port)
          Start the server
 void startServer(int port, boolean wait)
          Start the server
 void startServer(int port, boolean wait, int maxLen)
          Start the server
 void stopCompensationTimer()
          Stop the compensation timer
 void transmitStreams()
          Transmit all the streams for all the spaces known to tis interpreter.
 void updateEventCounter(int eventID)
          Update the event counter for an event
 
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

ServerInterpreter

public ServerInterpreter(java.lang.String name,
                         boolean collectStats)
Create a new server interpreter

Parameters:
name - The server's name
collectStats - WHether to collect statistics

ServerInterpreter

public ServerInterpreter(java.lang.String name,
                         boolean collectStats,
                         Events events,
                         int spaceNum)
Create a new server interpreter

Parameters:
name - The server's name
collectStats - Whether to collect statistics
events - The events
spaceNum - The number of spaces
Method Detail

getServerSpace

public ServerSpace getServerSpace(int i)
Get a server space

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

addServerSpace

public int addServerSpace(ServerSpace space)
Add a server space to the interpreter

Parameters:
space - The server space
Returns:
an ID for the space

transmitStreams

public void transmitStreams()
                     throws java.io.IOException
Transmit all the streams for all the spaces known to tis interpreter.

Throws:
java.io.IOException

sendPause

public void sendPause()
               throws java.io.IOException
Send a PAUSE comand

Throws:
java.io.IOException

sendShutdown

public void sendShutdown()
                  throws java.io.IOException
Senf a SHUT_DOWN command

Throws:
java.io.IOException

sendStream

public void sendStream(int spaceID,
                       int streamID,
                       int dataType,
                       java.lang.Object data)
                throws java.io.IOException
Send a stream for a space

Parameters:
spaceID - The space's ID
streamID - The stream's ID
dataType - The stream's data type
data - The stream's data
Throws:
java.io.IOException

sendStream

public void sendStream(int spaceID,
                       int streamID,
                       int dataType,
                       java.lang.Object data,
                       int len)
                throws java.io.IOException
Send a stream for a space

Parameters:
spaceID - The space's ID
streamID - The stream's ID
dataType - The stream's data type
data - The stream's data
len - The length of the stream data
Throws:
java.io.IOException

sendEvent

public void sendEvent(int eventID,
                      int elapsedTime,
                      int compensationTime)
               throws java.io.IOException
Send an event

Parameters:
eventID - The event's ID
elapsedTime - The elapsed time fo rthe event
compensationTime - The compensation time fo rthe event
Throws:
java.io.IOException

sendControl

public void sendControl(int spaceID,
                        byte[] control)
                 throws java.io.IOException
Send a control stream for a space

Parameters:
spaceID - The space's ID
control - The controls
Throws:
java.io.IOException

sendEventCount

public void sendEventCount()
                    throws java.io.IOException
Send the event count

Throws:
java.io.IOException

sendSummary

public void sendSummary(int spaceID,
                        int streamID,
                        int[] summary)
                 throws java.io.IOException
Send the summary

Parameters:
spaceID - The space's ID
streamID - The stream's ID
summary - The summary values
Throws:
java.io.IOException

sendSpaceInfo

public void sendSpaceInfo(int spaceID,
                          java.lang.String spaceInfo)
                   throws java.io.IOException
Send the space information

Parameters:
spaceID - The space's ID
spaceInfo - The space information
Throws:
java.io.IOException

sendSpace

public void sendSpace(Space space)
               throws java.io.IOException
Send a space

Parameters:
space - The space
Throws:
java.io.IOException

startServer

public void startServer(int port)
                 throws java.io.IOException
Start the server

Parameters:
port - The port on which to communicate
Throws:
java.io.IOException

startServer

public void startServer(int port,
                        boolean wait)
                 throws java.io.IOException
Start the server

Parameters:
port - The port on which to communicate
wait - Whether to wait until client connects
Throws:
java.io.IOException

startServer

public void startServer(int port,
                        boolean wait,
                        int maxLen)
                 throws java.io.IOException
Start the server

Parameters:
port - The port on which to communicate
wait - Whether to wait until client connects
maxLen - The buffer length
Throws:
java.io.IOException

startCompensationTimer

public void startCompensationTimer()
Start the compensation timer


stopCompensationTimer

public void stopCompensationTimer()
Stop the compensation timer


run

public void run()
Start the main interpreter thread loop

Specified by:
run in interface java.lang.Runnable

safepoint

public void safepoint()
Indicate a safe point


updateEventCounter

public void updateEventCounter(int eventID)
Update the event counter for an event

Parameters:
eventID - The event's ID

eventBoundary

public void eventBoundary(int eventID,
                          int elapsedTime,
                          int compensationTime)
Indicate an event boundary

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

countingEventBoundary

public void countingEventBoundary(int eventID)
Indicate an event boundary and update counters if necessary

Parameters:
eventID - The event's ID

shouldTransmit

public boolean shouldTransmit(int eventID)
Should this event be transmitted?

Parameters:
eventID - The event ID
Returns:
true if the server is connected and this event is enabled?

internalSetup

protected void internalSetup()
Set up a connection. This is called per connection