Search in sources :

Example 1 with StreamEventCloner

use of io.siddhi.core.event.stream.StreamEventCloner in project siddhi by wso2.

the class WrappedSnapshotOutputRateLimiter method init.

public void init(int outPutAttributeSize, List<AttributeProcessor> attributeProcessorList, MetaComplexEvent metaComplexEvent) {
    for (AttributeProcessor attributeProcessor : attributeProcessorList) {
        if (attributeProcessor.getExpressionExecutor() instanceof AttributeAggregatorExecutor<?>) {
            aggregateAttributePositionList.add(attributeProcessor.getOutputPosition());
        }
    }
    if (windowed) {
        if (groupBy) {
            if (outPutAttributeSize == aggregateAttributePositionList.size()) {
                // All Aggregation
                outputRateLimiter = new AllAggregationGroupByWindowedPerSnapshotOutputRateLimiter(value, this, groupBy, siddhiQueryContext);
            } else if (aggregateAttributePositionList.size() > 0) {
                // Some Aggregation
                outputRateLimiter = new AggregationGroupByWindowedPerSnapshotOutputRateLimiter(value, aggregateAttributePositionList, this, groupBy, siddhiQueryContext);
            } else {
                // No aggregation
                // GroupBy is same as Non GroupBy
                outputRateLimiter = new WindowedPerSnapshotOutputRateLimiter(value, this, groupBy, siddhiQueryContext);
            }
        } else {
            if (outPutAttributeSize == aggregateAttributePositionList.size()) {
                // All Aggregation
                outputRateLimiter = new AllAggregationPerSnapshotOutputRateLimiter(value, this, groupBy, siddhiQueryContext);
            } else if (aggregateAttributePositionList.size() > 0) {
                // Some Aggregation
                outputRateLimiter = new AggregationWindowedPerSnapshotOutputRateLimiter(value, aggregateAttributePositionList, this, groupBy, siddhiQueryContext);
            } else {
                // No aggregation
                outputRateLimiter = new WindowedPerSnapshotOutputRateLimiter(value, this, groupBy, siddhiQueryContext);
            }
        }
    } else {
        if (groupBy) {
            outputRateLimiter = new GroupByPerSnapshotOutputRateLimiter(value, this, groupBy, siddhiQueryContext);
        } else {
            outputRateLimiter = new PerSnapshotOutputRateLimiter(value, this, groupBy, siddhiQueryContext);
        }
    }
    if (metaComplexEvent instanceof MetaStateEvent) {
        StateEventFactory stateEventFactory = new StateEventFactory((MetaStateEvent) metaComplexEvent);
        outputRateLimiter.setStateEventCloner(new StateEventCloner((MetaStateEvent) metaComplexEvent, stateEventFactory));
    } else {
        StreamEventFactory streamEventFactory = new StreamEventFactory((MetaStreamEvent) metaComplexEvent);
        outputRateLimiter.setStreamEventCloner(new StreamEventCloner((MetaStreamEvent) metaComplexEvent, streamEventFactory));
    }
}
Also used : StreamEventFactory(io.siddhi.core.event.stream.StreamEventFactory) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) StateEventFactory(io.siddhi.core.event.state.StateEventFactory) StreamEventCloner(io.siddhi.core.event.stream.StreamEventCloner) AttributeProcessor(io.siddhi.core.query.selector.attribute.processor.AttributeProcessor) StateEventCloner(io.siddhi.core.event.state.StateEventCloner) AttributeAggregatorExecutor(io.siddhi.core.query.selector.attribute.aggregator.AttributeAggregatorExecutor) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Example 2 with StreamEventCloner

use of io.siddhi.core.event.stream.StreamEventCloner in project siddhi by wso2.

the class TestStoreForCacheMiss method init.

