Search in sources :

Example 6 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation in project siddhi by wso2.

the class SiddhiExtensionLoader method addExtensionToMap.

/**
 * Adding extensions to Siddhi siddhiExtensionsMap.
 *
 * @param extensionClass      extension class
 * @param siddhiExtensionsMap reference map for the Siddhi extension
 */
private static void addExtensionToMap(Class extensionClass, Map<String, Class> siddhiExtensionsMap) {
    Extension siddhiExtensionAnnotation = (Extension) extensionClass.getAnnotation(Extension.class);
    if (siddhiExtensionAnnotation != null) {
        if (!siddhiExtensionAnnotation.name().isEmpty()) {
            Class previousClass = null;
            if (!siddhiExtensionAnnotation.namespace().isEmpty()) {
                String key = siddhiExtensionAnnotation.namespace() + SiddhiConstants.EXTENSION_SEPARATOR + siddhiExtensionAnnotation.name();
                Class existingValue = siddhiExtensionsMap.get(key);
                if (existingValue == null) {
                    previousClass = siddhiExtensionsMap.put(key, extensionClass);
                }
                if (previousClass != null) {
                    log.warn("Dropping extension '" + extensionClass + "' as '" + previousClass + "' was already " + "loaded with the same namespace and name '" + siddhiExtensionAnnotation.namespace() + SiddhiConstants.EXTENSION_SEPARATOR + siddhiExtensionAnnotation.name() + "'");
                }
            } else {
                previousClass = siddhiExtensionsMap.put(siddhiExtensionAnnotation.name(), extensionClass);
                if (previousClass != null) {
                    log.warn("Dropping extension '" + extensionClass + "' as '" + previousClass + "' was already " + "loaded with the " + "same name '" + siddhiExtensionAnnotation.name() + "'");
                }
            }
        } else {
            log.error("Unable to load extension " + extensionClass.getName() + ", missing Extension annotation.");
        }
    } else {
        log.error("Unable to load extension " + extensionClass.getName() + ", empty name element given in " + "Extension annotation.");
    }
}
Also used : Extension(org.wso2.siddhi.annotation.Extension)

Example 7 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation in project siddhi by wso2.

the class PartitionTestCase1 method testPartitionQuery39.

@Test
public void testPartitionQuery39() throws InterruptedException {
    log.info("Partition test");
    SiddhiApp siddhiApp = SiddhiApp.siddhiApp("Test").defineStream(StreamDefinition.id("streamA").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT));
    Query query = Query.query();
    query.from(InputStream.stream("streamA"));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")));
    query.insertInto("StockQuote");
    Partition partition = Partition.partition().annotation(Annotation.annotation("info").element("name", "partitionA")).with("streamA", Expression.variable("symbol")).addQuery(query);
    siddhiApp.addPartition(partition);
    SiddhiManager siddhiManager = new SiddhiManager();
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    StreamCallback streamCallback = new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            AssertJUnit.assertTrue("IBM".equals(events[0].getData(0)) || "WSO2".equals(events[0].getData(0)));
            count.addAndGet(events.length);
            eventArrived = true;
        }
    };
    siddhiAppRuntime.addCallback("StockQuote", streamCallback);
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("streamA");
    siddhiAppRuntime.start();
    inputHandler.send(new Event(System.currentTimeMillis(), new Object[] { "IBM", 700 }));
    inputHandler.send(new Event(System.currentTimeMillis(), new Object[] { "WSO2", 60 }));
    inputHandler.send(new Event(System.currentTimeMillis(), new Object[] { "WSO2", 60 }));
    Thread.sleep(1000);
    AssertJUnit.assertEquals(3, count.get());
    siddhiAppRuntime.shutdown();
}
Also used : Partition(org.wso2.siddhi.query.api.execution.partition.Partition) InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiApp(org.wso2.siddhi.query.api.SiddhiApp) Query(org.wso2.siddhi.query.api.execution.query.Query) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Example 8 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation in project siddhi by wso2.

the class SingleClientDistributedSink method initTransport.

@Override
public void initTransport(OptionHolder sinkOptionHolder, List<OptionHolder> destinationOptionHolders, Annotation sinkAnnotation, ConfigReader sinkConfigReader, SiddhiAppContext siddhiAppContext) {
    final String transportType = sinkOptionHolder.validateAndGetStaticValue(SiddhiConstants.ANNOTATION_ELEMENT_TYPE);
    Extension sinkExtension = DefinitionParserHelper.constructExtension(streamDefinition, SiddhiConstants.ANNOTATION_SINK, transportType, sinkAnnotation, SiddhiConstants.NAMESPACE_SINK);
    Set<String> allDynamicOptionKeys = findAllDynamicOptions(destinationOptionHolders);
    destinationOptionHolders.forEach(optionHolder -> {
        optionHolder.merge(sinkOptionHolder);
        allDynamicOptionKeys.forEach(optionKey -> {
            String optionValue = optionHolder.getOrCreateOption(optionKey, null).getValue();
            if (optionValue == null || optionValue.isEmpty()) {
                throw new SiddhiAppValidationException("Destination properties can only contain " + "non-empty static values.");
            }
            Option sinkOption = sinkOptionHolder.getOrAddStaticOption(optionKey, optionValue);
            sinkOption.addVariableValue(optionValue);
            destinationCount++;
        });
    });
    this.sink = (Sink) SiddhiClassLoader.loadExtensionImplementation(sinkExtension, SinkExecutorExtensionHolder.getInstance(siddhiAppContext));
    this.sink.initOnlyTransport(streamDefinition, sinkOptionHolder, sinkConfigReader, siddhiAppContext);
}
Also used : Extension(org.wso2.siddhi.query.api.extension.Extension) SiddhiAppValidationException(org.wso2.siddhi.query.api.exception.SiddhiAppValidationException)

