Search in sources :

Example 1 with SiddhiEventFactory

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

the class EventTestCase method testEventCreation.

@Test
public void testEventCreation() {
    SiddhiEventFactory siddhiEventFactory = new SiddhiEventFactory(2);
    AssertJUnit.assertEquals(2, siddhiEventFactory.newInstance().getData().length);
    StreamEventFactory streamEventFactory = new StreamEventFactory(2, 3, 4);
    StreamEvent streamEvent = streamEventFactory.newInstance();
    AssertJUnit.assertEquals(2, streamEvent.getBeforeWindowData().length);
    AssertJUnit.assertEquals(3, streamEvent.getOnAfterWindowData().length);
    AssertJUnit.assertEquals(4, streamEvent.getOutputData().length);
}
Also used : StreamEventFactory(org.ballerinalang.siddhi.core.event.stream.StreamEventFactory) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) SiddhiEventFactory(org.ballerinalang.siddhi.core.event.SiddhiEventFactory) Test(org.testng.annotations.Test)

Example 2 with SiddhiEventFactory

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

the class StreamJunction method startProcessing.

/**
 * Create and start disruptor based on annotations given in the streamDefinition.
 */
public synchronized void startProcessing() {
    if (!receivers.isEmpty() && async) {
        for (Constructor constructor : Disruptor.class.getConstructors()) {
            if (constructor.getParameterTypes().length == 5) {
                // If new disruptor classes available
                ProducerType producerType = ProducerType.MULTI;
                disruptor = new Disruptor<Event>(new SiddhiEventFactory(streamDefinition.getAttributeList().size()), bufferSize, executorService, producerType, new BlockingWaitStrategy());
                disruptor.handleExceptionsWith(siddhiAppContext.getDisruptorExceptionHandler());
                break;
            }
        }
        if (disruptor == null) {
            disruptor = new Disruptor<Event>(new SiddhiEventFactory(streamDefinition.getAttributeList().size()), bufferSize, executorService);
            disruptor.handleExceptionsWith(siddhiAppContext.getDisruptorExceptionHandler());
        }
        for (Receiver receiver : receivers) {
            disruptor.handleEventsWith(new StreamHandler(receiver));
        }
        ringBuffer = disruptor.start();
    } else {
        for (Receiver receiver : receivers) {
            if (receiver instanceof StreamCallback) {
                ((StreamCallback) receiver).startProcessing();
            }
        }
    }
}
Also used : BlockingWaitStrategy(com.lmax.disruptor.BlockingWaitStrategy) ProducerType(com.lmax.disruptor.dsl.ProducerType) Constructor(java.lang.reflect.Constructor) ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) Event(org.ballerinalang.siddhi.core.event.Event) SiddhiEventFactory(org.ballerinalang.siddhi.core.event.SiddhiEventFactory) StreamCallback(org.ballerinalang.siddhi.core.stream.output.StreamCallback)

Aggregations

SiddhiEventFactory (org.ballerinalang.siddhi.core.event.SiddhiEventFactory)2 BlockingWaitStrategy (com.lmax.disruptor.BlockingWaitStrategy)1 ProducerType (com.lmax.disruptor.dsl.ProducerType)1 Constructor (java.lang.reflect.Constructor)1 ComplexEvent (org.ballerinalang.siddhi.core.event.ComplexEvent)1 Event (org.ballerinalang.siddhi.core.event.Event)1 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)1 StreamEvent (org.ballerinalang.siddhi.core.event.stream.StreamEvent)1 StreamEventFactory (org.ballerinalang.siddhi.core.event.stream.StreamEventFactory)1 StreamCallback (org.ballerinalang.siddhi.core.stream.output.StreamCallback)1 Test (org.testng.annotations.Test)1