Search in sources :

Example 1 with StreamJunction

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);
    }
}
Also used : CronTrigger(io.siddhi.core.trigger.CronTrigger) StreamJunction(io.siddhi.core.stream.StreamJunction) AbstractTrigger(io.siddhi.core.trigger.AbstractTrigger) StartTrigger(io.siddhi.core.trigger.StartTrigger) PeriodicTrigger(io.siddhi.core.trigger.PeriodicTrigger)

Example 2 with StreamJunction

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);
}
Also used : StreamJunction(io.siddhi.core.stream.StreamJunction) DefinitionNotExistException(io.siddhi.core.exception.DefinitionNotExistException)

Example 3 with StreamJunction

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);
    }
}
Also used : StreamJunction(io.siddhi.core.stream.StreamJunction) SiddhiAppRuntimeException(io.siddhi.core.exception.SiddhiAppRuntimeException)

Example 4 with StreamJunction

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);
}
Also used : Query(io.siddhi.query.api.execution.query.Query) StreamDefinition(io.siddhi.query.api.definition.StreamDefinition) InsertIntoWindowCallback(io.siddhi.core.query.output.callback.InsertIntoWindowCallback) InsertIntoStream(io.siddhi.query.api.execution.query.output.stream.InsertIntoStream) StreamJunction(io.siddhi.core.stream.StreamJunction) InsertIntoStreamCallback(io.siddhi.core.query.output.callback.InsertIntoStreamCallback)

Example 5 with StreamJunction

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());
            }
        }
    }
}
Also used : QueryRuntimeImpl(io.siddhi.core.query.QueryRuntimeImpl) QueryRuntime(io.siddhi.core.query.QueryRuntime) StreamJunction(io.siddhi.core.stream.StreamJunction) StreamRuntime(io.siddhi.core.query.input.stream.StreamRuntime)

Aggregations

StreamJunction (io.siddhi.core.stream.StreamJunction)12 InsertIntoStreamCallback (io.siddhi.core.query.output.callback.InsertIntoStreamCallback)3 DefinitionNotExistException (io.siddhi.core.exception.DefinitionNotExistException)2 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)2 QueryRuntime (io.siddhi.core.query.QueryRuntime)2 StreamRuntime (io.siddhi.core.query.input.stream.StreamRuntime)2 InsertIntoWindowCallback (io.siddhi.core.query.output.callback.InsertIntoWindowCallback)2 Sink (io.siddhi.core.stream.output.sink.Sink)2 Table (io.siddhi.core.table.Table)2 ExternalReferencedHolder (io.siddhi.core.util.extension.holder.ExternalReferencedHolder)2 StreamDefinition (io.siddhi.query.api.definition.StreamDefinition)2 InsertIntoStream (io.siddhi.query.api.execution.query.output.stream.InsertIntoStream)2 AggregationRuntime (io.siddhi.core.aggregation.AggregationRuntime)1 SiddhiAppRuntimeException (io.siddhi.core.exception.SiddhiAppRuntimeException)1 QueryRuntimeImpl (io.siddhi.core.query.QueryRuntimeImpl)1 ProcessStreamReceiver (io.siddhi.core.query.input.ProcessStreamReceiver)1 SingleStreamRuntime (io.siddhi.core.query.input.stream.single.SingleStreamRuntime)1 OutputCallback (io.siddhi.core.query.output.callback.OutputCallback)1 Source (io.siddhi.core.stream.input.source.Source)1 SourceHandlerManager (io.siddhi.core.stream.input.source.SourceHandlerManager)1