Search in sources :

Example 6 with StreamEventConverter

use of org.ballerinalang.siddhi.core.event.stream.converter.StreamEventConverter in project ballerina by ballerina-lang.

the class EventTestCase method testSimpleStreamEventConverter.

@Test
public void testSimpleStreamEventConverter() {
    Attribute price = new Attribute("price", Attribute.Type.DOUBLE);
    Attribute symbol = new Attribute("symbol", Attribute.Type.STRING);
    MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
    metaStreamEvent.addOutputData(symbol);
    metaStreamEvent.addOutputData(price);
    StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.DOUBLE).attribute("volume", Attribute.Type.INT);
    Event event = new Event(System.currentTimeMillis(), new Object[] { "WSO2", 200, 50 });
    metaStreamEvent.addInputDefinition(streamDefinition);
    StreamEventConverter converter = StreamEventConverterFactory.constructEventConverter(metaStreamEvent);
    StreamEventPool eventPool = new StreamEventPool(metaStreamEvent, 5);
    StreamEvent borrowedEvent = eventPool.borrowEvent();
    converter.convertEvent(event, borrowedEvent);
    AssertJUnit.assertTrue(converter instanceof SimpleStreamEventConverter);
    AssertJUnit.assertNull(borrowedEvent.getBeforeWindowData());
    AssertJUnit.assertNull(borrowedEvent.getOnAfterWindowData());
    AssertJUnit.assertEquals(2, borrowedEvent.getOutputData().length);
    AssertJUnit.assertEquals(200, borrowedEvent.getOutputData()[1]);
    AssertJUnit.assertEquals("WSO2", borrowedEvent.getOutputData()[0]);
}
Also used : StreamDefinition(org.ballerinalang.siddhi.query.api.definition.StreamDefinition) Attribute(org.ballerinalang.siddhi.query.api.definition.Attribute) SimpleStreamEventConverter(org.ballerinalang.siddhi.core.event.stream.converter.SimpleStreamEventConverter) StreamEventConverter(org.ballerinalang.siddhi.core.event.stream.converter.StreamEventConverter) ZeroStreamEventConverter(org.ballerinalang.siddhi.core.event.stream.converter.ZeroStreamEventConverter) SelectiveStreamEventConverter(org.ballerinalang.siddhi.core.event.stream.converter.SelectiveStreamEventConverter) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) StreamEventPool(org.ballerinalang.siddhi.core.event.stream.StreamEventPool) Event(org.ballerinalang.siddhi.core.event.Event) MetaStateEvent(org.ballerinalang.siddhi.core.event.state.MetaStateEvent) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) SimpleStreamEventConverter(org.ballerinalang.siddhi.core.event.stream.converter.SimpleStreamEventConverter) Test(org.testng.annotations.Test)

Example 7 with StreamEventConverter

use of org.ballerinalang.siddhi.core.event.stream.converter.StreamEventConverter in project ballerina by ballerina-lang.

the class EventTestCase method testPassThroughStreamEventConverter.

@Test
public void testPassThroughStreamEventConverter() {
    Attribute symbol = new Attribute("symbol", Attribute.Type.STRING);
    Attribute price = new Attribute("price", Attribute.Type.DOUBLE);
    Attribute volume = new Attribute("volume", Attribute.Type.INT);
    MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
    metaStreamEvent.addOutputDataAllowingDuplicate(symbol);
    metaStreamEvent.addOutputDataAllowingDuplicate(price);
    metaStreamEvent.addOutputDataAllowingDuplicate(volume);
    StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.DOUBLE).attribute("volume", Attribute.Type.INT);
    Event event = new Event(System.currentTimeMillis(), new Object[] { "WSO2", 200.0, 50 });
    metaStreamEvent.addInputDefinition(streamDefinition);
    StreamEventConverter converter = StreamEventConverterFactory.constructEventConverter(metaStreamEvent);
    StreamEventPool eventPool = new StreamEventPool(metaStreamEvent, 5);
    StreamEvent borrowedEvent = eventPool.borrowEvent();
    converter.convertEvent(event, borrowedEvent);
    AssertJUnit.assertTrue(converter instanceof ZeroStreamEventConverter);
    AssertJUnit.assertEquals(3, borrowedEvent.getOutputData().length);
    AssertJUnit.assertEquals("WSO2", borrowedEvent.getOutputData()[0]);
    AssertJUnit.assertEquals(200.0, borrowedEvent.getOutputData()[1]);
    AssertJUnit.assertEquals(50, borrowedEvent.getOutputData()[2]);
}
Also used : ZeroStreamEventConverter(org.ballerinalang.siddhi.core.event.stream.converter.ZeroStreamEventConverter) StreamDefinition(org.ballerinalang.siddhi.query.api.definition.StreamDefinition) Attribute(org.ballerinalang.siddhi.query.api.definition.Attribute) SimpleStreamEventConverter(org.ballerinalang.siddhi.core.event.stream.converter.SimpleStreamEventConverter) StreamEventConverter(org.ballerinalang.siddhi.core.event.stream.converter.StreamEventConverter) ZeroStreamEventConverter(org.ballerinalang.siddhi.core.event.stream.converter.ZeroStreamEventConverter) SelectiveStreamEventConverter(org.ballerinalang.siddhi.core.event.stream.converter.SelectiveStreamEventConverter) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) StreamEventPool(org.ballerinalang.siddhi.core.event.stream.StreamEventPool) Event(org.ballerinalang.siddhi.core.event.Event) MetaStateEvent(org.ballerinalang.siddhi.core.event.state.MetaStateEvent) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) Test(org.testng.annotations.Test)

