its.backbone.sdd
Class SddTransmitter

java.lang.Object
  extended byits.backbone.sdd.SddTransmitter
Direct Known Subclasses:
DemoTransmitter

public class SddTransmitter
extends java.lang.Object


Field Summary
protected  Contents contents
          Contains the parsed Contents object after a successful call to transmitContents.
 boolean parseDataFrame
          By default, SddTransmitter runs the SDD Contents parser on Contents and Data frames.
protected  Schema schema
          Contains the parsed Schema object after a successful call to transmitSchema.
protected  short timeout
           
 boolean useCompression
          By default, SddTransmitter uses GZIPOutputStream to compress each frame.
 
Constructor Summary
SddTransmitter(int requestPort)
          constructor: starts listening for connections on the given port
SddTransmitter(int requestPort, AccessManager accessManager)
           
 
Method Summary
 int getClientCount()
          Returns the number of clients currently connected to this data stream.
 void setContentsSerialNumber(java.lang.String sn)
           
 void setSchemaSerialNumber(java.lang.String sn)
           
 void setSerialNumbers(java.lang.String sn)
           
 void setSerialNumbers(java.lang.String schemaSN, java.lang.String contentsSN)
           
 void setTimeout(int s)
          Sets the value placed in the "timeout" field of the ItsFrame objects created by SddTransmitter.
 void startPulse(int frequencySeconds)
          Starts a thread that sends an empty data frame after the given interval has elapsed with no network activity.
 void stop()
           
 void stopPulse()
          Stops the thread that was started by startPulse.
 void transmitContents(java.lang.String contents)
          Creates and sends an ITSFrame containing two BER encoded packets: a serial number encoding of the current time and the given contents.
 void transmitContentsFile(java.lang.String contentsFileName)
          for convenience, reads the contents from a file and transmits it.
 void transmitData(byte[] data)
          creates and sends an ITSFrame containing two BER encoded packets: a serial number matching the current contents and the given data.
 void transmitData(java.lang.String data)
          creates and sends an ITSFrame containing two BER encoded packets: a serial number matching the current contents and the given data.
 void transmitExtractor(java.lang.String jarFileName)
          creates and sends an ITSFrame containing two BER encoded packets: a serial number matching the current schema, and the contents of the given jar file (which had better contain an implementation of DataFactory.)
 void transmitSchema(java.lang.String schema)
          Creates and sends an ITSFrame containing two BER encoded packets: a serial number encoding of the current time and the given schema.
 void transmitSchemaFile(java.lang.String schemaFileName)
          for convenience, reads the schema from a file and transmits it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

useCompression

public boolean useCompression
By default, SddTransmitter uses GZIPOutputStream to compress each frame. To disable this behavior, set useCompression to false.


parseDataFrame

public boolean parseDataFrame
By default, SddTransmitter runs the SDD Contents parser on Contents and Data frames. If an application-specific format for the data frame is required, the parser can be disabled by setting parseDataFrame to false.


schema

protected Schema schema
Contains the parsed Schema object after a successful call to transmitSchema.


contents

protected Contents contents
Contains the parsed Contents object after a successful call to transmitContents.


timeout

protected short timeout
Constructor Detail

SddTransmitter

public SddTransmitter(int requestPort)
               throws java.io.IOException
constructor: starts listening for connections on the given port

Parameters:
requestPort - the port others will use to connect to this transmitter

SddTransmitter

public SddTransmitter(int requestPort,
                      AccessManager accessManager)
               throws java.io.IOException
Method Detail

setSerialNumbers

public void setSerialNumbers(java.lang.String sn)

setSerialNumbers

public void setSerialNumbers(java.lang.String schemaSN,
                             java.lang.String contentsSN)

setSchemaSerialNumber

public void setSchemaSerialNumber(java.lang.String sn)

setContentsSerialNumber

public void setContentsSerialNumber(java.lang.String sn)

transmitSchemaFile

