Stream Handler

Use a stream handler for client-server communication.

Although Flex clients can use raw XML to subscribe to and receive stream data from Event Stream Processor, Sybase recommends that you delegate the client-server communication to a Stream Handler. To use the Stream Handler functionality, include the streamhandler.swc library, located in the lib directory, in your Flex client build.

Here is an example of using the Stream Handler in the ActionScript code:

	import com.sybase.esp.adapter.flex.StreamHandler;
private var streamHandler:StreamHandler = new StreamHandler(
"localhost", 23456, onConnect, onDisconnect, onRecord);
private function onConnect(event:Event):void {
// Invoked after the client has successfully connected to
// the adapter
}
private function onDisconnect(event:Event):void {
// Invoked after the client has disconnected from
// the adapter
}
private function onRecord(streamName:String, opcode:String,
record:Object):void {
// Invoked when the client receives a record from
// the adapter
}

To subscribe to a stream, invoke the subscribe() method of the Stream Handler with the stream name and filter parameters. The filter is an ActionScript object with several properties, one for each filtered column. You can use regular expressions as property values. For example:

var filter:Object = new Object();
filter.Symbol = "I.*";
streamHandler.subscribe("Stream1", filter);

Ensure that filtered columns are string type. To receive all stream records, without filtering, do not add any properties to the filter object. To unsubscribe from a stream, invoke the unsubscribe() method of the Stream Handler, passing in the stream name as a parameter.

For example:

streamHandler.subscribe("Stream1");
Implement the onRecord() callback method to process the records coming on a subscription. The callback has three parameters:
  • streamName
  • Opcode
  • An object which contains all non-null column values as properties

For example:

private function onRecord(streamName:String, opcode:String,
record:Object):void {
trace("Record received on stream " + streamName);
trace("Opcode=" + opcode);
trace("Column values:");
for (var column:String in record)
trace(column + "=" + record[column];