com.streamhub.api
Interface Payload

All Known Implementing Classes:
JsonPayload

public interface Payload

A Payload represents a message which is to be sent over the wire to a client or has been received from a client. A Payload must implement toCometBytes(), #toString() and have a client capable of decoding it.

The recommended implementation of Payload is JsonPayload which is supported out of the box in all StreamHub clients.

See Also:
JsonPayload

Method Summary
 void addField(String key, String value)
          Adds a field to the message with the key and value.
 Map<String,String> getFields()
          Returns a map of every single field added to this message
 void timestamp()
          If timestamping is enabled, adds a field named 'timestamp' to the Payload with a value of System.currentTimeMillis().
 byte[] toCometBytes()
          Returns a byte array representing the bytes ready to be sent over the wire to a Comet client.
 void toggleTimestamping(boolean onOrOff)
          Toggles timestamping on or off.
 

Method Detail

addField

void addField(String key,
              String value)
Adds a field to the message with the key and value.

Parameters:
key - the key of the message - must be unique
value - the value of the message

getFields

Map<String,String> getFields()
Returns a map of every single field added to this message

Returns:
A map of all the fields in this payload

toCometBytes

byte[] toCometBytes()
Returns a byte array representing the bytes ready to be sent over the wire to a Comet client.

This method should not be used to send a payload, use NIOServer.publish(String, Payload) or Client.send(String, Payload) instead.

Returns:
A byte array representing the bytes ready to be sent over the wire to a Comet client

toggleTimestamping

void toggleTimestamping(boolean onOrOff)
Toggles timestamping on or off. By default timestamping is off.

Parameters:
onOrOff - A boolean representing whether to turn on timestamping or not. Use true to enable it, and false to disable it.
See Also:
timestamp()

timestamp

void timestamp()
If timestamping is enabled, adds a field named 'timestamp' to the Payload with a value of System.currentTimeMillis().

See Also:
toggleTimestamping(boolean)


Copyright © 2009 StreamHub. Tutorials, news and guides can be found on the StreamHub Comet Blog.