Adobe Flex Output Adapter

Introduction

The Adobe Flex output adapter serves one or more internal StreamBase streams to Flex client applications for visualization within the Adobe Flash Player. The adapter listens on a TCP port for incoming connections from one or more Flex clients. Clients use a library provided with StreamBase to connect to the adapter. Any combination of Flex control and charting objects can be used within the client application to present meaningful views of the StreamBase data to the user.

Note

This adapter is deprecated as of StreamBase release 7.2.5 and will be removed in a future release.

The primary direction of data flow is from the StreamBase application to the Flex client. However, the adapter and corresponding client library support a control stream for passing data in the opposite direction. This is useful in cases where input entered by the user via the Flex client must be passed to the StreamBase application.

Properties

The Flex adapter is configured with the properties shown in the following table. Properties are set in the Adapter Settings tab of the Properties view in StreamBase Studio. In certain cases, properties can also be set in the StreamBase Server configuration file.

properties table

Property Description
Stream Names This property names one or more internal StreamBase streams to be served by the adapter to Flex clients. Streams are listed in the order they are connected to the adapter's input ports. As names are added to this table, additional input ports appear on the adapter icon within StreamBase Studio. Flex clients subscribe to streams using the names entered in this table.
Listen Port This property provides the TCP port number on which the adapter listens for incoming connections from Flex clients.
Policy File This property contains the name of an optional cross-domain policy file used to enforce Flash Player security rules. Flex applications can access all data resources in the same domain as the .swf file. However, in retrieving data from a different domain, the policy file determines whether the client should be granted access. An example policy file, crossdomain.xml, is shipped with the Flex adapter sample.
Enable Debugging If set to true, traffic between the adapter and the Flex client is displayed in the Server Diagnostics view (when running in StreamBase Studio) or sent to standard output.

StreamBase Flex Client Library

StreamBase provides a library, flexclient.swc, that allows Flex clients to subscribe to streams and send control commands to StreamBase applications. The library is installed in the lib subdirectory of the top-level StreamBase installation directory. This library should be used in developing Flex client applications that interact with StreamBase.

The library consists of a single ActionScript class, StreamReader, which provides bidirectional data flow between a StreamBase application and the Flex client. Clients should use an instance of StreamReader for each StreamBase stream being accessed. The StreamReader constructor provides the following arguments:

  • host: Host name or IP address of the StreamBase Server.

  • port: TCP port number the Flex adapter has been configured to listen on.

  • stream: One of the adapter's configured stream names.

  • tupleReceivedCallback: Name of an ActionScript function to be invoked when tuples are received from StreamBase.

  • connectionOpenedCallback: Name of an ActionScript function to be invoked when a connection to StreamBase is opened.

  • connectionClosedCallback: Name of an ActionScript function to be invoked when a connection to StreamBase is closed.

The tupleReceivedCallback function receives a single argument: an ActionScript Object containing the contents of the tuple received from StreamBase. Object properties hold tuple field values, with property names matching those of the corresponding stream fields.

StreamReader Example

The following example contains ActionScript code illustrating the use of the StreamReader class.

import com.streambase.sb.StreamReader;

private var myStreamReader:StreamReader = 
    new StreamReader(
        "localhost", 
        20000, 
        "myStream",
        tupleReceived,
        connectionOpened,
        connectionClosed);

private function tupleReceived(tuple:Object):void {
        
    var myInt:int = tuple.myInt;
    var myString:String = tuple.String;

    // TODO: process the tuple field values
}

public function connectionOpened(event:Event):void {
        
    // TODO: process the connection opened event
}

public function connectionClosed(event:Event):void {
        
    // TODO: process the connection closed event
}

For a more detailed example, refer to the source code for the sample shipped with the StreamBase Flex adapter.

Control Commands

The Flex adapter supports data flow from Flex clients to StreamBase via a single output (control) stream. The control stream's schema is set via the adapter's Edit Schema property tab.

Flex client applications use the StreamReader's writeControlCommand function to write control tuples to StreamBase. writeControlCommand takes a single Object argument, which contains a property for each field of the adapter's control stream. The Object's property names must match the field names of the control stream. If the property for a StreamBase field is missing, that field is sent as null in the resulting tuple.

The following example illustrates the use of the writeControlCommand method.

var myValue:int = 5;
myStreamReader.writeControlCommand({object: "speed", action: "set", p1: myValue});

Note

The StreamReader class uses a connectionOpened callback to subscribe to the stream specified in its constructor. If you send control commands that result in tuples being returned through this stream, do so only after receiving a call to connectionOpened. Otherwise, a race condition exists in which your control command could reach the StreamBase Server before the subscription request, and the resulting tuples would be lost.

The following NOT recommended code fragment is subject to this race condition.

myStreamReader:StreamReader = new StreamReader(...);
myStreamReader.writeControlCommand(...);

Replace code like the above fragment with the following:

myStreamReader:StreamReader = new StreamReader(...,connectionOpened,...);

public function connectionOpened(event:Event):void {
    myStreamReader.writeControlCommand(...);
    }

Typechecking and Error Handling

Typechecking fails in the following circumstances:

  • More than 25 named input streams are specified.

  • This listen port is not between 1024 and 65535.

Suspend/Resume Behavior

On suspend, the adapter stops serving streams to Flex clients. Tuples received by a suspended adapter are discarded.

On resumption, the adapter again begins serving streams to Flex clients.