Developers: Using the StreamBase Java Toolkit to Write a 'Dead End' Embedded Output Adapter

Home
Documentation
Library
Sample Code and Applications
FAQs
Articles
Community
Training
Download Center
Contact DevZone

Printer Friendly

Library Articles

Using the StreamBase Java Toolkit to Write a 'Dead End' Embedded Output Adapter

Author: Steve Barber
Contributor: Dr. John Lifter
StreamBase Systems
20-March-2007
Revised: 10-May-2007

Topics:

Introduction 

The Developer Zone article Using the StreamBase Java Toolkit to Create an Embedded Output Adapter presented a basic overview of the process used to write a custom embedded output adapter. Sometimes when developing a StreamBase application, you need to temporarily ignore the output of a stream. While you could simply not connect the stream to a downstream component, these tuples would still be captured by the StreamBase Studio in the Application Output View within the Test/Debug perspective. An alternative approach would be to direct these tuples to an embedded output adapter that justs drops each tuple without attempting to write, save, or display the tuple's field values.

This article illustrates how easy it is to create such a 'Dead End' embedded output adapter. This article was developed using the StreamBase Java Toolkit for Eclipse, v3.7.2, which supports development of enqueuer and dequeuer clients, custom Java operators, Java functions, and embedded adapters that are compatible with StreamBase 3.5.x or 3.7.x.

Starting an Eclipse StreamBase Project 

Follow these steps to create an Eclipse project in which to build a StreamBase Custom Embedded Output Adapter.

  1. In Eclipse, create a new Java project by selecting the File > New > Project... menu item, or right-click in the Package Explorer view and select New > Project... from the popup menu.

    In the New Project, Select a Wizard window, select Java Project and click the Next command button.

    In the New Project, Create a Java Project window, enter a Project name and click the Next command button.

  2. Use the New Java Project, Java Settings window to add the StreamBase client libraries to the project.

    Select the Libraries tab and click the Add Library... command button, which opens the Add Library window.

    Highlight the StreamBase Client API entry and click the Next command button.

    Complete the process by clicking the Finish command button.

Using the StreamBase Java Toolkit to Create the 'Dead End' Embedded Output Adapter 

Follow these steps to generate starting point code using the StreamBase Java Toolkit.

  1. Highlight the icon corresponding to the Java project, right-click and select New > Other... from the popup menu. Alternatively, highlight the project and select the File > New > Other... menu entry.

    The New, Select a Wizard window opens; expand the options under the StreamBase entry, highlight the StreamBase Embedded Adapter selection and click the Next command button.

  2. In the New StreamBase Embedded Adapter, StreamBase Embedded Adapter window, select the Output Adapter radio button in the Type: grouping, confirm that the Source folder: text box references the project directory, enter a package name into the Package: text box and a name for the adapter class into the Name: text box. Use the controls associated with the Number of Input ports: label to specify the number of input ports required by the adapter. (You can enter any package and class name you want.) Finally, select the radio button in the Target: grouping that corresponds to the version of StreamBase for which you are writing this adapter; then click the Next command button.
  3. Normally you use the New StreamBase Embedded Adapter, Output Adapter window add the class variables that will become the configurable parameters of the custom adapter. For this effort, you do not need to define any configurable properties.

    Finally, check, if desired, the Use a background thread check box.

    Now, click the Finish command button to generate the starting point code.

Editing the Generated Code 

The toolkit will generate two Java classes: an output adapter class and a bean info class. You will not add any code to either file. Since the output adapter class does not include an implementation for the processTuple method, nothing will be done with each tuple received from the input port(s).

Writing a Manifest File 

The manifest file that is included in the JAR file with a custom adapter must contain entries that identify the adapter class as a StreamBase adapter. Therefore, you must add a manifest file containing the desired text to this project. Both the content and syntax of the manifest file is very specific. Fortunately, the toolkit will assist you in this task.

  1. In the Package Explorer, highlight the file that represents the custom output adapter class, right-click, and select StreamBase > Generate StreamBase Manifest... from the popup menu.
  2. In the Generate StreamBase Manifest window, the entry corresponding to your output adapter class should already be identified. Select the Workspace radio button within the Destination grouping, click the Browse command button, and in the Save As window, pick a location into which the file should be written and give the file a name.

    Then click the OK command button twice and a manifest file, with the required content, is generated.

Creating a JAR File 

Before you can use your output adapter in a StreamBase application, you need to prepare a JAR file that contains the .class files and the manifest.

  1. In the Package Explorer, highlight the icon that represents your project and select File > Export... menu item. Alternatively, you can right-click and select Export... from the popup menu. In the Export window, select the JAR file entry under the Java category and click the Next command button.
  2. In the JAR Export, JAR File Specification window, check the checkbox corresponding to the package(s) you want to include in the JAR file and in the JAR file: text box, provide the path and name of the JAR file that will be created by this process.
  3. Then click the Next command button twice to move to the JAR Export, JAR Manifest Specification window.

    Select the Use existing manifest from workspace radio button and then enter (or browse to) the path and name of the manifest file written by the toolkit.

    Complete the process by clicking the Finish command button. The JAR file will be given the specified name and written to the location provided in the JAR Export, JAR File Specification window.

Adding the Output Adapter to a StreamBase Application 

Follow these steps to incorporate the custom input adapter into a StreamBase application.

  1. Start StreamBase Studio and create a new project that includes an Application Diagram.
  2. Import the JAR file (see Creating a JAR File).
  3. Next drag the Output Adapter icon from the palette onto the canvas. The Select Adapter window opens immediately and your output adapter class is listed in the drop down list.
  4. Select the adapter class and click the OK command button. The canvas now includes an Output Adapter icon.

Related Topics 

Back to Top ^