Building the NewsTicker Stream
The NewsTicker stream will be used to add news items that we specifically look for within our event definition. It will serve as a filter for all the data contained within the Player stream. This way, you can largely ignore the Player stream and trust that the NewsTicker stream will alert you when your desired data exists.
To build the NewsTicker Stream, add a new stream in the same manner as you did above and complete the following the steps:
- In the New Stream dialog box, enter 'MLB_News ' as the Namespace, 'NewsTicker ' as the Name, and 'Map Schema ' as the Type. Click OK.
- Build out the NewsTicker as specified in Table 2. Click Add.
Table 2. The NewsTicker Stream
|
Field
Name
|
Type
|
Nullable
|
|
NewsMessage
|
String
|
False
|
|
FirstName
|
String
|
True
|
|
LastName
|
String
|
True
|
|
Date
|
Date
|
False
|
|
Team
|
String
|
True
|
Once you build both of the stream objects, EPL Studio should resemble Figure 4. Now that we have some streams, we need to build the event object that will search for the desired data and insert items into the news ticker when it finds what we want.
 | |
| Figure 4. EPL Studio Displaying Both Stream Objects |
Creating the Chavez_Alert Event Definition
The Chavez_Alert event definition will scan the Player stream looking for news regarding Eric Chavez. If the alert finds any Chavez-related items, the event processor will add an item to the NewsTicker stream.
To build the Chavez_Alert, right-click the Event Definitions node in the System pane and select New Event Definition. In the New Event Definition dialog box, enter MLB_News as the Namespace and Chavez_Alert as the Name. Click OK to open the Event Definition editor.
A new event, as displayed in the Event Definition tab, only contains the keywords used in an event (ON, WHEN, THEN). Our event will scan the Player stream (ON) and look for news related to Eric Chavez (WHEN). If found, the event will insert a new item into the NewsTicker stream (THEN). To build the event, enter the following text as the Event Definition:
ON
Player
WHEN
Player.LastName = 'Chavez' AND Player.FirstName='Eric'
THEN
NewsTicker.INSERT(Player.LastAction, Player.FirstName, Player.LastName,
NOW(),Player.Team )
Once you enter the text, choose File > Save System from the EPL Studio file menu. Note, you can also view the EPL that was created for this Event Definition by clicking on the EPL tab of the editor. This action saves all EPL objects to the file system and will make them available when we start the EPL Server in the next section.
Start Server and Test Solution
Now that we have all of our components built, it's time to test our sample application. Before we can test the streams and the event, we need to start the EPL Server. Click the Windows Start Menu and Select [All] Programs > Event_Processor > Server > Start Server (if you saved your modified default engine in a different directory, you'll have to start this using the command line.) A command window will open and display the startup log of the server. Leave this window open; if you close it, the server will cease running.
Once the server is running, open the EPL Console by selecting Start > [All] Programs > Event_Processor > EPL Console. To test the sample application, complete the following steps:
- Click the Streams menu to display the streams in the EPL engine.
- Next to the Player stream, click the Insert into Stream button to display the input form (see Figure 5).
 | |
| Figure 5. Adding Data to the Player Stream |
- Add data to create a record for Eric Chavez and click Insert. This input will cause the Chavez_Alert event definition to take action and insert the news into the NewsTicker stream.
- To see the newly created news item, click the Streams link and then click the NewsTicker stream. The EPL Console will display the contents of the NewsTicker stream (see Figure 6).
 | |
| Figure 6. The NewsTicker Stream Containing the Latest Eric Chavez News |
More Complex Scenarios
This sample uses a very simple scenario to demonstrate how to begin building streams and event definitions. As you start building your own EPL solutions, you'll encounter more complex situations. For example, in the above example, Spring Training news comes from multiple feeds (i.e. Major broadcasters, blogs, play-by-play simulcasts, etc). You could create streams to monitor each feed for occurrences of Chavez and cross reference the incoming information against static data sources (e.g. statistical histories, personal bio information, contract details, etc).
With a combination of real-time streams and static data (accessed via a Data Adapter), you could combine both current and historical information to put events into context. For example, "Eric Chavez just hit his second home run today…making this game his tenth two-homerun game of the season." Furthermore, you could identify trends across all the data to highlight player trends. For example, "Eric Chavez leads baseball in RBIs and Fielding Percentage. A third baseman has not lead baseball in both of these categories at the same time since 1982."
Summary
As you can see, Avaya's Event Processing technology and Programming Language (EPL), provides you with the technology to build queries that scan data as it is created and to respond as you desire. Because EPL resembles SQL the learning-curve is relatively flat and your existing skills quickly translate into building EPL solutions. While the example in this article is basic, it does illustrate how you can begin monitoring the flow of data in your organization and responding when certain data conditions exist.
The EPL Console provides you with an easy way to insert test data into a stream and test the system. In a real-world solution you will want to tap into and monitor existing data streams. To do this requires working with Event Processor I/O adapters which we'll cover in a future article.