Extracting an Application Module

Instead of creating a new application module, you can also extract a subset of components from an existing EventFlow. StreamBase creates the new application module for you, and inserts a new module reference in your EventFlow that links to the new application module.

Note that the graphical procedure described in this topic is only available for EventFlows. StreamBase Studio does not enable you to extract an application module from a StreamSQL application.

  1. In the StreamBase Studio SB Authoring perspective, open the application that contains the components you want to extract.

  2. In the EventFlow Editor, select a contiguous group of components to include in the application module. In the following example, the selected group includes two Map operators and a Gather operator:

    Note

    Please observe the following rules for selecting components:

    • Application modules do not include the streams going into and out of the group of components you select, and by default, such streams are omitted from your selection. For example, in the preceding screen, the selection includes internal arcs, but omits the arcs going into the Filter_2 operator and out of Map_4. As we will show later, StreamBase uses an internal representation of input and output streams when it creates the module.

      If you explicitly add any of these streams or arcs to your selection, the Extract as Module command is not available.

    • Do not omit any components that a selected operator or data construct depends on. For example, if you select a Query operator but omit its associated Query Table data construct, you cannot extract your selection into a module.

    Note

    If one or more components that you extract already have the concurrency (Run this component in its own thread) option enabled, those settings are preserved in the new sbapp file. However, if concurrency is appropriate for the components, (see Execution Order, Concurrency, and Parallelism), the most common use case is that you:

    • Disable the concurrency option for each individual operator that resides "inside" the module. and...

    • Instead, enable the concurrency option of the module reference.

  3. Select Extract as Module from the Diagram menu, or right-click your selection and choose the same command.

  4. In the Extract as Module dialog:

    • Specify a name for the new module.

    • Choose whether to open the module in the editor.

  5. Click OK. StreamBase creates a new sbapp EventFlow application file with the module name you entered, containing the components you selected. The new application is created in the project folder of the application you extracted it from. At the same time, an icon for the new application is added in the Modules drawer of the palette.

    In your current EventFlow, the selected components are replaced with a single new Module Reference component, which links to the new application module.

    Notice the input and output ports on the new Module Reference icon, which StreamBase has connected to appropriate components in your application.

    If you like, you can open the new application module to see its contents, by right-clicking the module reference in the EventFlow diagram and choosing Open Referenced Application in Editor. The following sample screen shows the application diagram of the application module created in the preceding figure. Compare it to the first figure in this topic, which shows the initial selection of elements. Notice that where the selection omitted the outer arcs, StreamBase has added input and output streams. These streams have the same schemas as the corresponding connections in the application:

  6. Verify that the new module reference has no typecheck errors. If it does, you may need to edit the module reference's properties, as described in Defining Module Reference Properties.

    Note that changing module reference properties does not change the application module being referenced: it is a local change that affects only the referencing application. By contrast, if you change an application module, the changes affect every application that references it.

  7. Save your application.