use of org.wso2.siddhi.core.config.SiddhiAppContext in project siddhi by wso2.
the class MultiClientDistributedSink method initTransport.
@Override
public void initTransport(OptionHolder sinkOptionHolder, List<OptionHolder> destinationOptionHolders, Annotation sinkAnnotation, ConfigReader sinkConfigReader, SiddhiAppContext siddhiAppContext) {
String transportType = sinkOptionHolder.validateAndGetStaticValue(SiddhiConstants.ANNOTATION_ELEMENT_TYPE);
Extension sinkExtension = DefinitionParserHelper.constructExtension(streamDefinition, SiddhiConstants.ANNOTATION_SINK, transportType, sinkAnnotation, SiddhiConstants.NAMESPACE_SINK);
destinationOptionHolders.forEach(destinationOption -> {
Sink sink = (Sink) SiddhiClassLoader.loadExtensionImplementation(sinkExtension, SinkExecutorExtensionHolder.getInstance(siddhiAppContext));
destinationOption.merge(sinkOptionHolder);
sink.initOnlyTransport(streamDefinition, destinationOption, sinkConfigReader, siddhiAppContext);
transports.add(sink);
});
}
use of org.wso2.siddhi.core.config.SiddhiAppContext in project siddhi by wso2.
the class QueryRuntime method clone.
public QueryRuntime clone(String key, ConcurrentMap<String, StreamJunction> localStreamJunctionMap) {
LockWrapper lockWrapper = null;
if (synchronised) {
lockWrapper = new LockWrapper("");
lockWrapper.setLock(new ReentrantLock());
}
StreamRuntime clonedStreamRuntime = this.streamRuntime.clone(key);
QuerySelector clonedSelector = this.selector.clone(key);
OutputRateLimiter clonedOutputRateLimiter = outputRateLimiter.clone(key);
clonedOutputRateLimiter.init(siddhiAppContext, lockWrapper, queryId);
QueryRuntime queryRuntime = new QueryRuntime(query, siddhiAppContext, clonedStreamRuntime, clonedSelector, clonedOutputRateLimiter, outputCallback, this.metaComplexEvent, synchronised, this.queryId + key);
QueryParserHelper.initStreamRuntime(clonedStreamRuntime, metaComplexEvent, lockWrapper, queryId);
queryRuntime.setToLocalStream(toLocalStream);
if (!toLocalStream) {
queryRuntime.outputRateLimiter.setOutputCallback(outputCallback);
queryRuntime.outputCallback = this.outputCallback;
} else {
OutputCallback clonedQueryOutputCallback = OutputParser.constructOutputCallback(query.getOutputStream(), key, localStreamJunctionMap, outputStreamDefinition, siddhiAppContext, queryId);
queryRuntime.outputRateLimiter.setOutputCallback(clonedQueryOutputCallback);
queryRuntime.outputCallback = clonedQueryOutputCallback;
}
return queryRuntime;
}
use of org.wso2.siddhi.core.config.SiddhiAppContext in project siddhi by wso2.
the class PartitionRuntime method clonePartition.
private synchronized void clonePartition(String key) {
PartitionInstanceRuntime partitionInstance = this.partitionInstanceRuntimeMap.get(key);
if (partitionInstance == null) {
List<QueryRuntime> queryRuntimeList = new ArrayList<QueryRuntime>();
List<QueryRuntime> partitionedQueryRuntimeList = new ArrayList<QueryRuntime>();
for (QueryRuntime queryRuntime : metaQueryRuntimeMap.values()) {
QueryRuntime clonedQueryRuntime = queryRuntime.clone(key, localStreamJunctionMap);
queryRuntimeList.add(clonedQueryRuntime);
QueryParserHelper.registerMemoryUsageTracking(clonedQueryRuntime.getQueryId(), queryRuntime, SiddhiConstants.METRIC_INFIX_QUERIES, siddhiAppContext, memoryUsageTracker);
if (queryRuntime.isFromLocalStream()) {
for (int i = 0; i < clonedQueryRuntime.getStreamRuntime().getSingleStreamRuntimes().size(); i++) {
String streamId = queryRuntime.getStreamRuntime().getSingleStreamRuntimes().get(i).getProcessStreamReceiver().getStreamId();
StreamDefinition streamDefinition;
if (streamId.startsWith("#")) {
streamDefinition = (StreamDefinition) localStreamDefinitionMap.get(streamId);
} else {
streamDefinition = (StreamDefinition) streamDefinitionMap.get(streamId);
}
StreamJunction streamJunction = localStreamJunctionMap.get(streamId + key);
if (streamJunction == null) {
streamJunction = new StreamJunction(streamDefinition, siddhiAppContext.getExecutorService(), siddhiAppContext.getBufferSize(), siddhiAppContext);
localStreamJunctionMap.put(streamId + key, streamJunction);
}
streamJunction.subscribe(clonedQueryRuntime.getStreamRuntime().getSingleStreamRuntimes().get(i).getProcessStreamReceiver());
}
} else {
partitionedQueryRuntimeList.add(clonedQueryRuntime);
}
}
partitionInstanceRuntimeMap.putIfAbsent(key, new PartitionInstanceRuntime(key, queryRuntimeList));
updatePartitionStreamReceivers(key, partitionedQueryRuntimeList);
}
}
use of org.wso2.siddhi.core.config.SiddhiAppContext in project siddhi by wso2.
the class PartitionRuntime method addPartitionReceiver.
public void addPartitionReceiver(QueryRuntime queryRuntime, List<VariableExpressionExecutor> executors, MetaStateEvent metaEvent) {
Query query = queryRuntime.getQuery();
List<List<PartitionExecutor>> partitionExecutors = new StreamPartitioner(query.getInputStream(), partition, metaEvent, executors, siddhiAppContext, null).getPartitionExecutorLists();
if (queryRuntime.getStreamRuntime() instanceof SingleStreamRuntime) {
SingleInputStream singleInputStream = (SingleInputStream) query.getInputStream();
addPartitionReceiver(singleInputStream.getStreamId(), singleInputStream.isInnerStream(), metaEvent.getMetaStreamEvent(0), partitionExecutors.get(0));
} else if (queryRuntime.getStreamRuntime() instanceof JoinStreamRuntime) {
SingleInputStream leftSingleInputStream = (SingleInputStream) ((JoinInputStream) query.getInputStream()).getLeftInputStream();
addPartitionReceiver(leftSingleInputStream.getStreamId(), leftSingleInputStream.isInnerStream(), metaEvent.getMetaStreamEvent(0), partitionExecutors.get(0));
SingleInputStream rightSingleInputStream = (SingleInputStream) ((JoinInputStream) query.getInputStream()).getRightInputStream();
addPartitionReceiver(rightSingleInputStream.getStreamId(), rightSingleInputStream.isInnerStream(), metaEvent.getMetaStreamEvent(1), partitionExecutors.get(1));
} else if (queryRuntime.getStreamRuntime() instanceof StateStreamRuntime) {
StateElement stateElement = ((StateInputStream) query.getInputStream()).getStateElement();
addPartitionReceiverForStateElement(stateElement, metaEvent, partitionExecutors, 0);
}
}
use of org.wso2.siddhi.core.config.SiddhiAppContext in project siddhi by wso2.
the class StreamPartitioner method createJoinInputStreamExecutors.
private void createJoinInputStreamExecutors(JoinInputStream inputStream, Partition partition, MetaStateEvent metaEvent, List<VariableExpressionExecutor> executors, SiddhiAppContext siddhiAppContext, String queryName) {
createExecutors(inputStream.getLeftInputStream(), partition, metaEvent.getMetaStreamEvent(0), executors, siddhiAppContext, queryName);
int size = executors.size();
for (VariableExpressionExecutor variableExpressionExecutor : executors) {
variableExpressionExecutor.getPosition()[SiddhiConstants.STREAM_EVENT_CHAIN_INDEX] = 0;
}
createExecutors(inputStream.getRightInputStream(), partition, metaEvent.getMetaStreamEvent(1), executors, siddhiAppContext, queryName);
for (int i = size; i < executors.size(); i++) {
executors.get(i).getPosition()[SiddhiConstants.STREAM_EVENT_CHAIN_INDEX] = 1;
}
}
Aggregations