io.siddhi.core.config.SiddhiAppContext Java Examples

The following examples show how to use io.siddhi.core.config.SiddhiAppContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ObjectSizeCalculator.java    From siddhi with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an object size calculator that can calculate object sizes for a given
 * {@code memoryLayoutSpecification}.
 *
 * @param memoryLayoutSpecification a description of the JVM memory layout.
 */
public ObjectSizeCalculator(MemoryLayoutSpecification memoryLayoutSpecification) {
    Preconditions.checkNotNull(memoryLayoutSpecification);
    arrayHeaderSize = memoryLayoutSpecification.getArrayHeaderSize();
    objectHeaderSize = memoryLayoutSpecification.getObjectHeaderSize();
    objectPadding = memoryLayoutSpecification.getObjectPadding();
    referenceSize = memoryLayoutSpecification.getReferenceSize();
    superclassFieldPadding = memoryLayoutSpecification.getSuperclassFieldPadding();
    ignoreCalculation.add(SiddhiAppContext.class);
    ignoreCalculation.add(StreamJunction.class);
    ignoreCalculation.add(OutputCallback.class);
    ignoreCalculation.add(StreamCallback.class);
    ignoreCalculation.add(ThroughputTracker.class);
    ignoreCalculation.add(LatencyTracker.class);
    ignoreCalculation.add(MemoryUsageTracker.class);
    ignoreCalculation.add(BufferedEventsTracker.class);
    ignoreCalculation.add(StatisticsManager.class);
    ignoreCalculation.add(MemoryCalculable.class);
    ignoreCalculation.add(AbstractRecordTable.class);
}
 
Example #2
Source File: InsertIntoStreamEndPartitionCallback.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Override
public void send(ComplexEventChunk complexEventChunk, int noOfEvents) {
    if (getSiddhiDebugger() != null) {
        getSiddhiDebugger()
                .checkBreakPoint(getQueryName(), SiddhiDebugger.QueryTerminal.OUT, complexEventChunk.getFirst());
    }
    complexEventChunk.reset();
    if (complexEventChunk.getFirst() != null) {
        String flowId = SiddhiAppContext.getPartitionFlowId();
        SiddhiAppContext.stopPartitionFlow();
        try {
            while (complexEventChunk.hasNext()) {
                ComplexEvent complexEvent = complexEventChunk.next();
                if (complexEvent.getType() == ComplexEvent.Type.EXPIRED) {
                    complexEvent.setType(ComplexEvent.Type.CURRENT);
                }
            }
            publisher.send(complexEventChunk.getFirst());
        } finally {
            SiddhiAppContext.startPartitionFlow(flowId);
        }
    }
}
 
Example #3
Source File: IncrementalExecutorsInitialiser.java    From siddhi with Apache License 2.0 6 votes vote down vote up
public IncrementalExecutorsInitialiser(List<TimePeriod.Duration> incrementalDurations,
                                       Map<TimePeriod.Duration, Table> aggregationTables,
                                       Map<TimePeriod.Duration, IncrementalExecutor> incrementalExecutorMap,
                                       boolean isDistributed, String shardId, SiddhiAppContext siddhiAppContext,
                                       MetaStreamEvent metaStreamEvent, Map<String, Table> tableMap,
                                       Map<String, Window> windowMap,
                                       Map<String, AggregationRuntime> aggregationMap, String timeZone) {
    this.timeZone = timeZone;
    this.incrementalDurations = incrementalDurations;
    this.aggregationTables = aggregationTables;
    this.incrementalExecutorMap = incrementalExecutorMap;

    this.isDistributed = isDistributed;
    this.shardId = shardId;

    this.streamEventFactory = new StreamEventFactory(metaStreamEvent);

    this.siddhiAppContext = siddhiAppContext;
    this.tableMap = tableMap;
    this.windowMap = windowMap;
    this.aggregationMap = aggregationMap;

    this.isInitialised = false;
}
 
