Search in sources :

Example 21 with StreamEventPool

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

the class ComplexEventChunkTestCase method eventChunkRemoveTest5.

@Test(expectedExceptions = IllegalStateException.class)
public void eventChunkRemoveTest5() {
    StreamEvent streamEvent1 = new StreamEvent(0, 0, 3);
    streamEvent1.setOutputData(new Object[] { "IBM", 700L, 100L });
    StreamEvent streamEvent2 = new StreamEvent(0, 0, 3);
    streamEvent2.setOutputData(new Object[] { "WSO2", 700L, 100L });
    streamEvent1.setNext(streamEvent2);
    StreamEventPool streamEventPool = new StreamEventPool(0, 0, 3, 5);
    ConversionStreamEventChunk streamEventChunk = new ConversionStreamEventChunk(streamEventConverter, streamEventPool);
    streamEventChunk.convertAndAssign(streamEvent1);
    streamEventChunk.remove();
    streamEventChunk.remove();
}
Also used : ConversionStreamEventChunk(org.ballerinalang.siddhi.core.event.stream.converter.ConversionStreamEventChunk) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) StreamEventPool(org.ballerinalang.siddhi.core.event.stream.StreamEventPool) Test(org.testng.annotations.Test)

Example 22 with StreamEventPool

use of org.ballerinalang.siddhi.core.event.stream.StreamEventPool 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 23 with StreamEventPool

use of org.ballerinalang.siddhi.core.event.stream.StreamEventPool 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 24 with StreamEventPool

use of org.ballerinalang.siddhi.core.event.stream.StreamEventPool 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 25 with StreamEventPool

use of org.ballerinalang.siddhi.core.event.stream.StreamEventPool 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

StreamEventPool (org.ballerinalang.siddhi.core.event.stream.StreamEventPool)34 StreamEvent (org.ballerinalang.siddhi.core.event.stream.StreamEvent)16 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)15 Test (org.testng.annotations.Test)11 StreamEventConverter (org.ballerinalang.siddhi.core.event.stream.converter.StreamEventConverter)9 Attribute (org.ballerinalang.siddhi.query.api.definition.Attribute)8 Event (org.ballerinalang.siddhi.core.event.Event)6 ConversionStreamEventChunk (org.ballerinalang.siddhi.core.event.stream.converter.ConversionStreamEventChunk)6 MetaStateEvent (org.ballerinalang.siddhi.core.event.state.MetaStateEvent)5 ZeroStreamEventConverter (org.ballerinalang.siddhi.core.event.stream.converter.ZeroStreamEventConverter)5 StreamDefinition (org.ballerinalang.siddhi.query.api.definition.StreamDefinition)5 StreamEventCloner (org.ballerinalang.siddhi.core.event.stream.StreamEventCloner)4 ComplexEvent (org.ballerinalang.siddhi.core.event.ComplexEvent)3 SelectiveStreamEventConverter (org.ballerinalang.siddhi.core.event.stream.converter.SelectiveStreamEventConverter)3 SimpleStreamEventConverter (org.ballerinalang.siddhi.core.event.stream.converter.SimpleStreamEventConverter)3 SiddhiAppCreationException (org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException)3 Table (org.ballerinalang.siddhi.core.table.Table)3 ArrayList (java.util.ArrayList)2 StateEventCloner (org.ballerinalang.siddhi.core.event.state.StateEventCloner)2 StateEventPool (org.ballerinalang.siddhi.core.event.state.StateEventPool)2