This documentation is for WSO2 Complex Event Processor 2.0.1. View documentation for the latest release.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Siddhi supports custom codes within queries.

In the current implementation Windows and Aggregators are implemented in a pluggable manner.

Note

These are subject to change, in future release.

Writing a custom Window

To write a custom window you have to create a class in the package "org.wso2.siddhi.core.query.stream.handler.window" with a name <Name>WindowHandler, and it has to extend "org.wso2.siddhi.core.query.stream.handler.window.WindowHandler".

You need to compile that class and add the jar to the class path. (In WSO2 CEP add that to the CEP_HOME/repertory/components/lib)

E.g for creating firstUnique window you class name need to be FirstUniqueWindowHandler.

You can use your class in the query as follows

from StockExchangeStream[price >= 20]#window.firstUnique(50) 
insert into StockQuote symbol, price

Writing a custom Aggregator

To write a custom aggregator you have to create a class in the package "org.wso2.siddhi.core.query.projector.attibute.processor" with a name <Name>AggregateAttributeProcessor, and it has to extend "org.wso2.siddhi.core.query.projector.attibute.processor.AbstractAggregateAttributeProcessor". This will work as the base class for aggregator creation.

Then you also need to create appropriate runtime aggregators implementing "org.wso2.siddhi.core.query.projector.attibute.aggregator.Aggregator" which will be specific for attribute types, such as  STRING, INT, LONG, FLOAT, DOUBLE & BOOL.

You need to compile these classes and add the jars to the class path. (In WSO2 CEP add them to the CEP_HOME/repertory/components/lib)

E.g for creating std Aggregator you need to create a class with name StdAggregateAttributeProcessor, and some appropriate Aggregators.

You can use your class in the query as follows


from StockExchangeStream[price >= 20]#window.length(50) 
insert into StockQuote symbol, std(price) as stdPrice

  • No labels