Example #4
Source File: AbstractExtensionHolder.java    From siddhi with Apache License 2.0 6 votes vote down vote up
protected AbstractExtensionHolder(Class clazz, SiddhiAppContext siddhiAppContext) {
    Map<String, Class> extensions = siddhiAppContext.getSiddhiContext().getSiddhiExtensions();
    if (extensions != null) {
        for (String extensionKey : siddhiAppContext.getSiddhiContext().getSiddhiExtensions().keySet()) {
            Class extension = extensions.get(extensionKey);
            if (clazz.isAssignableFrom(extension)) {
                if (extensionMap.containsKey(extensionKey)) {
                    log.error("Extension class " + extension.getName() + " not loaded, as there is already an" +
                            " matching extension '" + extensionKey + "' implemented as " + extensionMap
                            .get
                                    (extensionKey).getName());
                } else {
                    extensionMap.put(extensionKey, extension);
                }

            }

        }
    }
}
 
Example #5
Source File: ByteSerializer.java    From siddhi with Apache License 2.0 6 votes vote down vote up
public static byte[] objectToByte(Object obj, SiddhiAppContext siddhiAppContext) {
    long start = System.currentTimeMillis();
    byte[] out = null;
    if (obj != null) {
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(baos);
            oos.writeObject(obj);
            out = baos.toByteArray();
        } catch (IOException e) {
            log.error(ExceptionUtil.getMessageWithContext(e, siddhiAppContext) +
                    " Error when writing byte array.", e);
            return null;
        }
    }
    long end = System.currentTimeMillis();
    if (log.isDebugEnabled()) {
        log.debug("For SiddhiApp '" + siddhiAppContext.getName() + "'. Encoded in :" + (end - start) + " msec");
    }
    return out;
}
 
Example #6
Source File: CacheTableLRU.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Override
protected StreamEvent addRequiredFields(ComplexEvent event, SiddhiAppContext siddhiAppContext,
                                        boolean cacheExpiryEnabled) {
    Object[] outputDataForCache;
    Object[] outputData = event.getOutputData();
    if (cacheExpiryEnabled) {
        outputDataForCache = new Object[numColumns];
        outputDataForCache[expiryAttributePosition] = outputDataForCache[cachePolicyAttributePosition] =
                siddhiAppContext.getTimestampGenerator().currentTime();
    } else {
        outputDataForCache = new Object[numColumns];
        outputDataForCache[cachePolicyAttributePosition] =
                siddhiAppContext.getTimestampGenerator().currentTime();
    }
    System.arraycopy(outputData, 0, outputDataForCache, 0, outputData.length);
    StreamEvent eventForCache = new StreamEvent(0, 0, outputDataForCache.length);
    eventForCache.setOutputData(outputDataForCache);
    return eventForCache;
}
 
Example #7
Source File: Scheduler.java    From siddhi with Apache License 2.0 6 votes vote down vote up
/**
 * Schedule events which are not scheduled in the queue when switching back from event time to system current time
 */
public void switchToLiveMode() {
    Map<String, Map<String, SchedulerState>> allStates = stateHolder.getAllStates();
    try {
        for (Map.Entry<String, Map<String, SchedulerState>> allStatesEntry : allStates.entrySet()) {
            for (Map.Entry<String, SchedulerState> stateEntry : allStatesEntry.getValue().entrySet()) {
                Long toNotifyTime = stateEntry.getValue().toNotifyQueue.peek();
                if (toNotifyTime != null) {
                    SiddhiAppContext.startPartitionFlow(allStatesEntry.getKey());
                    SiddhiAppContext.startGroupByFlow(stateEntry.getKey());
                    try {
                        schedule(toNotifyTime, stateEntry.getValue(), true);
                    } finally {
                        SiddhiAppContext.stopGroupByFlow();
                        SiddhiAppContext.stopPartitionFlow();
                    }
                }
            }
        }
    } finally {
        stateHolder.returnAllStates(allStates);
    }
}
 