public void transmitSchemaFile(java.lang.String schemaFileName)
                        throws java.io.IOException,
                               SchemaParserException
for convenience, reads the schema from a file and transmits it.

Parameters:
schemaFileName - name of text file containing the schema
Throws:
java.io.IOException - if the file cannot be read
ItsException - if the schema contains parse errors
SchemaParserException

transmitSchema

public void transmitSchema(java.lang.String schema)
                    throws SchemaParserException
Creates and sends an ITSFrame containing two BER encoded packets: a serial number encoding of the current time and the given schema. If the schema has changed since the last time transmitSchema was called, a new serial number will be generated; otherwise, the original serial number is retained.

Parameters:
schema - the schema encoded as a String
Throws:
SchemaParserException - if the schema contains parse errors

transmitContents

public void transmitContents(java.lang.String contents)
                      throws ContentsParserException,
                             MissingSchemaException
Creates and sends an ITSFrame containing two BER encoded packets: a serial number encoding of the current time and the given contents. If the contents information has changed since the last time transmitContents was called, a new serial number will be generated; otherwise, the original serial number is retained.

Parameters:
contents - the contents encoded as a String
Throws:
ContentsParserException - if the contents data contains parse errors or does not match the current schema
MissingSchemaException - if transmitSchema has not already been called successfully

transmitContentsFile

public void transmitContentsFile(java.lang.String contentsFileName)
                          throws java.io.IOException,
                                 ContentsParserException,
                                 MissingSchemaException
for convenience, reads the contents from a file and transmits it.

Parameters:
contentsFileName - name of text file containing the schema
Throws:
java.io.IOException - if the file cannot be read
ContentsParserException - if the contents contains parse errors
MissingSchemaException - if transmitSchema has not already been called successfully

transmitData

public void transmitData(byte[] data)
                  throws ContentsParserException,
                         MissingContentsException
creates and sends an ITSFrame containing two BER encoded packets: a serial number matching the current contents and the given data.

Parameters:
data - the data encoded as an array of bytes
Throws:
MissingContentsException - if transmitContents has not already been called successfully
ContentsParserException

transmitData

public void transmitData(java.lang.String data)
                  throws ContentsParserException,
                         MissingContentsException
creates and sends an ITSFrame containing two BER encoded packets: a serial number matching the current contents and the given data.

Parameters:
data - the data encoded as a String
Throws:
MissingContentsException - if transmitContents has not already been called successfully
ContentsParserException

transmitExtractor

public void transmitExtractor(java.lang.String jarFileName)
                       throws java.io.IOException,
                              MissingSchemaException
creates and sends an ITSFrame containing two BER encoded packets: a serial number matching the current schema, and the contents of the given jar file (which had better contain an implementation of DataFactory.)

Parameters:
jarFileName - name of jar file containing extractor
Throws:
java.io.IOException - if the file cannot be read
MissingSchemaException
See Also:
DataFactory

setTimeout

public void setTimeout(int s)
Sets the value placed in the "timeout" field of the ItsFrame objects created by SddTransmitter. Receivers can use this field to determine the maximum number of seconds to wait for the next data frame. If the field contains 0, receivers use a default timeout of 30 seconds. If the data stream being implemented generates data frames less frequently, it is important to specify a timeout value longer than this default.


stop

public void stop()

startPulse

public void startPulse(int frequencySeconds)
Starts a thread that sends an empty data frame after the given interval has elapsed with no network activity. This is one way for the transmitter to provide a "heartbeat" packet that informs its clients that their connection is still valid, the stream is still alive, but there is no new data. This can be useful for implementing asynchronous streams, where a long interval may pass between updates to large data sets. In this case, the large data set should be transmitted in the Contents frame, so that the pulse frame doesn't take its place as the most recent data frame, and newly connected clients will receive the most recent data set.


stopPulse

public void stopPulse()
Stops the thread that was started by startPulse. Calling startPulse again with a different frequency achieves the same result.


getClientCount

public int getClientCount()
Returns the number of clients currently connected to this data stream.