use of io.siddhi.core.stream.StreamJunction in project siddhi by wso2.
the class DefinitionParserHelper method addEventTrigger.
public static void addEventTrigger(TriggerDefinition triggerDefinition, ConcurrentMap<String, Trigger> eventTriggerMap, ConcurrentMap<String, StreamJunction> streamJunctionMap, SiddhiAppContext siddhiAppContext) {
if (!eventTriggerMap.containsKey(triggerDefinition.getId())) {
AbstractTrigger trigger;
if (triggerDefinition.getAtEvery() != null) {
trigger = new PeriodicTrigger();
} else if (triggerDefinition.getAt().trim().equalsIgnoreCase(SiddhiConstants.TRIGGER_START)) {
trigger = new StartTrigger();
} else {
trigger = new CronTrigger();
}
StreamJunction streamJunction = streamJunctionMap.get(triggerDefinition.getId());
trigger.init(triggerDefinition, siddhiAppContext, streamJunction);
siddhiAppContext.addTrigger(trigger);
eventTriggerMap.putIfAbsent(trigger.getId(), trigger);
}
}
use of io.siddhi.core.stream.StreamJunction in project siddhi by wso2.
the class SiddhiAppRuntimeImpl method addCallback.
public void addCallback(String streamId, StreamCallback streamCallback) {
streamCallback.setStreamId(streamId);
StreamJunction streamJunction = streamJunctionMap.get(streamId);
if (streamJunction == null) {
throw new DefinitionNotExistException("No stream found with name: " + streamId);
}
streamCallback.setStreamDefinition(streamDefinitionMap.get(streamId));
streamCallback.setContext(siddhiAppContext);
streamJunction.subscribe(streamCallback);
}
use of io.siddhi.core.stream.StreamJunction in project siddhi by wso2.
the class SiddhiAppRuntimeImpl method removeCallback.
public void removeCallback(StreamCallback streamCallback) {
if (streamCallback.getStreamId() == null) {
throw new SiddhiAppRuntimeException("Cannot find streamID in the streamCallback");
}
String streamId = streamCallback.getStreamId();
StreamJunction streamJunction = streamJunctionMap.get(streamId);
if (streamJunction != null) {
streamJunction.unsubscribe(streamCallback);
}
}
use of io.siddhi.core.stream.StreamJunction in project siddhi by wso2.
the class PartitionRuntimeImpl method addQuery.
public void addQuery(QueryRuntimeImpl metaQueryRuntime) {
Query query = metaQueryRuntime.getQuery();
if (query.getOutputStream() instanceof InsertIntoStream && metaQueryRuntime.getOutputCallback() instanceof InsertIntoStreamCallback) {
InsertIntoStreamCallback insertIntoStreamCallback = (InsertIntoStreamCallback) metaQueryRuntime.getOutputCallback();
StreamDefinition streamDefinition = insertIntoStreamCallback.getOutputStreamDefinition();
String id = streamDefinition.getId();
if (((InsertIntoStream) query.getOutputStream()).isInnerStream()) {
metaQueryRuntime.setToLocalStream(true);
localStreamDefinitionMap.putIfAbsent(id, streamDefinition);
DefinitionParserHelper.validateOutputStream(streamDefinition, localStreamDefinitionMap.get(id));
StreamJunction outputStreamJunction = localStreamJunctionMap.get(id);
if (outputStreamJunction == null) {
outputStreamJunction = new StreamJunction(streamDefinition, siddhiAppContext.getExecutorService(), siddhiAppContext.getBufferSize(), null, siddhiAppContext);
localStreamJunctionMap.putIfAbsent(id, outputStreamJunction);
}
insertIntoStreamCallback.init(localStreamJunctionMap.get(id));
} else {
streamDefinitionMap.putIfAbsent(id, streamDefinition);
DefinitionParserHelper.validateOutputStream(streamDefinition, streamDefinitionMap.get(id));
StreamJunction outputStreamJunction = streamJunctionMap.get(id);
if (outputStreamJunction == null) {
outputStreamJunction = new StreamJunction(streamDefinition, siddhiAppContext.getExecutorService(), siddhiAppContext.getBufferSize(), null, siddhiAppContext);
streamJunctionMap.putIfAbsent(id, outputStreamJunction);
}
insertIntoStreamCallback.init(streamJunctionMap.get(id));
}
} else if (query.getOutputStream() instanceof InsertIntoStream && metaQueryRuntime.getOutputCallback() instanceof InsertIntoWindowCallback) {
InsertIntoWindowCallback insertIntoWindowCallback = (InsertIntoWindowCallback) metaQueryRuntime.getOutputCallback();
StreamDefinition streamDefinition = insertIntoWindowCallback.getOutputStreamDefinition();
String id = streamDefinition.getId();
DefinitionParserHelper.validateOutputStream(streamDefinition, windowDefinitionMap.get(id));
StreamJunction outputStreamJunction = streamJunctionMap.get(id);
if (outputStreamJunction == null) {
outputStreamJunction = new StreamJunction(streamDefinition, siddhiAppContext.getExecutorService(), siddhiAppContext.getBufferSize(), null, siddhiAppContext);
streamJunctionMap.putIfAbsent(id, outputStreamJunction);
}
insertIntoWindowCallback.getWindow().setPublisher(streamJunctionMap.get(insertIntoWindowCallback.getOutputStreamDefinition().getId()).constructPublisher());
}
if (metaQueryRuntime.isFromLocalStream()) {
for (int i = 0; i < metaQueryRuntime.getStreamRuntime().getSingleStreamRuntimes().size(); i++) {
String streamId = metaQueryRuntime.getStreamRuntime().getSingleStreamRuntimes().get(i).getProcessStreamReceiver().getStreamId();
if (streamId.startsWith("#")) {
StreamDefinition streamDefinition = (StreamDefinition) localStreamDefinitionMap.get(streamId);
StreamJunction streamJunction = localStreamJunctionMap.get(streamId);
if (streamJunction == null) {
streamJunction = new StreamJunction(streamDefinition, siddhiAppContext.getExecutorService(), siddhiAppContext.getBufferSize(), null, siddhiAppContext);
localStreamJunctionMap.put(streamId, streamJunction);
}
streamJunction.subscribe(metaQueryRuntime.getStreamRuntime().getSingleStreamRuntimes().get(i).getProcessStreamReceiver());
}
}
}
queryRuntimeList.add(metaQueryRuntime);
}
use of io.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 queryRuntimeList queryRuntime list of the partition
*/
public void addStreamJunction(List<QueryRuntime> queryRuntimeList) {
StreamJunction streamJunction = streamJunctionMap.get(streamId);
if (streamJunction == null) {
streamJunction = partitionRuntime.getInnerPartitionStreamReceiverStreamJunctionMap().get(streamId);
if (streamJunction == null) {
streamJunction = createStreamJunction();
partitionRuntime.addInnerpartitionStreamReceiverStreamJunction(streamId, streamJunction);
}
streamJunctionMap.put(streamId, streamJunction);
}
for (QueryRuntime queryRuntime : queryRuntimeList) {
StreamRuntime streamRuntime = ((QueryRuntimeImpl) queryRuntime).getStreamRuntime();
for (int i = 0; i < ((QueryRuntimeImpl) queryRuntime).getInputStreamId().size(); i++) {
if ((streamRuntime.getSingleStreamRuntimes().get(i)).getProcessStreamReceiver().getStreamId().equals(streamId)) {
streamJunction.subscribe((streamRuntime.getSingleStreamRuntimes().get(i)).getProcessStreamReceiver());
}
}
}
}
Aggregations