Example #8
Source File: CacheTableLFU.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Override
protected StreamEvent addRequiredFields(ComplexEvent event, SiddhiAppContext siddhiAppContext,
                                        boolean cacheExpiryEnabled) {
    Object[] outputDataForCache;
    Object[] outputData = event.getOutputData();
    if (cacheExpiryEnabled) {
        outputDataForCache = new Object[numColumns];
        outputDataForCache[expiryAttributePosition] =
                siddhiAppContext.getTimestampGenerator().currentTime();
        outputDataForCache[cachePolicyAttributePosition] = 1;
    } else {
        outputDataForCache = new Object[numColumns];
        outputDataForCache[cachePolicyAttributePosition] = 1;
    }
    System.arraycopy(outputData, 0, outputDataForCache, 0, outputData.length);
    StreamEvent eventForCache = new StreamEvent(0, 0, outputDataForCache.length);
    eventForCache.setOutputData(outputDataForCache);
    return eventForCache;
}
 
Example #9
Source File: QueryParserHelper.java    From siddhi with Apache License 2.0 6 votes vote down vote up
public static void registerMemoryUsageTracking(String name, Object value, String metricInfixQueries,
                                               SiddhiAppContext siddhiAppContext,
                                               MemoryUsageTracker memoryUsageTracker) {
    String metricName = siddhiAppContext.getSiddhiContext().getStatisticsConfiguration().getMetricPrefix() +
            SiddhiConstants.METRIC_DELIMITER + SiddhiConstants.METRIC_INFIX_SIDDHI_APPS +
            SiddhiConstants.METRIC_DELIMITER + siddhiAppContext.getName() + SiddhiConstants.METRIC_DELIMITER +
            SiddhiConstants.METRIC_INFIX_SIDDHI + SiddhiConstants.METRIC_DELIMITER +
            metricInfixQueries + SiddhiConstants.METRIC_DELIMITER +
            name + SiddhiConstants.METRIC_DELIMITER + "memory";
    boolean matchExist = false;
    for (String regex : siddhiAppContext.getIncludedMetrics()) {
        if (metricName.matches(regex)) {
            matchExist = true;
            break;
        }
    }
    if (matchExist) {
        memoryUsageTracker.registerObject(value, metricName);
    }
}
 
Example #10
Source File: JsonSinkMapper.java    From siddhi-map-json with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize the mapper and the mapping configurations.
 *
 * @param streamDefinition          The stream definition
 * @param optionHolder              Option holder containing static and dynamic options
 * @param payloadTemplateBuilderMap Unmapped list of payloads for reference
 */
@Override
public void init(StreamDefinition streamDefinition, OptionHolder optionHolder,
                 Map<String, TemplateBuilder> payloadTemplateBuilderMap, ConfigReader mapperConfigReader,
                 SiddhiAppContext siddhiAppContext) {

    this.attributeNameArray = streamDefinition.getAttributeNameArray();
    this.enclosingElement = optionHolder.validateAndGetStaticValue(ENCLOSING_ELEMENT_IDENTIFIER, null);
    this.isJsonValidationEnabled = Boolean.parseBoolean(optionHolder
            .validateAndGetStaticValue(JSON_VALIDATION_IDENTIFIER, "false"));

    //if @payload() is added there must be at least 1 element in it, otherwise a SiddhiParserException raised
    if (payloadTemplateBuilderMap != null && payloadTemplateBuilderMap.size() != 1) {
        throw new SiddhiAppCreationException("Json sink-mapper does not support multiple @payload mappings, " +
                "error at the mapper of '" + streamDefinition.getId() + "'");
    }
    if (payloadTemplateBuilderMap != null &&
            payloadTemplateBuilderMap.get(payloadTemplateBuilderMap.keySet().iterator().next()).isObjectMessage()) {
        throw new SiddhiAppCreationException("Json sink-mapper does not support object @payload mappings, " +
                "error at the mapper of '" + streamDefinition.getId() + "'");
    }
}
 
