Java Code Examples for io.siddhi.core.config.SiddhiAppContext#generateStateHolder()

The following examples show how to use io.siddhi.core.config.SiddhiAppContext#generateStateHolder() . 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: SinkHandler.java    From siddhi with Apache License 2.0 5 votes vote down vote up
final void initSinkHandler(String siddhiAppName, StreamDefinition streamDefinition,
                           SinkHandlerCallback sinkHandlerCallback,
                           SiddhiAppContext siddhiAppContext) {
    this.sinkHandlerCallback = sinkHandlerCallback;
    StateFactory<S> stateFactory = init(streamDefinition, sinkHandlerCallback);
    id = siddhiAppName + "-" + streamDefinition.getId() + "-" + this.getClass().getName();
    stateHolder = siddhiAppContext.generateStateHolder(
            streamDefinition.getId() + "-" + this.getClass().getName(),
            stateFactory);
}
 
Example 2
Source File: Source.java    From siddhi with Apache License 2.0 5 votes vote down vote up
public final void init(String sourceType, OptionHolder transportOptionHolder, SourceMapper sourceMapper,
                       String[] transportPropertyNames, ConfigReader configReader, String mapType,
                       OptionHolder mapOptionHolder, List<AttributeMapping> attributeMappings,
                       List<AttributeMapping> transportMappings, ConfigReader mapperConfigReader,
                       SourceHandler sourceHandler, StreamDefinition streamDefinition,
                       Map<String, String> deploymentProperties, SiddhiAppContext siddhiAppContext) {
    this.type = sourceType;

    sourceMapper.init(streamDefinition, mapType, mapOptionHolder, attributeMappings, sourceType,
            (this instanceof SourceSyncCallback) ? (SourceSyncCallback) this : null, transportMappings,
            sourceHandler, transportOptionHolder, mapperConfigReader, siddhiAppContext);
    this.mapper = sourceMapper;
    this.streamDefinition = streamDefinition;
    this.siddhiAppContext = siddhiAppContext;
    StateFactory<S> stateFactory = init(sourceMapper, transportOptionHolder, transportPropertyNames,
            configReader, siddhiAppContext);
    stateHolder = siddhiAppContext.generateStateHolder(streamDefinition.getId() + "-" +
            this.getClass().getName(), stateFactory);
    scheduledExecutorService = siddhiAppContext.getScheduledExecutorService();
    serviceDeploymentInfo = exposeServiceDeploymentInfo();
    if (serviceDeploymentInfo != null) {
        serviceDeploymentInfo.addDeploymentProperties(deploymentProperties);
    } else if (!deploymentProperties.isEmpty()) {
        throw new SiddhiAppCreationException("Deployment properties '" + deploymentProperties +
                "' are defined for source '" + sourceType + "' which does not expose a service");
    }
}
 
Example 3
Source File: SourceHandler.java    From siddhi with Apache License 2.0 5 votes vote down vote up
final void initSourceHandler(String siddhiAppName, SourceSyncCallback sourceSyncCallback,
                             StreamDefinition streamDefinition, SiddhiAppContext siddhiAppContext) {
    StateFactory<S> stateFactory = init(siddhiAppName, sourceSyncCallback, streamDefinition, siddhiAppContext);
    id = siddhiAppName + "-" + streamDefinition.getId() + "-" + this.getClass().getName();
    stateHolder = siddhiAppContext.generateStateHolder(
            streamDefinition.getId() + "-" + this.getClass().getName(),
            stateFactory);
}
 
Example 4
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 5
Source File: CacheTable.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, true);

    if (eventHolder instanceof IndexEventHolderForCache) {
        ((IndexEventHolderForCache) eventHolder).setCacheTable(this);
    }

    stateHolder = siddhiAppContext.generateStateHolder(tableDefinition.getId(),
            () -> new TableState(eventHolder));
}
 
