Embedded Adapter Introduction

StreamBase provides a number of embedded adapters that you can use within your application. Embedded adapters run in the same StreamBase Server process that is hosting and processing your StreamBase application. This configuration eliminates the client-server communication overhead incurred when using external adapters.

Embedded adapters start and stop automatically with the StreamBase application, which simplifies many administration tasks. In StreamBase Studio, you can define the properties for each embedded adapter that you drag and drop into the EventFlow diagram. You can also use embedded adapters in a StreamSQL application.

To learn about each of the embedded and external adapters available from StreamBase, as well as how to create your own custom embedded adapters, see the Adapters Guide.

Prerequisite steps (described in Developing Embedded Adapters in the API Guide):

  • You have created one or more custom embedded adapters (for example, by using the StreamBase Embedded Adapter wizard), and edited the generated java source to add the functionality you want, or placed a JAR file containing one or more custom embedded adapters in your project.

  • The StreamBase Java Client library is on your project's build path.

  • You have refreshed the project's Typecheck Environment.

Adding an Embedded Adapter to an EventFlow Application

To add an embedded adapter to a StreamBase EventFlow application:

  1. Open the sbapp application in the EventFlow editor.

  2. Drag the Adapter, Java Operator icon from the Palette Operators and Adapters drawer onto the EventFlow canvas.

  3. Select the adapter you want from the scrolling list in the dialog that opens. You can type filter text to find it more quickly.

    • If you are using one of the embedded adapters that are installed with StreamBase, look under Global Adapters in the Insert Operator or Adapter dialog. This folder can also include custom adapters, if they have been compiled and their JAR files stored in the Global Repository (as described in StreamBase Embedded Adapters).

    • If you are adding a custom adapter that is not in the Global Adapters folder, look in the Project Adapter folder.

      Tip

      If your adapter does not appear at first, try refreshing your project's typechecking environment, as described earlier.

  4. Click OK to place the adapter on the canvas.

  5. Click the adapter in the EventFlow Editor to open its Properties view. Set adapter properties in the tabs provided, as described in Setting Input Adapter Properties and Setting Output Adapter Properties.

  6. Connect the adapter to the appropriate components, according to the flow you want.

  7. Save the application. When you are ready to test it, click the Run button. The adapter will start automatically with the application.

Adding an Embedded Adapter to a StreamSQL Application

To add an embedded adapter to a StreamSQL application:

  1. Open the ssql application to which you want to add the embedded adapter.

  2. Add a StreamSQL APPLY statement, as described in the StreamSQL Guide.

    Here is a simple example that uses the CSV Reader embedded adapter, which gets data from a CSV file and sends it to a named Output Stream:

    CREATE INPUT STREAM In1 (f1 int);
    CREATE OUTPUT STREAM OutputStream1;
      APPLY JAVA "com.streambase.sb.adapter.csvreader.CSVReader"
      (FileName="example.csv", Delimiter=",", QuoteChar="\"",
      TimestampFormat="MM/dd/yyyy hh:mm:ss aa", Period=0, Repeat=1,
      Schema=(Timestamp timestamp, Username string, IP string)
      INTO OutputStream1;
    
  3. Save the application. When you are ready to test it, click the Run button. The adapter will start automatically with the application.

Controlling Embedded Adapter Availability in StreamBase Studio

The Global Repository is a special area that initially contains the embedded adapters installed by StreamBase. You can add other adapters to it to make them shareable, as described in this section. When StreamBase Studio starts, the adapters found there are loaded in the Global Adapters folder within the Insert Operator or Adapter dialog. The Global Repository is located in:

On Windows
C:\TIBCO\sb-cep\n.m\lib\adapter\
On Linux
/opt/tibco/sb-cep/n.m/lib/adapter/

Normally, an adapter that you import or create in your project is initially available only in that project. For example, after creating an adapter using the StreamBase Embedded Adapter Wizard (as described in Developing Embedded Adapters), the adapter source is automatically added to your project's Java Build Path. After you right-click your project and choose Refresh Project Typecheck Environment, your new adapter becomes available in the Project Adapters drawer of the Palette.

For your own development, working from the adapter source is the simplest method. However, if you need to share a working adapter with other StreamBase Studio users, you can package it and make it available in the Global Repository:

Note

On UNIX systems, root permissions may be required to write to the Global Repository.

  1. Right-click the adapter Java source file in the Package Explorer, and choose StreamBaseCreate Global Adapter Manifest.

  2. In the Generate StreamBase Manifest dialog:

    1. Make sure the class name is selected.

    2. In the workspace field, click Browse.

    3. In the Save As dialog, navigate to the root folder of your project.

      Then enter a file name for the manifest, with an extension of mf. For example, myAdapter.mf.

      Click OK to close the Save As dialog.

    4. Click OK to close the Generate StreamBase Manifest dialog.

  3. Again, right-click the adapter source in the Package Explorer. This time choose Export.

  4. In the Export wizard:

    1. Expand Java and choose JAR File. Then click Next.

    2. In the JAR File Specification page, navigate to the java source in your project and select it.

    3. In the JAR file field, navigate to the Global Repository on your system (see the default locations defined at the beginning of this section), and enter the name of the JAR file you want to create in the destination. Click Next.

    4. Click Next again in the JAR Packaging Options page.

    5. In the JAR Manifest Specification page, select the option, Use existing manifest from workspace.

    6. In the Manifest Selection dialog, navigate to the mf manifest file that you created earlier. Select it and click OK.

    7. Click Finish to complete the JAR Export dialog.

      If a dialog prompts you to save modified resources, click OK to confirm.

  5. Close StreamBase Studio.

The next time StreamBase Studio is opened using any workspace on your system, your new adapter is available in the Palette Global Adapters drawer.

Note

When troubleshooting problems with your adapters not loading as expected, be sure to check the Eclipse Error Log View, as described in Error Log View. If you see an entry in the log such as Unable to load global adapter, double-click that entry to see a stack trace of the failure.