Using the StreamBase Embedded Adapter Wizard

This topic explains how to use the StreamBase Embedded Adapter wizard to generate the base code for a custom embedded adapter. For additional details, please refer to the StreamBase Help topics listed in Related Topics.

Introduction

In the StreamBase Java API, we provide the com.streambase.sb.adapter.InputAdapter and com.streambase.sb.adapter.OutputAdapter classes, which you can extend to define custom embedded adapters for your StreamBase applications. Embedded adapters run in the same server process (sbd) that is hosting and processing your StreamBase application's requests, thus eliminating the client/server communication overhead seen with external adapters. Embedded adapters start and stop automatically with the StreamBase application, which simplifies many administration tasks.

The Embedded Adapter wizard helps you get started with the Java API by stepping you through the definition process. The Java source file that it generates has commented TODO sections that you can later edit to add the functionality you want.

After you replace these sections with your implementation code, you can use the adapter immediately in applications that you run locally in StreamBase Studio. If you are running your applications remotely, you may want to generate a JAR first.

Using the StreamBase Embedded Adapter Wizard

To open the wizard, click FileNewStreamBase Embedded Adapter. Edit these fields in the wizard:

Type

Select between Input Adapter and Output Adapter. Input adapters take information from outside of a StreamBase application and provide it in the form of a stream or streams to the application. Output adapters take streams from a StreamBase application and make them available outside of the application.

Source folder

Specify the path to an existing folder within your StreamBase Studio project, or to a referenced folder. The default path entered for you is the java-src subfolder of the current project.

Package

Specify the name of a Java package to contain your adapter class, such as com.mycompany.mysbapp.myadapter.

Name

Specify a name for your class, such as MyInputAdapter.

Display Name

Specify a display name to identify your adapter within StreamBase Studio. If not specified, the adapter name in the field above is used.

Ports

For Input Adapters, specify the number of output ports. For Output Adapters, specify the number of input ports.

For example:

If the wizard detects that the Java Client API is not on your project's build path, it displays a message informing you of the problem and suggesting a solution. See Adding StreamBase Client API to the Project Build Path.

When ready, click Next to display the next page (either the input or output adapter page).

Setting Input Adapter Properties

Use the Input Adapter dialog to set properties for your custom embedded Input Adapter. Input adapters take information from outside of a StreamBase application and provide it in the form of a stream or streams to the application. This class implements com.streambase.sb.adapter.InputAdapter. Input adapters should call sendOutput(int, Tuple) to provide tuples to the application.

  1. Define the properties for the adapter:

    1. Click the Add button in the Input Adapter page.

    2. In the New Adapter Property dialog, set the Type, Name, Display name, and default values.

    3. In the New Adapter Property dialog, set the Property, Name, Display name, and Default Value. By default, properties are required: uncheck Optional property if you want to make this property optional.

    4. Click OK to add the property to the Input Adapter page.

    5. Repeat the previous steps for each property you want to add.

    Use the other buttons to modify or manage properties in the adapter. For example, select a property and click Edit to change its values; use the Up and Down buttons to change the order of properties in the generated adapter.

  2. Optionally, change the default setting to Use a background thread. When enabled, this option generates code that enqueues the tuples in a thread separate from the application’s main thread.

  3. Optionally, change which method stubs will be created:

    • init()

    • resume() and suspend()

    • shutdown()

  4. When you are ready, click Finish.

    Two Java classes will be generated: an adapter class and a bean info class. You will not need to edit the content of the bean info class, but you do need to provide implementations for the methods marked // TODO. You will need to edit the body of the constructor method if you have an Enum type as a configurable parameter.

  5. The wizard prompts you to refresh the project's Typecheck Environment. Do this in one of the following ways:

    1. Switch to the project's EventFlow application and press Ctrl-F5, or run Refresh Project Typecheck Environment from the context menu.

    2. Select the project's name in the Package Explorer, right-click, and choose StreamBaseRefresh Typecheck Environment.

    Notice that refreshing the typecheck environment (Ctrl-F5) is not the same as the Apply and Typecheck operation (Ctrl-T).

    The new adapter does not appear in the Project Adapters drawer of the Palette view until you run this step.

    Tip

    You must repeat this step whenever you make changes to source files for your Java adapter.

Setting Output Adapter Properties

Use the Output Adapter dialog to set properties for your custom embedded Input Adapter. Output adapters take streams from a StreamBase application and make them available outside of the application. This class implements com.streambase.sb.adapter.OutputAdapter. Output adapters should override the method processTuple(int, Tuple) to receive tuples from the application.

  1. Define the properties for the adapter:

    1. Click the Add button in the Output Adapter page.

    2. In the New Adapter Property dialog, set the Property, Name, Display name, and Default Value. By default, properties are required: uncheck Optional property if you want to make this property optional.

    3. Click OK to add the property to the Output Adapter page.

    4. Repeat the previous steps for each property you want to add.

    Use the other buttons to modify or manage properties in the adapter. For example, select a property and click Edit to change its values; use the Up and Down buttons to change the order of properties in the generated adapter.

  2. Optionally, change the default setting to Use a background thread. When enabled, this option generates code that enqueues the tuples in a thread separate from the application’s main thread.

  3. Optionally, change which method stubs will be created:

    • init()

    • resume() and suspend()

    • shutdown()

  4. When you are ready, click Finish.

    Two Java classes will be generated: an adapter class and a bean info class. You will not need to edit the content of the bean info class, but you do need to provide implementations for the methods marked // TODO. You will need to edit the body of the constructor method if you have an Enum type as a configurable parameter.

  5. The wizard prompts you to refresh the project's Typecheck Environment. Do so after clicking OK to dismiss the wizard: right-click the project in the Package Explorer, and choose StreamBaseRefresh Typecheck Environment. This makes the new adapter available for use by your applications.

    Tip

    You must repeat this step whenever you make changes to source files that you want your applications to use.

Related Topics

  • For general information about using the StreamBase API for Java clients, start in API Guide.

  • For the Java API Javadoc, see the StreamBase Application Programming Interfaces topic of the StreamBase Reference Guide.