Example 6
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 7
Source File: Sink.java    From siddhi with Apache License 2.0 4 votes vote down vote up
public final void init(StreamDefinition streamDefinition, String type, OptionHolder transportOptionHolder,
                       ConfigReader sinkConfigReader, SinkMapper sinkMapper, String mapType,
                       OptionHolder mapOptionHolder, SinkHandler sinkHandler, List<Element> payloadElementList,
                       ConfigReader mapperConfigReader, Map<String, String> deploymentProperties,
                       StreamJunction streamJunction, SiddhiAppContext siddhiAppContext) {
    this.streamDefinition = streamDefinition;
    this.type = type;
    this.streamJunction = streamJunction;
    this.siddhiAppContext = siddhiAppContext;
    this.onErrorAction = OnErrorAction.valueOf(transportOptionHolder
            .getOrCreateOption(SiddhiConstants.ANNOTATION_ELEMENT_ON_ERROR, "LOG")
            .getValue().toUpperCase());
    if (siddhiAppContext.getStatisticsManager() != null) {
        this.throughputTracker = QueryParserHelper.createThroughputTracker(siddhiAppContext,
                streamDefinition.getId(),
                SiddhiConstants.METRIC_INFIX_SINKS, type);
        this.mapperLatencyTracker = QueryParserHelper.createLatencyTracker(siddhiAppContext,
                streamDefinition.getId(),
                SiddhiConstants.METRIC_INFIX_SINK_MAPPERS,
                type + SiddhiConstants.METRIC_DELIMITER + mapType);
    }
    StateFactory<S> stateFactory = init(streamDefinition, transportOptionHolder, sinkConfigReader,
            siddhiAppContext);
    stateHolder = siddhiAppContext.generateStateHolder(streamDefinition.getId() + "-" +
            this.getClass().getName(), stateFactory);
    if (sinkMapper != null) {
        sinkMapper.init(streamDefinition, mapType, mapOptionHolder, payloadElementList, this,
                mapperConfigReader, mapperLatencyTracker, transportOptionHolder, siddhiAppContext);
        this.mapper = sinkMapper;
    }
    if (sinkHandler != null) {
        sinkHandler.initSinkHandler(siddhiAppContext.getName(), streamDefinition,
                new SinkHandlerCallback(sinkMapper), siddhiAppContext);
        this.handler = sinkHandler;
    }
    scheduledExecutorService = siddhiAppContext.getScheduledExecutorService();
    serviceDeploymentInfo = exposeServiceDeploymentInfo();
    if (serviceDeploymentInfo != null) {
        serviceDeploymentInfo.addDeploymentProperties(deploymentProperties);
    } else if (!deploymentProperties.isEmpty()) {
        throw new SiddhiAppCreationException("Deployment properties '" + deploymentProperties +
                "' are defined for sink '" + type + "' which does not expose a service");
    }
}
 
Example 8
Source File: PartitionRuntimeImpl.java    From siddhi with Apache License 2.0 4 votes vote down vote up
public PartitionRuntimeImpl(ConcurrentMap<String, AbstractDefinition> streamDefinitionMap,
                            ConcurrentMap<String, AbstractDefinition> windowDefinitionMap,
                            ConcurrentMap<String, StreamJunction> streamJunctionMap,
                            Partition partition, int partitionIndex, SiddhiAppContext siddhiAppContext) {
    this.siddhiAppContext = siddhiAppContext;
    if (partition.getPartitionTypeMap().isEmpty()) {
        throw new SiddhiAppCreationException("Partition must have at least one partition executor. " +
                "But found none.");
    }
    try {
        Element element = AnnotationHelper.getAnnotationElement("info", "name",
                partition.getAnnotations());
        if (element != null) {
            this.partitionName = element.getValue();
        }
    } catch (DuplicateAnnotationException e) {
        throw new DuplicateAnnotationException(e.getMessageWithOutContext() + " for the same Query " +
                partition.toString(), e, e.getQueryContextStartIndex(), e.getQueryContextEndIndex(),
                siddhiAppContext.getName(), siddhiAppContext.getSiddhiAppString());
    }
    if (partitionName == null) {
        this.partitionName = "partition_" + partitionIndex;
    }

    Annotation purge = AnnotationHelper.getAnnotation(SiddhiConstants.NAMESPACE_PURGE, partition.getAnnotations());
    if (purge != null) {
        if (purge.getElement(SiddhiConstants.ANNOTATION_ELEMENT_ENABLE) != null) {
            String purgeEnable = purge.getElement(SiddhiConstants.ANNOTATION_ELEMENT_ENABLE);
            if (!("true".equalsIgnoreCase(purgeEnable) || "false".equalsIgnoreCase(purgeEnable))) {
                throw new SiddhiAppCreationException("Invalid value for enable: " + purgeEnable + "." +
                        " Please use 'true' or 'false'");
            } else {
                purgingEnabled = Boolean.parseBoolean(purgeEnable);
            }
        } else {
            throw new SiddhiAppCreationException("Annotation @" + SiddhiConstants.NAMESPACE_PURGE +
                    " is missing element '" + SiddhiConstants.ANNOTATION_ELEMENT_ENABLE + "'");
        }
        if (purge.getElement(SiddhiConstants.ANNOTATION_ELEMENT_IDLE_PERIOD) != null) {
            String purgeIdle = purge.getElement(SiddhiConstants.ANNOTATION_ELEMENT_IDLE_PERIOD);
            purgeIdlePeriod = Expression.Time.timeToLong(purgeIdle);

        } else {
            throw new SiddhiAppCreationException("Annotation @" + SiddhiConstants.NAMESPACE_PURGE +
                    " is missing element '" + SiddhiConstants.ANNOTATION_ELEMENT_IDLE_PERIOD + "'");
        }

        if (purge.getElement(SiddhiConstants.ANNOTATION_ELEMENT_INTERVAL) != null) {
            String interval = purge.getElement(SiddhiConstants.ANNOTATION_ELEMENT_INTERVAL);
            purgeExecutionInterval = Expression.Time.timeToLong(interval);
        }
    }
    this.partition = partition;
    this.streamDefinitionMap = streamDefinitionMap;
    this.windowDefinitionMap = windowDefinitionMap;
    this.streamJunctionMap = streamJunctionMap;

    this.stateHolder = siddhiAppContext.generateStateHolder(partitionName, () -> new PartitionState());
}