Example #11
Source File: SourceExecutorExtensionHolder.java    From siddhi with Apache License 2.0 5 votes vote down vote up
public static SourceExecutorExtensionHolder getInstance(SiddhiAppContext siddhiAppContext) {
    ConcurrentHashMap<Class, AbstractExtensionHolder> extensionHolderMap = siddhiAppContext.getSiddhiContext
            ().getExtensionHolderMap();
    AbstractExtensionHolder abstractExtensionHolder = extensionHolderMap.get(clazz);
    if (abstractExtensionHolder == null) {
        abstractExtensionHolder = new SourceExecutorExtensionHolder(siddhiAppContext);
        extensionHolderMap.putIfAbsent(clazz, abstractExtensionHolder);
    }
    return (SourceExecutorExtensionHolder) extensionHolderMap.get(clazz);
}
 
Example #12
Source File: IncrementalAttributeAggregatorExtensionHolder.java    From siddhi with Apache License 2.0 5 votes vote down vote up
public static IncrementalAttributeAggregatorExtensionHolder getInstance(SiddhiAppContext siddhiAppContext) {
    ConcurrentHashMap<Class, AbstractExtensionHolder> extensionHolderMap = siddhiAppContext.getSiddhiContext()
            .getExtensionHolderMap();
    AbstractExtensionHolder abstractExtensionHolder = extensionHolderMap.get(clazz);
    if (abstractExtensionHolder == null) {
        abstractExtensionHolder = new IncrementalAttributeAggregatorExtensionHolder(siddhiAppContext);
        extensionHolderMap.putIfAbsent(clazz, abstractExtensionHolder);
    }
    return (IncrementalAttributeAggregatorExtensionHolder) extensionHolderMap.get(clazz);
}
 
Example #13
Source File: Table.java    From siddhi with Apache License 2.0 5 votes vote down vote up
public void initTable(TableDefinition tableDefinition, StreamEventFactory storeEventPool,
                      StreamEventCloner storeEventCloner,
                      ConfigReader configReader, SiddhiAppContext siddhiAppContext,
                      RecordTableHandler recordTableHandler) {
    this.tableDefinition = tableDefinition;
    this.scheduledExecutorService = siddhiAppContext.getScheduledExecutorService();
    this.siddhiAppContext = siddhiAppContext;
    this.recordTableHandler = recordTableHandler;
    if (siddhiAppContext.getStatisticsManager() != null) {
        latencyTrackerFind = QueryParserHelper.createLatencyTracker(siddhiAppContext, tableDefinition.getId(),
                SiddhiConstants.METRIC_INFIX_TABLES, SiddhiConstants.METRIC_TYPE_FIND);
        latencyTrackerInsert = QueryParserHelper.createLatencyTracker(siddhiAppContext, tableDefinition.getId(),
                SiddhiConstants.METRIC_INFIX_TABLES, SiddhiConstants.METRIC_TYPE_INSERT);
        latencyTrackerUpdate = QueryParserHelper.createLatencyTracker(siddhiAppContext, tableDefinition.getId(),
                SiddhiConstants.METRIC_INFIX_TABLES, SiddhiConstants.METRIC_TYPE_UPDATE);
        latencyTrackerDelete = QueryParserHelper.createLatencyTracker(siddhiAppContext, tableDefinition.getId(),
                SiddhiConstants.METRIC_INFIX_TABLES, SiddhiConstants.METRIC_TYPE_DELETE);
        latencyTrackerUpdateOrInsert = QueryParserHelper.createLatencyTracker(siddhiAppContext,
                tableDefinition.getId(), SiddhiConstants.METRIC_INFIX_TABLES,
                SiddhiConstants.METRIC_TYPE_UPDATE_OR_INSERT);
        latencyTrackerContains = QueryParserHelper.createLatencyTracker(siddhiAppContext, tableDefinition.getId(),
                SiddhiConstants.METRIC_INFIX_TABLES, SiddhiConstants.METRIC_TYPE_CONTAINS);

        throughputTrackerFind = QueryParserHelper.createThroughputTracker(siddhiAppContext, tableDefinition.getId(),
                SiddhiConstants.METRIC_INFIX_TABLES, SiddhiConstants.METRIC_TYPE_FIND);
        throughputTrackerInsert = QueryParserHelper.createThroughputTracker(siddhiAppContext,
                tableDefinition.getId(), SiddhiConstants.METRIC_INFIX_TABLES, SiddhiConstants.METRIC_TYPE_INSERT);
        throughputTrackerUpdate = QueryParserHelper.createThroughputTracker(siddhiAppContext,
                tableDefinition.getId(), SiddhiConstants.METRIC_INFIX_TABLES, SiddhiConstants.METRIC_TYPE_UPDATE);
        throughputTrackerDelete = QueryParserHelper.createThroughputTracker(siddhiAppContext,
                tableDefinition.getId(), SiddhiConstants.METRIC_INFIX_TABLES, SiddhiConstants.METRIC_TYPE_DELETE);
        throughputTrackerUpdateOrInsert = QueryParserHelper.createThroughputTracker(siddhiAppContext,
                tableDefinition.getId(), SiddhiConstants.METRIC_INFIX_TABLES,
                SiddhiConstants.METRIC_TYPE_UPDATE_OR_INSERT);
        throughputTrackerContains = QueryParserHelper.createThroughputTracker(siddhiAppContext,
                tableDefinition.getId(), SiddhiConstants.METRIC_INFIX_TABLES, SiddhiConstants.METRIC_TYPE_CONTAINS);

    }
    init(tableDefinition, storeEventPool, storeEventCloner, configReader, siddhiAppContext, recordTableHandler);
}
 