@Override
protected void init(TableDefinition tableDefinition, ConfigReader configReader) {
    inMemoryTable = new InMemoryTable();
    MetaStreamEvent cacheTableMetaStreamEvent = new MetaStreamEvent();
    cacheTableMetaStreamEvent.addInputDefinition(tableDefinition);
    for (Attribute attribute : tableDefinition.getAttributeList()) {
        cacheTableMetaStreamEvent.addOutputData(attribute);
    }
    StreamEventCloner testTableStreamEventCloner = new StreamEventCloner(cacheTableMetaStreamEvent, storeEventPool);
    TableDefinition testStoreContainingIMTableDefinition = TableDefinition.id(tableDefinition.getId());
    for (Attribute attribute : tableDefinition.getAttributeList()) {
        testStoreContainingIMTableDefinition.attribute(attribute.getName(), attribute.getType());
    }
    for (Annotation annotation : tableDefinition.getAnnotations()) {
        if (!annotation.getName().equalsIgnoreCase("Store")) {
            testStoreContainingIMTableDefinition.annotation(annotation);
        }
    }
    inMemoryTable.init(testStoreContainingIMTableDefinition, storeEventPool, testTableStreamEventCloner, configReader, siddhiAppContext, recordTableHandler);
}
Also used : InMemoryTable(io.siddhi.core.table.InMemoryTable) Attribute(io.siddhi.query.api.definition.Attribute) StreamEventCloner(io.siddhi.core.event.stream.StreamEventCloner) TableDefinition(io.siddhi.query.api.definition.TableDefinition) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) Annotation(io.siddhi.query.api.annotation.Annotation)

Example 3 with StreamEventCloner

use of io.siddhi.core.event.stream.StreamEventCloner in project siddhi by wso2.

the class TestStoreForCachePreLoading method init.

@Override
protected void init(TableDefinition tableDefinition, ConfigReader configReader) {
    inMemoryTable = new InMemoryTable();
    MetaStreamEvent cacheTableMetaStreamEvent = new MetaStreamEvent();
    cacheTableMetaStreamEvent.addInputDefinition(tableDefinition);
    for (Attribute attribute : tableDefinition.getAttributeList()) {
        cacheTableMetaStreamEvent.addOutputData(attribute);
    }
    StreamEventCloner testTableStreamEventCloner = new StreamEventCloner(cacheTableMetaStreamEvent, storeEventPool);
    TableDefinition testStoreContainingIMTableDefinition = TableDefinition.id(tableDefinition.getId());
    for (Attribute attribute : tableDefinition.getAttributeList()) {
        testStoreContainingIMTableDefinition.attribute(attribute.getName(), attribute.getType());
    }
    for (Annotation annotation : tableDefinition.getAnnotations()) {
        if (!annotation.getName().equalsIgnoreCase("Store")) {
            testStoreContainingIMTableDefinition.annotation(annotation);
        }
    }
    inMemoryTable.init(testStoreContainingIMTableDefinition, storeEventPool, testTableStreamEventCloner, configReader, siddhiAppContext, recordTableHandler);
    ComplexEventChunk<StreamEvent> originalData = new ComplexEventChunk<>();
    StreamEvent data1 = new StreamEvent(0, 0, 3);
    data1.setOutputData(new Object[] { "WSO2", 55.6f, 100L });
    originalData.add(data1);
    StreamEvent data2 = new StreamEvent(0, 0, 3);
    data2.setOutputData(new Object[] { "IBM", 75.6f, 100L });
    originalData.add(data2);
    inMemoryTable.add(originalData);
}
Also used : InMemoryTable(io.siddhi.core.table.InMemoryTable) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) Attribute(io.siddhi.query.api.definition.Attribute) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) StreamEventCloner(io.siddhi.core.event.stream.StreamEventCloner) TableDefinition(io.siddhi.query.api.definition.TableDefinition) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) Annotation(io.siddhi.query.api.annotation.Annotation)

Example 4 with StreamEventCloner

use of io.siddhi.core.event.stream.StreamEventCloner in project siddhi by wso2.

the class Window method init.

/**
 * Initialize the WindowEvent table by creating {@link WindowProcessor} to handle the events.
 *
 * @param tableMap         map of {@link Table}s
 * @param eventWindowMap   map of EventWindows
 * @param windowName       name of the query window belongs to.
 * @param findToBeExecuted will find will be executed on the window.
 */
