Oracle Stream Analysis – Pattern Matching

With the advent of IoT & big-data, the use cases for event processing should be shooting all time high. Recently, i have started to explore more on the Complex event processing (CEP) which is a subset of Stream processing. While I am still trying to understand the basic difference between Stream processing and Complex event processing,  the idea of Pattern matching in CEP looks so attractive for me. So, i have decided to have hands-on it.

My Experiment : Lucky Color Machine : 

img0

That is simple. Lets assume a jackpot machine which picks a random number (1-50) and a random color (in RED, GREEN, BLUE, BLACK, WHITE, YELLOW) for every 100 millisec. A successive sequence of event is considered to be successive when the jackpot machine results WHITE-RED-GREEN event and the winner is selected by this ticket number derived from the sum of all these 3 event’s lucky number (i.e. White’s Lucky number + Red’s lucky number + Green’s lucky number).

I do not want to be much more details how i have written these using Oracle’s stream Analysis platform (OSA). But, can give the brief outline of Event processing network (EPN):

  1. OSA allows us to write customer adapters in Java. So, for the jackpot machine i wrote a java class implementing StreamSource API. The class’s stream sender have been used to insert an event for every 100millisec. Huh ! An event is filled with a random pick from the list of color (as i said before) and a random number.
  2. The event of type ‘LuckyDraw’ has 1 property for color and 1 for number.
    1. The brain of EPN is the CQL processor(named WinnerFinder) which has the matching pattern logic implemented to look for the sequential events of White, Red & Green. And, when it finds the sequence, it adds the lucky number for each and projects the output to the next stage.
  3. Next is the print bean, which prints the winner’s ticket number. i.e. the total we got in the last stage.
  4. In the CQL processor, i have also added a property named ‘information’ which has the information about each’s color number (just for our debug purpose).

Below is the is CQL processor with its various parts:

CQL Language

 

Starting from the inner query :

  1. Line 15, 16 & 17 defines how CQL should be differentiating  various events from the incoming channel ( defined from Line 9). So, we differentiated based on the property named luckyColor.
  2. Line 13 defines the sequence the event should occur. In this case, it is ‘white red green’ in order. This is called Pattern quantifiers (like Regular expression).
  3. block MEASURES at line 10 defines what should be calculated from each event. In this case, winnerRollNumber as the total of each lucky number.
  4. Line 9 is the final projection that should be sent for the next stage in the EPN.

That is it. As expect, the event-type defined in the next stage of EPN having two property for roll number & information as we projected from the CQL processor. And, the print-bean just prints the value of the property we just sent out as below :

Screenshot from 2017-05-08 23-27-46

In addition, below is the place where you can find the code i have used ..

Below are the articles i have come across about event processing.

  1. Stream Processing vs. Complex Event Processing from softwareengineeringdaily.
  2. Design patterns from complexevents.
  3. CQL references from Oracle documentation

We have just done the basic pattern matching for the experiment we wanted to do ! I will keep posting for more stuffs we can do with pattern matching.

My full project of this can be downloadable from : GIT hub

Happy days.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s