Example #14
Source File: SinkMapperExecutorExtensionHolder.java    From siddhi with Apache License 2.0 5 votes vote down vote up
public static SinkMapperExecutorExtensionHolder getInstance(SiddhiAppContext siddhiAppContext) {
    ConcurrentHashMap<Class, AbstractExtensionHolder> extensionHolderMap = siddhiAppContext.getSiddhiContext()
            .getExtensionHolderMap();
    AbstractExtensionHolder abstractExtensionHolder = extensionHolderMap.get(clazz);
    if (abstractExtensionHolder == null) {
        abstractExtensionHolder = new SinkMapperExecutorExtensionHolder(siddhiAppContext);
        extensionHolderMap.putIfAbsent(clazz, abstractExtensionHolder);
    }
    return (SinkMapperExecutorExtensionHolder) extensionHolderMap.get(clazz);
}
 
Example #15
Source File: CronTrigger.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Override
public void init(TriggerDefinition triggerDefinition, SiddhiAppContext siddhiAppContext,
                 StreamJunction streamJunction) {
    this.triggerDefinition = triggerDefinition;
    this.siddhiAppContext = siddhiAppContext;
    this.streamJunction = streamJunction;
    if (siddhiAppContext.getStatisticsManager() != null) {
        this.throughputTracker = QueryParserHelper.createThroughputTracker(siddhiAppContext,
                triggerDefinition.getId(),
                SiddhiConstants.METRIC_INFIX_TRIGGERS, null);
    }
}
 
Example #16
Source File: CacheTableFIFO.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Override
protected StreamEvent addRequiredFields(ComplexEvent event, SiddhiAppContext siddhiAppContext,
                                        boolean cacheExpiryEnabled) {
    Object[] outputDataForCache;
    Object[] outputData = event.getOutputData();
    outputDataForCache = new Object[numColumns];
    outputDataForCache[cachePolicyAttributePosition] = siddhiAppContext.getTimestampGenerator().currentTime();
    System.arraycopy(outputData, 0, outputDataForCache, 0, outputData.length);
    StreamEvent eventForCache = new StreamEvent(0, 0, outputDataForCache.length);
    eventForCache.setOutputData(outputDataForCache);
    return eventForCache;
}
 
