use of org.wso2.siddhi.query.api.annotation.Annotation in project siddhi by wso2.
the class MultiClientDistributedSink method initTransport.
@Override
public void initTransport(OptionHolder sinkOptionHolder, List<OptionHolder> destinationOptionHolders, Annotation sinkAnnotation, ConfigReader sinkConfigReader, SiddhiAppContext siddhiAppContext) {
String transportType = sinkOptionHolder.validateAndGetStaticValue(SiddhiConstants.ANNOTATION_ELEMENT_TYPE);
Extension sinkExtension = DefinitionParserHelper.constructExtension(streamDefinition, SiddhiConstants.ANNOTATION_SINK, transportType, sinkAnnotation, SiddhiConstants.NAMESPACE_SINK);
destinationOptionHolders.forEach(destinationOption -> {
Sink sink = (Sink) SiddhiClassLoader.loadExtensionImplementation(sinkExtension, SinkExecutorExtensionHolder.getInstance(siddhiAppContext));
destinationOption.merge(sinkOptionHolder);
sink.initOnlyTransport(streamDefinition, destinationOption, sinkConfigReader, siddhiAppContext);
transports.add(sink);
});
}
use of org.wso2.siddhi.query.api.annotation.Annotation in project siddhi by wso2.
the class PartitionTestCase1 method testPartitionQuery5.
@Test
public void testPartitionQuery5() throws InterruptedException {
log.info("Partition test5");
final SiddhiManager siddhiManager = new SiddhiManager();
SiddhiApp siddhiApp = new SiddhiApp("plan5");
StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
StreamDefinition streamDefinition1 = StreamDefinition.id("cseEventStream1").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
StreamDefinition streamDefinition2 = StreamDefinition.id("StockStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
siddhiApp.defineStream(streamDefinition);
siddhiApp.defineStream(streamDefinition1);
siddhiApp.defineStream(streamDefinition2);
Partition partition = Partition.partition().with("cseEventStream", Expression.variable("symbol"));
Query query = Query.query();
query.from(InputStream.stream("cseEventStream")).annotation(Annotation.annotation("info").element("name", "query"));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("volume", Expression.variable("volume")));
query.insertIntoInner("StockStream");
Query query1 = Query.query();
query1.from(InputStream.innerStream("StockStream")).annotation(Annotation.annotation("info").element("name", "query1"));
query1.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("volume", Expression.variable("volume")));
query1.insertInto("OutStockStream");
// //////////////////////////////////partition-2/////////////////
Partition partition1 = Partition.partition().with("cseEventStream1", Expression.variable("symbol"));
Query query2 = Query.query();
query2.from(InputStream.stream("cseEventStream1")).annotation(Annotation.annotation("info").element("name", "query2"));
query2.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("volume", Expression.variable("volume")));
query2.insertIntoInner("StockStream");
Query query3 = Query.query();
query3.from(InputStream.innerStream("StockStream")).annotation(Annotation.annotation("info").element("name", "query3"));
query3.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("volume", Expression.variable("volume")));
query3.insertInto("OutStockStream");
Query query4 = Query.query();
query4.from(InputStream.stream("StockStream")).annotation(Annotation.annotation("info").element("name", "query4"));
query4.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("volume", Expression.variable("volume")));
query4.insertInto("OutStockStream");
Query query5 = Query.query();
query5.from(InputStream.innerStream("StockStream")).annotation(Annotation.annotation("info").element("name", "query5"));
query5.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("volume", Expression.variable("volume")));
query5.insertInto("StockStream");
partition.addQuery(query);
partition.addQuery(query1);
partition.addQuery(query5);
partition1.addQuery(query2);
partition1.addQuery(query3);
siddhiApp.addPartition(partition);
siddhiApp.addPartition(partition1);
siddhiApp.addQuery(query4);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("StockStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
stockStreamEventCount = stockStreamEventCount + events.length;
}
});
siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
synchronized (siddhiManager) {
count.addAndGet(events.length);
eventArrived = true;
}
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
InputHandler inputHandler2 = siddhiAppRuntime.getInputHandler("cseEventStream1");
InputHandler inputHandler3 = siddhiAppRuntime.getInputHandler("StockStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 75.6f, 100 });
inputHandler.send(new Object[] { "WSO2", 75.6f, 100 });
inputHandler.send(new Object[] { "IBM", 75.6f, 100 });
inputHandler.send(new Object[] { "ORACLE", 75.6f, 100 });
inputHandler2.send(new Object[] { "IBM1", 75.6f, 100 });
inputHandler2.send(new Object[] { "WSO21", 75.6f, 100 });
inputHandler2.send(new Object[] { "IBM1", 75.6f, 100 });
inputHandler2.send(new Object[] { "ORACLE1", 75.6f, 100 });
inputHandler3.send(new Object[] { "ABC", 75.6f, 100 });
inputHandler3.send(new Object[] { "DEF", 75.6f, 100 });
inputHandler3.send(new Object[] { "KLM", 75.6f, 100 });
inputHandler3.send(new Object[] { "ABC", 75.6f, 100 });
SiddhiTestHelper.waitForEvents(100, 16, count, 60000);
AssertJUnit.assertEquals(16, count.get());
Thread.sleep(100);
AssertJUnit.assertEquals(8, stockStreamEventCount);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.annotation.Annotation in project siddhi by wso2.
the class SiddhiQLBaseVisitorImpl method visitAnnotation.
/**
* {@inheritDoc}
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*
* @param ctx
*/
@Override
public Annotation visitAnnotation(@NotNull SiddhiQLParser.AnnotationContext ctx) {
Annotation annotation = Annotation.annotation((String) visit(ctx.name()));
for (SiddhiQLParser.Annotation_elementContext elementContext : ctx.annotation_element()) {
annotation.element((Element) visit(elementContext));
}
for (SiddhiQLParser.AnnotationContext annotationContext : ctx.annotation()) {
annotation.annotation((Annotation) visit(annotationContext));
}
populateQueryContext(annotation, ctx);
return annotation;
}
use of org.wso2.siddhi.query.api.annotation.Annotation in project siddhi by wso2.
the class SiddhiQLBaseVisitorImpl method visitDefinition_stream.
/**
* {@inheritDoc}
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*
* @param ctx
*/
@Override
public StreamDefinition visitDefinition_stream(@NotNull SiddhiQLParser.Definition_streamContext ctx) {
Source source = (Source) visit(ctx.source());
if (source.isInnerStream) {
throw newSiddhiParserException(ctx, " InnerStreams cannot be defined!");
}
try {
StreamDefinition streamDefinition = StreamDefinition.id(source.streamId);
populateQueryContext(streamDefinition, ctx);
List<SiddhiQLParser.Attribute_nameContext> attribute_names = ctx.attribute_name();
List<SiddhiQLParser.Attribute_typeContext> attribute_types = ctx.attribute_type();
for (int i = 0; i < attribute_names.size(); i++) {
SiddhiQLParser.Attribute_nameContext attributeNameContext = attribute_names.get(i);
SiddhiQLParser.Attribute_typeContext attributeTypeContext = attribute_types.get(i);
streamDefinition.attribute((String) visit(attributeNameContext), (Attribute.Type) visit(attributeTypeContext));
}
for (SiddhiQLParser.AnnotationContext annotationContext : ctx.annotation()) {
streamDefinition.annotation((Annotation) visit(annotationContext));
}
return streamDefinition;
} catch (Throwable t) {
throw newSiddhiParserException(ctx, t.getMessage(), t);
}
}
use of org.wso2.siddhi.query.api.annotation.Annotation in project siddhi by wso2.
the class SiddhiQLBaseVisitorImpl method visitApp_annotation.
/**
* {@inheritDoc}
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*
* @param ctx
*/
@Override
public Annotation visitApp_annotation(@NotNull SiddhiQLParser.App_annotationContext ctx) {
Annotation annotation = new Annotation((String) visit(ctx.name()));
for (SiddhiQLParser.Annotation_elementContext elementContext : ctx.annotation_element()) {
annotation.element((Element) visit(elementContext));
}
populateQueryContext(annotation, ctx);
return annotation;
}
Aggregations