use of org.wso2.siddhi.core.stream.StreamJunction in project siddhi by wso2.
the class SiddhiAppRuntime method shutdown.
public synchronized void shutdown() {
SourceHandlerManager sourceHandlerManager = siddhiAppContext.getSiddhiContext().getSourceHandlerManager();
for (List<Source> sources : sourceMap.values()) {
for (Source source : sources) {
try {
if (sourceHandlerManager != null) {
sourceHandlerManager.unregisterSourceHandler(source.getMapper().getHandler().getElementId());
}
source.shutdown();
} catch (Throwable t) {
log.error(StringUtil.removeCRLFCharacters(ExceptionUtil.getMessageWithContext(t, siddhiAppContext)) + " Error in shutting down source '" + StringUtil.removeCRLFCharacters(source.getType()) + "' at '" + StringUtil.removeCRLFCharacters(source.getStreamDefinition().getId()) + "' on Siddhi App '" + siddhiAppContext.getName() + "'.", t);
}
}
}
for (Table table : tableMap.values()) {
try {
table.shutdown();
} catch (Throwable t) {
log.error(StringUtil.removeCRLFCharacters(ExceptionUtil.getMessageWithContext(t, siddhiAppContext)) + " Error in shutting down table '" + StringUtil.removeCRLFCharacters(table.getTableDefinition().getId()) + "' on Siddhi App '" + StringUtil.removeCRLFCharacters(siddhiAppContext.getName()) + "'.", t);
}
}
SinkHandlerManager sinkHandlerManager = siddhiAppContext.getSiddhiContext().getSinkHandlerManager();
for (List<Sink> sinks : sinkMap.values()) {
for (Sink sink : sinks) {
try {
if (sinkHandlerManager != null) {
sinkHandlerManager.unregisterSinkHandler(sink.getHandler().getElementId());
}
sink.shutdown();
} catch (Throwable t) {
log.error(StringUtil.removeCRLFCharacters(ExceptionUtil.getMessageWithContext(t, siddhiAppContext)) + " Error in shutting down sink '" + StringUtil.removeCRLFCharacters(sink.getType()) + "' at '" + StringUtil.removeCRLFCharacters(sink.getStreamDefinition().getId()) + "' on Siddhi App '" + StringUtil.removeCRLFCharacters(siddhiAppContext.getName()) + "'.", t);
}
}
}
for (Table table : tableMap.values()) {
RecordTableHandlerManager recordTableHandlerManager = siddhiAppContext.getSiddhiContext().getRecordTableHandlerManager();
if (recordTableHandlerManager != null) {
String elementId = null;
RecordTableHandler recordTableHandler = table.getHandler();
if (recordTableHandler != null) {
elementId = recordTableHandler.getElementId();
}
if (elementId != null) {
recordTableHandlerManager.unregisterRecordTableHandler(elementId);
}
}
table.shutdown();
}
for (EternalReferencedHolder eternalReferencedHolder : siddhiAppContext.getEternalReferencedHolders()) {
try {
eternalReferencedHolder.stop();
} catch (Throwable t) {
log.error(StringUtil.removeCRLFCharacters(ExceptionUtil.getMessageWithContext(t, siddhiAppContext)) + " Error while stopping EternalReferencedHolder '" + StringUtil.removeCRLFCharacters(eternalReferencedHolder.toString()) + "' down Siddhi app '" + StringUtil.removeCRLFCharacters(siddhiAppContext.getName()) + "'.", t);
}
}
inputManager.disconnect();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
for (StreamJunction streamJunction : streamJunctionMap.values()) {
streamJunction.stopProcessing();
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
siddhiAppContext.getScheduledExecutorService().shutdownNow();
siddhiAppContext.getExecutorService().shutdownNow();
}
}, "Siddhi-SiddhiApp-" + siddhiAppContext.getName() + "-Shutdown-Cleaner");
thread.start();
if (siddhiAppRuntimeMap != null) {
siddhiAppRuntimeMap.remove(siddhiAppContext.getName());
}
if (siddhiAppContext.getStatisticsManager() != null) {
if (siddhiAppContext.isStatsEnabled()) {
siddhiAppContext.getStatisticsManager().stopReporting();
}
siddhiAppContext.getStatisticsManager().cleanup();
}
running = false;
}
use of org.wso2.siddhi.core.stream.StreamJunction 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.stream.StreamJunction 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.stream.StreamJunction in project siddhi by wso2.
the class PartitionStreamReceiver method addStreamJunction.
/**
* create local streamJunctions through which events received by partitionStreamReceiver, are sent to
* queryStreamReceivers
*
* @param key partitioning key
* @param queryRuntimeList queryRuntime list of the partition
*/
public void addStreamJunction(String key, List<QueryRuntime> queryRuntimeList) {
StreamJunction streamJunction = cachedStreamJunctionMap.get(streamId + key);
if (streamJunction == null) {
streamJunction = partitionRuntime.getLocalStreamJunctionMap().get(streamId + key);
if (streamJunction == null) {
streamJunction = createStreamJunction();
partitionRuntime.addStreamJunction(streamId + key, streamJunction);
}
cachedStreamJunctionMap.put(streamId + key, streamJunction);
}
for (QueryRuntime queryRuntime : queryRuntimeList) {
StreamRuntime streamRuntime = queryRuntime.getStreamRuntime();
for (int i = 0; i < queryRuntime.getInputStreamId().size(); i++) {
if ((streamRuntime.getSingleStreamRuntimes().get(i)).getProcessStreamReceiver().getStreamId().equals(streamId + key)) {
streamJunction.subscribe((streamRuntime.getSingleStreamRuntimes().get(i)).getProcessStreamReceiver());
}
}
}
}
use of org.wso2.siddhi.core.stream.StreamJunction in project siddhi by wso2.
the class StreamJunction method sendEvent.
private void sendEvent(List<Event> events) {
if (isTraceEnabled) {
log.trace("Event is received by streamJunction " + this);
}
if (disruptor != null) {
for (Event event : events) {
// Todo : optimize for arrays
long sequenceNo = ringBuffer.next();
try {
Event existingEvent = ringBuffer.get(sequenceNo);
existingEvent.copyFrom(event);
} finally {
ringBuffer.publish(sequenceNo);
}
}
} else {
for (Receiver receiver : receivers) {
receiver.receive(events.toArray(new Event[events.size()]));
}
}
}
Aggregations