Example #17
Source File: InMemoryTable.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Override
public void init(TableDefinition tableDefinition, StreamEventFactory storeEventPool,
                 StreamEventCloner storeEventCloner, ConfigReader configReader, SiddhiAppContext siddhiAppContext,
                 RecordTableHandler recordTableHandler) {
    this.tableDefinition = tableDefinition;
    this.tableStreamEventCloner = storeEventCloner;
    EventHolder eventHolder = EventHolderPasser.parse(tableDefinition, storeEventPool, siddhiAppContext, false);

    stateHolder = siddhiAppContext.generateStateHolder(tableDefinition.getId(),
            () -> new TableState(eventHolder));
}
 
Example #18
Source File: TestAsyncInMemory.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Override
protected StateFactory<State> init(StreamDefinition outputStreamDefinition, OptionHolder optionHolder,
                                   ConfigReader sinkConfigReader, SiddhiAppContext siddhiAppContext) {
    this.siddhiAppContext = siddhiAppContext;
    optionHolder.validateAndGetOption(TOPIC_KEY);
    super.init(outputStreamDefinition, optionHolder, sinkConfigReader, siddhiAppContext);
    return null;
}
 
Example #19
Source File: RecordTableHandler.java    From siddhi with Apache License 2.0 5 votes vote down vote up
protected final void init(TableDefinition tableDefinition, RecordTableHandlerCallback recordTableHandlerCallback,
                          SiddhiAppContext siddhiAppContext) {
    this.recordTableHandlerCallback = recordTableHandlerCallback;

    id = siddhiAppContext.getName() + "-" + tableDefinition.getId() + "-" + this.getClass().getName();
    StateFactory<S> stateFactory = init(id, tableDefinition);
    stateHolder = siddhiAppContext.generateStateHolder(
            tableDefinition.getId() + "-" + this.getClass().getName(),
            stateFactory);

}
 
Example #20
Source File: EventTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueryParser() {
    StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type
            .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
    StreamDefinition outStreamDefinition = StreamDefinition.id("outputStream").attribute("symbol", Attribute.Type
            .STRING).attribute("price", Attribute.Type.FLOAT);
    Query query = new Query();
    query.annotation(Annotation.annotation("info").element("name", "query1"));
    query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("volume"),
            Compare.Operator.NOT_EQUAL, Expression.value(50))));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression
            .variable("price")));
    query.insertInto("outputStream");
    Map<String, AbstractDefinition> tableDefinitionMap = new HashMap<>();
    Map<String, AbstractDefinition> windowDefinitionMap = new HashMap<>();
    Map<String, AbstractDefinition> aggregationDefinitionMap = new HashMap<>();
    Map<String, Table> tableMap = new HashMap<String, Table>();
    Map<String, Window> eventWindowMap = new HashMap<String, Window>();
    Map<String, AggregationRuntime> aggregationMap = new HashMap<String, AggregationRuntime>();
    Map<String, List<Source>> eventSourceMap = new HashMap<String, List<Source>>();
    Map<String, List<Sink>> eventSinkMap = new HashMap<String, List<Sink>>();
    Map<String, AbstractDefinition> streamDefinitionMap = new HashMap<String, AbstractDefinition>();
    LockSynchronizer lockSynchronizer = new LockSynchronizer();
    streamDefinitionMap.put("cseEventStream", streamDefinition);
    streamDefinitionMap.put("outputStream", outStreamDefinition);
    SiddhiContext siddhicontext = new SiddhiContext();
    SiddhiAppContext context = new SiddhiAppContext();
    context.setSiddhiContext(siddhicontext);
    context.setIdGenerator(new IdGenerator());
    context.setSnapshotService(new SnapshotService(context));
    QueryRuntimeImpl runtime = QueryParser.parse(query, context, streamDefinitionMap, tableDefinitionMap,
            windowDefinitionMap, aggregationDefinitionMap, tableMap, aggregationMap, eventWindowMap,
            lockSynchronizer, "1", false, SiddhiConstants.PARTITION_ID_DEFAULT);
    AssertJUnit.assertNotNull(runtime);
    AssertJUnit.assertTrue(runtime.getStreamRuntime() instanceof SingleStreamRuntime);
    AssertJUnit.assertNotNull(runtime.getSelector());
    AssertJUnit.assertTrue(runtime.getMetaComplexEvent() instanceof MetaStreamEvent);
}
 