public void init(Map<String, Table> tableMap, Map<String, Window> eventWindowMap, String windowName, boolean findToBeExecuted) {
    if (this.windowProcessor != null) {
        return;
    }
    // Create and initialize MetaStreamEvent
    MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
    metaStreamEvent.addInputDefinition(windowDefinition);
    metaStreamEvent.setEventType(MetaStreamEvent.EventType.WINDOW);
    for (Attribute attribute : windowDefinition.getAttributeList()) {
        metaStreamEvent.addOutputData(attribute);
    }
    this.streamEventFactory = new StreamEventFactory(metaStreamEvent);
    StreamEventCloner streamEventCloner = new StreamEventCloner(metaStreamEvent, this.streamEventFactory);
    OutputStream.OutputEventType outputEventType = windowDefinition.getOutputEventType();
    boolean outputExpectsExpiredEvents = outputEventType != OutputStream.OutputEventType.CURRENT_EVENTS;
    SiddhiQueryContext siddhiQueryContext = new SiddhiQueryContext(siddhiAppContext, windowName);
    WindowProcessor internalWindowProcessor = (WindowProcessor) SingleInputStreamParser.generateProcessor(windowDefinition.getWindow(), metaStreamEvent, new ArrayList<VariableExpressionExecutor>(), tableMap, false, outputExpectsExpiredEvents, findToBeExecuted, siddhiQueryContext);
    internalWindowProcessor.setStreamEventCloner(streamEventCloner);
    internalWindowProcessor.constructStreamEventPopulater(metaStreamEvent, 0);
    EntryValveProcessor entryValveProcessor = null;
    if (internalWindowProcessor instanceof SchedulingProcessor) {
        entryValveProcessor = new EntryValveProcessor(this.siddhiAppContext);
        Scheduler scheduler = SchedulerParser.parse(entryValveProcessor, siddhiQueryContext);
        scheduler.init(this.lockWrapper, windowName);
        scheduler.setStreamEventFactory(streamEventFactory);
        ((SchedulingProcessor) internalWindowProcessor).setScheduler(scheduler);
    }
    if (entryValveProcessor != null) {
        entryValveProcessor.setToLast(internalWindowProcessor);
        this.windowProcessor = entryValveProcessor;
    } else {
        this.windowProcessor = internalWindowProcessor;
    }
    // StreamPublishProcessor must be the last in chain so that it can publish the events to StreamJunction
    this.windowProcessor.setToLast(new StreamPublishProcessor(outputEventType));
    this.internalWindowProcessor = internalWindowProcessor;
}
Also used : Attribute(io.siddhi.query.api.definition.Attribute) Scheduler(io.siddhi.core.util.Scheduler) StreamEventFactory(io.siddhi.core.event.stream.StreamEventFactory) OutputStream(io.siddhi.query.api.execution.query.output.stream.OutputStream) ArrayList(java.util.ArrayList) SchedulingProcessor(io.siddhi.core.query.processor.SchedulingProcessor) SiddhiQueryContext(io.siddhi.core.config.SiddhiQueryContext) StreamEventCloner(io.siddhi.core.event.stream.StreamEventCloner) EntryValveProcessor(io.siddhi.core.query.input.stream.single.EntryValveProcessor) WindowProcessor(io.siddhi.core.query.processor.stream.window.WindowProcessor) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Example 5 with StreamEventCloner

use of io.siddhi.core.event.stream.StreamEventCloner in project siddhi by wso2.

the class SnapshotableEventQueueTestCase method incrementalPersistenceTest3.

