Contents
The Interfaces sample application demonstrates how to use StreamBase interfaces to enforce a set of stream and schema definitions, and to use different implementations of the same interface for different purposes.
The top-level application uses two Extension Point operators that each implement a different StreamBase interface. One Extension Point references two modules, while the other references one module. See This Sample's Files below for a description of each interface and module.
This sample illustrates several aspects of Extension Point operators and StreamBase interfaces. For further exploration of the Extension Point operator, see the Extension Point Operator Sample.
In StreamBase Studio, import this sample with the following steps:
-
From the top-level menu, select
> . -
Enter
interf
to narrow the list of options. -
Select the StreamBase interfaces sample from the Applications category.
-
Click
.
StreamBase Studio creates a project for the sample.
-
In the Project Explorer view, open the sample you just loaded.
If you see red marks on a project folder, wait a moment for the project to load its features.
If the red marks do not resolve themselves after a minute, select the project, right-click, and select
> from the context menu. -
Open the
src/main/eventflow/
folder.packageName
-
Open the package folder.
-
Open the
TopLevel.sbapp
file and click theRun button. This opens the SB Test/Debug perspective and starts the module.
-
In the Manual Input view, select the QuotesIn input stream.
-
Enter
ibm
,119.00
, and2000
in thesymbol
,price
, andvolume
fields, respectively. (You can enter the stocksymbol
field in lowercase, because the first Map operator converts that field to uppercase.) -
Click
, and observe data like the following in the Output Streams view. The first line might be a Buy order in your case, because it is processed by the module that randomizes buy and sell orders.Output Stream Fields SellOrders Time Output Stream Fields 13:56:38 SellOrders order_id=Rndm-1, symbol=IBM, order_type=sell, price=119.0, volume=2000 UnexpectedOrder Time Output Stream Fields 13:56:38 UnexpectedOrders order_id=Half-1, symbol=IBM, order_type=sellTYPOHERE, price=119.0, volume=1000 -
Notice that there is an order on the
UnexpectedOrder
stream. This is because the sample as shipped contains a deliberate error to force at least one case of unexpected orders. The Filter operator that splits the output into three streams looks for a match in theorder_type
field of eitherbuy
orsell
. However, one of the application's modules,BuyOrSellHalfQ2O.sbapp
, outputs eitherbuy
orsellTYPOHERE
, instead ofsell
. -
[Optional] You can choose to stop the sample now to correct the sample's error, then restart it. If so, follow the sub-steps below; if not, continue on with step 9.
-
Stop the application by pressing F9 or click the
Terminate EventFlow Fragment button.
-
In the Project Explorer view, open the sample you just loaded.
-
Open the
src/main/eventflow/
folder.packageName
-
Open the
com.tibco.sb.sample.interfaces.modules
package folder. -
Double-click
BuyOrSellHalfQ2O.sbapp
to open it. -
Double-click the
BuyOrSellHalf
Map operator to open its Properties view. -
In the Properties view, locate the Expression column corresponding to the
order_type
output field. -
Remove
TYPOHERE
from the expression. -
Save
BuyOrSellHalfQ2O.sbapp
. -
Switch back to the
TopLevel.sbapp
application, save it, and click theRun button to restart it.
-
Re-enter the same data as before:
ibm
,119.00
, and2000
. -
Click
, and observe that this time, there are two orders on theSellOrders
stream:Output Stream Fields SellOrders Time Output Stream Fields 14:30:59 SellOrders order_id=Random-1, symbol=IBM, order_type=sell, price=119.0, volume=2000 SellOrders Time Output Stream Fields 14:30:59 SellOrders order_id=Half-1, symbol=IBM, order_type=sell, price=119.0, volume=1000 The prefix on the order_id field (
Half-
orRandom-
) tells you which sub-module processed the order. The first order was processed byRandomBuyOrSellQ2O.sbapp
, while the second order was processed byBuyOrSellHalf.sbapp
.
-
-
Enter similar data, but this time use an even number for the price field:
ibm
,120.00
, and2000
. -
Click
, and observe data like the following in the Output Streams view. Remember that your results may vary because of processing by the module that randomizes buy and sell orders.Output Stream Fields SellOrders Time Output Stream Fields 14:33:24 SellOrders order_id=Random-2, symbol=IBM, order_type=sell, price=120.0, volume=3000 BuyOrders Time Output Stream Fields 14:33:24 BuyOrders order_id=Half-2, symbol=IBM, order_type=buy, price=120.0, volume=1500 BuyOrders Time Output Stream Fields 14:33:24 BuyOrders order_id=Yester-1, symbol=IBM, order_type=buy, price=120.0, volume=3000 -
Continue entering data in the Manual Input view to see the results. Keep in mind the following points:
-
The
BuyOrSellHalf.sbapp
module is set up to process quotes with even prices as buy orders, and odd prices as odd prices as sell orders. -
The
OrderIfBetterThanYesterday.sbapp
module only gets involved if thesymbol
you input is found in theHistoricalData
table, and the price meets certain criteria. TheHistoricalData
table is loaded from thequote-history.csv
file. Open that CSV file to determine the symbols and prices listed. To see this module in action, enter a price above the number in the first column of the CSV file, or below the number in the third column.
-
-
When done, press F9 or click the
Terminate EventFlow Fragment button.
The Interfaces sample includes the following files:
- In src/main/eventflow/com.tibco.sb.sample.interfaces:
-
- TopLevel.sbapp
-
The top-level application for this sample. The application populates the
HistoricalData
table on startup from a CSV file. - QuotesToOrders.sbint
-
A StreamBase interface that defines an input and an output stream, and defines named schemas used by those streams.
- QuotesToOrdersWithHistoricalData.sbint
-
A StreamBase interface that extends the
QuotesToOrders.sbint
interface, adding a table schema and placeholder table to the streams and schema definitions imported fromQuotesToOrders.sbint
.
- In src/main/eventflow/com.tibco.sb.sample.interfaces.modules:
-
- BuyOrSellHalfQ2O.sbapp
-
A module that implements the streams and schemas defined in the
QuotesToOrders.sbint
interface. This module determines whether to sell or buy based on the odd or evenness of the incoming price field. It contains a deliberate error in theBuyOrSellHalf
Map operator, which will send an order to theUnexpectedOrders
stream. Tuples processed by this module have the prefixHalf-
in their order IDs. - OrderIfBetterThanYesterday.sbapp
-
A module that implements the streams, named schemas, table schema, and placeholder table defined in the
QuotesToOrdersWithHistoricalData.sbint
interface. This module attempts to match the incoming symbol field against the same field in the HistoricalData table. If a match is found, the module sends a buy order if the incoming quote price is lower than yesterday's low price from the table, or sends a sell order if the incoming price is higher than yesterday's high price. Tuples processed by this module have the prefixYester-
in their order IDs. - RandomBuyOrSellQ2O.sbapp
-
Another module that implements the streams and schemas defined in the
QuotesToOrders.sbint
interface. This module determines at random whether to buy or sell. Tuples processed by this module have the prefixRndm-
in their order IDs.
- In src/main/resources:
-
- quote-history.csv
-
A small CSV file used to load data into the
HistoricalData
table inTopLevel.sbapp
.
When you load the sample into StreamBase Studio, Studio copies the sample project's files to your Studio workspace, which is normally part of your home directory, with full access rights.
Important
Load this sample in StreamBase Studio, and thereafter use the Studio workspace copy of the sample to run and test it, even when running from the command prompt.
Using the workspace copy of the sample avoids permission problems. The default workspace location for this sample is:
studio-workspace
/sample_interfaces
See Default Installation Directories for the default location of studio-workspace
on your system.