/* * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * * WSO2 Inc. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except * in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.wso2.siddhi.core.query.processor.stream.window; import org.wso2.siddhi.core.config.ExecutionPlanContext; import org.wso2.siddhi.core.event.ComplexEventChunk; import org.wso2.siddhi.core.event.state.StateEvent; import org.wso2.siddhi.core.event.stream.StreamEvent; import org.wso2.siddhi.core.event.stream.StreamEventCloner; import org.wso2.siddhi.core.exception.ExecutionPlanRuntimeException; import org.wso2.siddhi.core.executor.ExpressionExecutor; import org.wso2.siddhi.core.executor.VariableExpressionExecutor; import org.wso2.siddhi.core.query.processor.Processor; import org.wso2.siddhi.core.table.Table; import org.wso2.siddhi.core.util.collection.operator.CompiledCondition; import org.wso2.siddhi.core.util.collection.operator.MatchingMetaInfoHolder; import org.wso2.siddhi.core.util.config.ConfigReader; import org.wso2.siddhi.query.api.expression.Expression; import java.util.List; import java.util.Map; /** * Implementation of {@link WindowProcessor} which represent a Window operating based on {@link Table}. */ public class TableWindowProcessor extends WindowProcessor implements FindableProcessor { private Table table; private boolean outputExpectsExpiredEvents; private ConfigReader configReader; public TableWindowProcessor(Table table) { this.table = table; } @Override protected void init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, boolean outputExpectsExpiredEvents, ExecutionPlanContext executionPlanContext) { this.configReader = configReader; this.outputExpectsExpiredEvents = outputExpectsExpiredEvents; } @Override protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner) { // nothing to be done } @Override public StreamEvent find(StateEvent matchingEvent, CompiledCondition compiledCondition) { return table.find(matchingEvent, compiledCondition); } @Override public CompiledCondition compileCondition(Expression expression, MatchingMetaInfoHolder matchingMetaInfoHolder, ExecutionPlanContext executionPlanContext, List<VariableExpressionExecutor> variableExpressionExecutors, Map<String, Table> tableMap, String queryName) { return table.compileCondition(expression, matchingMetaInfoHolder, executionPlanContext, variableExpressionExecutors, tableMap, queryName); } @Override public void start() { //Do nothing } @Override public void stop() { //Do nothing } @Override public Processor cloneProcessor(String key) { try { TableWindowProcessor streamProcessor = new TableWindowProcessor(table); streamProcessor.inputDefinition = inputDefinition; ExpressionExecutor[] innerExpressionExecutors = new ExpressionExecutor[attributeExpressionLength]; ExpressionExecutor[] attributeExpressionExecutors1 = this.attributeExpressionExecutors; for (int i = 0; i < attributeExpressionLength; i++) { innerExpressionExecutors[i] = attributeExpressionExecutors1[i].cloneExecutor(key); } streamProcessor.attributeExpressionExecutors = innerExpressionExecutors; streamProcessor.attributeExpressionLength = attributeExpressionLength; streamProcessor.additionalAttributes = additionalAttributes; streamProcessor.complexEventPopulater = complexEventPopulater; streamProcessor.init(inputDefinition, attributeExpressionExecutors, configReader, executionPlanContext, outputExpectsExpiredEvents); streamProcessor.start(); return streamProcessor; } catch (Exception e) { throw new ExecutionPlanRuntimeException("Exception in cloning " + this.getClass().getCanonicalName(), e); } } @Override public Map<String, Object> currentState() { //No state return null; } @Override public void restoreState(Map<String, Object> state) { //Nothing to be done } }