Example #21
Source File: PartitionStreamReceiver.java    From siddhi with Apache License 2.0 5 votes vote down vote up
public PartitionStreamReceiver(SiddhiAppContext siddhiAppContext, MetaStreamEvent metaStreamEvent,
                               StreamDefinition streamDefinition,
                               List<PartitionExecutor> partitionExecutors,
                               PartitionRuntime partitionRuntime) {
    this.metaStreamEvent = metaStreamEvent;
    this.streamDefinition = streamDefinition;
    this.partitionRuntime = (PartitionRuntimeImpl) partitionRuntime;
    this.partitionExecutors = partitionExecutors;
    this.siddhiAppContext = siddhiAppContext;
    this.streamId = streamDefinition.getId();
    this.streamEventFactory = new StreamEventFactory(metaStreamEvent);

}
 
Example #22
Source File: SiddhiAppCreationException.java    From siddhi with Apache License 2.0 5 votes vote down vote up
public SiddhiAppCreationException(String message, Throwable throwable, int[] queryContextStartIndex,
                                  int[] queryContextEndIndex, SiddhiAppContext siddhiAppContext) {
    super(message, throwable);
    this.message = message;
    if (siddhiAppContext != null) {
        setQueryContextIndexIfAbsent(queryContextStartIndex, queryContextEndIndex, siddhiAppContext.getName(),
                siddhiAppContext.getSiddhiAppString());
    } else {
        setQueryContextIndexIfAbsent(queryContextStartIndex, queryContextEndIndex, null, null);
    }
}
 
Example #23
Source File: TestTrpSourceMapper.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Override
public void init(StreamDefinition streamDefinition, OptionHolder optionHolder,
                 List<AttributeMapping> attributeMappingList, ConfigReader configReader,
                 SiddhiAppContext siddhiAppContext) {
    this.streamDefinition = streamDefinition;
    this.optionHolder = optionHolder;
    this.attributeMappingList = attributeMappingList;
    this.configReader = configReader;
    this.siddhiAppContext = siddhiAppContext;
}
 
Example #24
Source File: IncrementalAggregationProcessor.java    From siddhi with Apache License 2.0 5 votes vote down vote up
public IncrementalAggregationProcessor(AggregationRuntime aggregationRuntime,
                                       List<ExpressionExecutor> incomingExpressionExecutors,
                                       MetaStreamEvent processedMetaStreamEvent,
                                       LatencyTracker latencyTrackerInsert,
                                       ThroughputTracker throughputTrackerInsert,
                                       SiddhiAppContext siddhiAppContext) {
    this.isFirstEventArrived = false;
    this.aggregationRuntime = aggregationRuntime;
    this.incomingExpressionExecutors = incomingExpressionExecutors;
    this.streamEventFactory = new StreamEventFactory(processedMetaStreamEvent);
    this.latencyTrackerInsert = latencyTrackerInsert;
    this.throughputTrackerInsert = throughputTrackerInsert;
    this.siddhiAppContext = siddhiAppContext;
}
 
Example #25
Source File: PeriodicTrigger.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Override
public void init(TriggerDefinition triggerDefinition, SiddhiAppContext siddhiAppContext, StreamJunction
        streamJunction) {
    this.triggerDefinition = triggerDefinition;
    this.siddhiAppContext = siddhiAppContext;
    this.streamJunction = streamJunction;
    if (siddhiAppContext.getStatisticsManager() != null) {
        this.throughputTracker = QueryParserHelper.createThroughputTracker(siddhiAppContext,
                triggerDefinition.getId(),
                SiddhiConstants.METRIC_INFIX_TRIGGERS, null);
    }
}
 