@Test
public void incrementalPersistenceTest3() throws InterruptedException, IOException, ClassNotFoundException {
    MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
    metaStreamEvent.addOutputData(new Attribute("symbol", Attribute.Type.STRING));
    metaStreamEvent.addOutputData(new Attribute("price", Attribute.Type.FLOAT));
    metaStreamEvent.addOutputData(new Attribute("volume", Attribute.Type.LONG));
    StreamEventCloner streamEventCloner = new StreamEventCloner(metaStreamEvent, new StreamEventFactory(metaStreamEvent));
    SnapshotableStreamEventQueue snapshotableStreamEventQueue = new SnapshotableStreamEventQueue(new StreamEventClonerHolder(streamEventCloner));
    StreamEvent streamEvent = new StreamEvent(metaStreamEvent.getBeforeWindowData().size(), metaStreamEvent.getOnAfterWindowData().size(), metaStreamEvent.getOutputData().size());
    streamEvent.setOutputData(new Object[] { "IBM", 500.6f, 1 });
    for (int i = 0; i < 10; i++) {
        streamEvent.getOutputData()[2] = i;
        snapshotableStreamEventQueue.add(streamEventCloner.copyStreamEvent(streamEvent));
    }
    HashMap<Long, String> snapshots = new HashMap<>();
    Snapshot snapshot1 = snapshotableStreamEventQueue.getSnapshot();
    StreamEvent streamEvents = (StreamEvent) snapshot1.getState();
    Assert.assertTrue(streamEvents != null);
    snapshots.put(3L, toString(snapshot1));
    snapshotableStreamEventQueue.next();
    snapshotableStreamEventQueue.next();
    snapshotableStreamEventQueue.next();
    for (int i = 7; i < 10; i++) {
        snapshotableStreamEventQueue.next();
        snapshotableStreamEventQueue.remove();
    }
    Snapshot snapshot2 = snapshotableStreamEventQueue.getSnapshot();
    ArrayList<Operation> operationLog = (ArrayList<Operation>) snapshot2.getState();
    Assert.assertTrue(operationLog != null);
    snapshots.put(4L, toString(snapshot2));
    for (int i = 10; i < 15; i++) {
        streamEvent.getOutputData()[2] = i;
        snapshotableStreamEventQueue.add(streamEventCloner.copyStreamEvent(streamEvent));
    }
    Snapshot snapshot3 = snapshotableStreamEventQueue.getSnapshot();
    operationLog = (ArrayList<Operation>) snapshot3.getState();
    Assert.assertTrue(operationLog != null);
    snapshots.put(5L, toString(snapshot3));
    SnapshotableStreamEventQueue snapshotableStreamEventQueue2 = new SnapshotableStreamEventQueue(new StreamEventClonerHolder(streamEventCloner));
    SnapshotStateList snapshotStateList = new SnapshotStateList();
    for (Map.Entry<Long, String> entry : snapshots.entrySet()) {
        snapshotStateList.putSnapshotState(entry.getKey(), (Snapshot) fromString(entry.getValue()));
    }
    snapshotableStreamEventQueue2.restore(snapshotStateList);
    Assert.assertEquals(snapshotableStreamEventQueue, snapshotableStreamEventQueue2);
}
Also used : Attribute(io.siddhi.query.api.definition.Attribute) HashMap(java.util.HashMap) StreamEventFactory(io.siddhi.core.event.stream.StreamEventFactory) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) ArrayList(java.util.ArrayList) Operation(io.siddhi.core.event.stream.Operation) StreamEventClonerHolder(io.siddhi.core.event.stream.holder.StreamEventClonerHolder) Snapshot(io.siddhi.core.util.snapshot.state.Snapshot) SnapshotStateList(io.siddhi.core.util.snapshot.state.SnapshotStateList) StreamEventCloner(io.siddhi.core.event.stream.StreamEventCloner) HashMap(java.util.HashMap) Map(java.util.Map) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) SnapshotableStreamEventQueue(io.siddhi.core.event.stream.holder.SnapshotableStreamEventQueue) Test(org.testng.annotations.Test)

Aggregations

MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)14 StreamEventCloner (io.siddhi.core.event.stream.StreamEventCloner)14 Attribute (io.siddhi.query.api.definition.Attribute)12 StreamEventFactory (io.siddhi.core.event.stream.StreamEventFactory)11 StreamEvent (io.siddhi.core.event.stream.StreamEvent)6 StreamEventClonerHolder (io.siddhi.core.event.stream.holder.StreamEventClonerHolder)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Operation (io.siddhi.core.event.stream.Operation)5 SnapshotableStreamEventQueue (io.siddhi.core.event.stream.holder.SnapshotableStreamEventQueue)5 Snapshot (io.siddhi.core.util.snapshot.state.Snapshot)5 SnapshotStateList (io.siddhi.core.util.snapshot.state.SnapshotStateList)5 Annotation (io.siddhi.query.api.annotation.Annotation)5 Test (org.testng.annotations.Test)5 InMemoryTable (io.siddhi.core.table.InMemoryTable)4 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)2 StateEventCloner (io.siddhi.core.event.state.StateEventCloner)2 SchedulingProcessor (io.siddhi.core.query.processor.SchedulingProcessor)2 TableDefinition (io.siddhi.query.api.definition.TableDefinition)2