Example 8 with StreamEventConverter

use of org.ballerinalang.siddhi.core.event.stream.converter.StreamEventConverter in project ballerina by ballerina-lang.

the class MultiProcessStreamReceiver method receive.

@Override
public void receive(Event[] events) {
    for (Event event : events) {
        synchronized (this) {
            stabilizeStates();
            for (int anEventSequence : eventSequence) {
                StreamEventConverter aStreamEventConverter = streamEventConverters[anEventSequence];
                StreamEventPool aStreamEventPool = streamEventPools[anEventSequence];
                StreamEvent borrowedEvent = aStreamEventPool.borrowEvent();
                aStreamEventConverter.convertEvent(event, borrowedEvent);
                process(anEventSequence, borrowedEvent);
            }
        }
    }
}
Also used : StreamEventConverter(org.ballerinalang.siddhi.core.event.stream.converter.StreamEventConverter) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) StreamEventPool(org.ballerinalang.siddhi.core.event.stream.StreamEventPool) Event(org.ballerinalang.siddhi.core.event.Event) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent)

Example 9 with StreamEventConverter

use of org.ballerinalang.siddhi.core.event.stream.converter.StreamEventConverter in project ballerina by ballerina-lang.

the class MultiProcessStreamReceiver method receive.

@Override
public void receive(Event event, boolean endOfBatch) {
    eventBuffer.add(event);
    if (endOfBatch) {
        for (Event aEvent : eventBuffer) {
            synchronized (this) {
                stabilizeStates();
                for (int anEventSequence : eventSequence) {
                    StreamEventConverter aStreamEventConverter = streamEventConverters[anEventSequence];
                    StreamEventPool aStreamEventPool = streamEventPools[anEventSequence];
                    StreamEvent borrowedEvent = aStreamEventPool.borrowEvent();
                    aStreamEventConverter.convertEvent(aEvent, borrowedEvent);
                    process(anEventSequence, borrowedEvent);
                }
            }
        }
        eventBuffer.clear();
    }
}
Also used : StreamEventConverter(org.ballerinalang.siddhi.core.event.stream.converter.StreamEventConverter) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) StreamEventPool(org.ballerinalang.siddhi.core.event.stream.StreamEventPool) Event(org.ballerinalang.siddhi.core.event.Event) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent)

Example 10 with StreamEventConverter

use of org.ballerinalang.siddhi.core.event.stream.converter.StreamEventConverter in project ballerina by ballerina-lang.

the class MultiProcessStreamReceiver method receive.

@Override
public void receive(long timestamp, Object[] data) {
    synchronized (this) {
        stabilizeStates();
        for (int anEventSequence : eventSequence) {
            StreamEventConverter aStreamEventConverter = streamEventConverters[anEventSequence];
            StreamEventPool aStreamEventPool = streamEventPools[anEventSequence];
            StreamEvent borrowedEvent = aStreamEventPool.borrowEvent();
            aStreamEventConverter.convertData(timestamp, data, borrowedEvent);
            process(anEventSequence, borrowedEvent);
        }
    }
}
Also used : StreamEventConverter(org.ballerinalang.siddhi.core.event.stream.converter.StreamEventConverter) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) StreamEventPool(org.ballerinalang.siddhi.core.event.stream.StreamEventPool)

Aggregations

StreamEventConverter (org.ballerinalang.siddhi.core.event.stream.converter.StreamEventConverter)10 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)9 StreamEventPool (org.ballerinalang.siddhi.core.event.stream.StreamEventPool)9 StreamEvent (org.ballerinalang.siddhi.core.event.stream.StreamEvent)8 Event (org.ballerinalang.siddhi.core.event.Event)5 ZeroStreamEventConverter (org.ballerinalang.siddhi.core.event.stream.converter.ZeroStreamEventConverter)4 Attribute (org.ballerinalang.siddhi.query.api.definition.Attribute)4 ComplexEvent (org.ballerinalang.siddhi.core.event.ComplexEvent)3 MetaStateEvent (org.ballerinalang.siddhi.core.event.state.MetaStateEvent)3 SelectiveStreamEventConverter (org.ballerinalang.siddhi.core.event.stream.converter.SelectiveStreamEventConverter)3 SimpleStreamEventConverter (org.ballerinalang.siddhi.core.event.stream.converter.SimpleStreamEventConverter)3 StreamDefinition (org.ballerinalang.siddhi.query.api.definition.StreamDefinition)3 Test (org.testng.annotations.Test)3 StateEventPool (org.ballerinalang.siddhi.core.event.state.StateEventPool)1 ConversionStreamEventChunk (org.ballerinalang.siddhi.core.event.stream.converter.ConversionStreamEventChunk)1 SiddhiAppCreationException (org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException)1 DeleteTableCallback (org.ballerinalang.siddhi.core.query.output.callback.DeleteTableCallback)1 InsertIntoStreamCallback (org.ballerinalang.siddhi.core.query.output.callback.InsertIntoStreamCallback)1 InsertIntoTableCallback (org.ballerinalang.siddhi.core.query.output.callback.InsertIntoTableCallback)1 InsertIntoWindowCallback (org.ballerinalang.siddhi.core.query.output.callback.InsertIntoWindowCallback)1