Example #26
Source File: BaseIncrementalValueStore.java    From siddhi with Apache License 2.0 5 votes vote down vote up
public synchronized void process(Map<String, StreamEvent> groupedByEvents) {
    for (Map.Entry<String, StreamEvent> eventEntry : groupedByEvents.entrySet()) {
        synchronized (this) {
            SiddhiAppContext.startGroupByFlow(eventEntry.getKey() + "-" +
                    eventEntry.getValue().getTimestamp());
            ValueState state = valueStateHolder.getState();
            try {
                boolean shouldUpdate = true;
                if (shouldUpdateTimestamp != null) {
                    shouldUpdate = shouldUpdate(shouldUpdateTimestamp.execute(eventEntry.getValue()), state);
                }
                for (int i = 0; i < expressionExecutors.size(); i++) { // keeping timestamp value location as null
                    ExpressionExecutor expressionExecutor = expressionExecutors.get(i);
                    if (shouldUpdate) {
                        state.setValue(expressionExecutor.execute(eventEntry.getValue()), i + 1);
                    } else if (!(expressionExecutor instanceof VariableExpressionExecutor)) {
                        state.setValue(expressionExecutor.execute(eventEntry.getValue()), i + 1);
                    }
                }
                setProcessed(true);
            } finally {
                valueStateHolder.returnState(state);
                SiddhiAppContext.stopGroupByFlow();
            }
        }
    }
}
 
Example #27
Source File: IncrementalExecutor.java    From siddhi with Apache License 2.0 5 votes vote down vote up
private void processAggregates(StreamEvent streamEvent, ExecutorState executorState) {
    synchronized (this) {
        if (groupByKeyGenerator != null) {
            try {
                String groupedByKey = groupByKeyGenerator.constructEventKey(streamEvent);
                SiddhiAppContext.startGroupByFlow(groupedByKey);
                baseIncrementalValueStore.process(streamEvent);
            } finally {
                SiddhiAppContext.stopGroupByFlow();
            }
        } else {
            baseIncrementalValueStore.process(streamEvent);
        }
    }
}
 
Example #28
Source File: FunctionExecutorExtensionHolder.java    From siddhi with Apache License 2.0 5 votes vote down vote up
public static FunctionExecutorExtensionHolder getInstance(SiddhiAppContext siddhiAppContext) {
    ConcurrentHashMap<Class, AbstractExtensionHolder> extensionHolderMap = siddhiAppContext.getSiddhiContext
            ().getExtensionHolderMap();
    AbstractExtensionHolder abstractExtensionHolder = extensionHolderMap.get(clazz);
    if (abstractExtensionHolder == null) {
        abstractExtensionHolder = new FunctionExecutorExtensionHolder(siddhiAppContext);
        extensionHolderMap.putIfAbsent(clazz, abstractExtensionHolder);
    }
    return (FunctionExecutorExtensionHolder) extensionHolderMap.get(clazz);
}
 
Example #29
Source File: PartitionStateHolder.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Override
public State getState() {
    String partitionFlowId = SiddhiAppContext.getPartitionFlowId();
    String groupByFlowId = SiddhiAppContext.getGroupByFlowId();
    Map<String, State> partitionStates = states.computeIfAbsent(partitionFlowId, k -> new HashMap<>());
    return partitionStates.computeIfAbsent(groupByFlowId, s -> stateFactory.createNewState());
}
 
Example #30
Source File: PartitionStreamReceiver.java    From siddhi with Apache License 2.0 5 votes vote down vote up
private void send(ComplexEvent event) {
    for (String key : partitionRuntime.getPartitionKeys()) {
        SiddhiAppContext.startPartitionFlow(key);
        try {
            streamJunctionMap.get(streamId).sendEvent(event);
        } finally {
            SiddhiAppContext.stopPartitionFlow();
        }
    }
}