Example 9 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation in project siddhi by wso2.

the class JunctionTestCase method oneToOneTest.

@Test
public void oneToOneTest() throws InterruptedException {
    log.info("one to one");
    StreamDefinition streamA = StreamDefinition.id("streamA").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).annotation(Annotation.annotation("parallel"));
    StreamJunction streamJunctionA = new StreamJunction(streamA, executorService, 1024, siddhiAppContext);
    StreamJunction.Publisher streamPublisherA = streamJunctionA.constructPublisher();
    StreamDefinition streamB = StreamDefinition.id("streamB").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).annotation(Annotation.annotation("parallel"));
    StreamJunction streamJunctionB = new StreamJunction(streamB, executorService, 1024, siddhiAppContext);
    final StreamJunction.Publisher streamPublisherB = streamJunctionB.constructPublisher();
    StreamCallback streamCallbackA = new StreamCallback() {

        @Override
        public void receive(Event[] streamEvents) {
            for (Event streamEvent : streamEvents) {
                StreamEvent innerStreamEvent = new StreamEvent(2, 2, 2);
                innerStreamEvent.setTimestamp(streamEvent.getTimestamp());
                innerStreamEvent.setOutputData(streamEvent.getData());
                streamPublisherB.send(innerStreamEvent);
            }
        }
    };
    StreamCallback streamCallbackB = new StreamCallback() {

        @Override
        public void receive(Event[] streamEvents) {
            count += streamEvents.length;
            eventArrived = true;
            for (Event streamEvent : streamEvents) {
                AssertJUnit.assertTrue(streamEvent.getData()[0].equals("IBM") || (streamEvent.getData()[0].equals("WSO2")));
            }
        }
    };
    streamJunctionA.subscribe(streamCallbackA);
    streamJunctionA.startProcessing();
    streamJunctionB.subscribe(streamCallbackB);
    streamJunctionB.startProcessing();
    // Thread.sleep(100);
    StreamEvent streamEvent1 = new StreamEvent(2, 2, 2);
    streamEvent1.setTimestamp(System.currentTimeMillis());
    streamEvent1.setOutputData(new Object[] { "IBM", 12 });
    StreamEvent streamEvent2 = new StreamEvent(2, 2, 2);
    streamEvent2.setTimestamp(System.currentTimeMillis());
    streamEvent2.setOutputData(new Object[] { "WSO2", 112 });
    streamPublisherA.send(streamEvent1);
    streamPublisherA.send(streamEvent2);
    Thread.sleep(100);
    AssertJUnit.assertTrue(eventArrived);
    AssertJUnit.assertEquals(2, count);
    streamJunctionA.stopProcessing();
    streamJunctionB.stopProcessing();
}
Also used : StreamDefinition(org.wso2.siddhi.query.api.definition.StreamDefinition) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) Event(org.wso2.siddhi.core.event.Event) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Example 10 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation in project siddhi by wso2.

the class JunctionTestCase method junctionToReceiverTest.

@Test
public void junctionToReceiverTest() throws InterruptedException {
    log.info("junction to receiver");
    StreamDefinition streamA = StreamDefinition.id("streamA").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).annotation(Annotation.annotation("parallel"));
    StreamJunction streamJunctionA = new StreamJunction(streamA, executorService, 1024, siddhiAppContext);
    StreamJunction.Publisher streamPublisherA = streamJunctionA.constructPublisher();
    StreamCallback streamCallback = new StreamCallback() {

        @Override
        public void receive(Event[] streamEvents) {
            count += streamEvents.length;
            eventArrived = true;
        }
    };
    streamJunctionA.subscribe(streamCallback);
    streamJunctionA.startProcessing();
    streamPublisherA.send(new StreamEvent(2, 2, 2));
    streamPublisherA.send(new StreamEvent(2, 2, 2));
    Thread.sleep(100);
    AssertJUnit.assertTrue(eventArrived);
    AssertJUnit.assertEquals(2, count);
    streamJunctionA.stopProcessing();
}
Also used : StreamDefinition(org.wso2.siddhi.query.api.definition.StreamDefinition) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)29 ArrayList (java.util.ArrayList)14 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)12 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)11 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)11 HashMap (java.util.HashMap)9 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)9 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)9 List (java.util.List)8 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)8 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)8 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)8 Annotation (org.wso2.siddhi.query.api.annotation.Annotation)8 BLangConnector (org.wso2.ballerinalang.compiler.tree.BLangConnector)7 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)7 BLangResource (org.wso2.ballerinalang.compiler.tree.BLangResource)7 BLangService (org.wso2.ballerinalang.compiler.tree.BLangService)7 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)7 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)7 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)7