Search in sources :

Example 1 with StreamJunction

use of org.wso2.siddhi.core.stream.StreamJunction in project siddhi by wso2.

the class PartitionRuntime method addQuery.

public QueryRuntime addQuery(QueryRuntime 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(), 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(), siddhiAppContext);
                streamJunctionMap.putIfAbsent(id, outputStreamJunction);
            }
            insertIntoStreamCallback.init(streamJunctionMap.get(id));
        }
    }
    metaQueryRuntimeMap.put(metaQueryRuntime.getQueryId(), metaQueryRuntime);
    return metaQueryRuntime;
}
Also used : Query(org.wso2.siddhi.query.api.execution.query.Query) StreamDefinition(org.wso2.siddhi.query.api.definition.StreamDefinition) InsertIntoStream(org.wso2.siddhi.query.api.execution.query.output.stream.InsertIntoStream) StreamJunction(org.wso2.siddhi.core.stream.StreamJunction) InsertIntoStreamCallback(org.wso2.siddhi.core.query.output.callback.InsertIntoStreamCallback)

Example 2 with StreamJunction

use of org.wso2.siddhi.core.stream.StreamJunction in project siddhi by wso2.

the class StreamJunction method sendEvent.

public void sendEvent(ComplexEvent complexEvent) {
    if (isTraceEnabled) {
        log.trace("Event is received by streamJunction " + this);
    }
    ComplexEvent complexEventList = complexEvent;
    if (disruptor != null) {
        while (complexEventList != null) {
            if (throughputTracker != null && siddhiAppContext.isStatsEnabled()) {
                throughputTracker.eventIn();
            }
            long sequenceNo = ringBuffer.next();
            try {
                Event existingEvent = ringBuffer.get(sequenceNo);
                existingEvent.copyFrom(complexEventList);
            } finally {
                ringBuffer.publish(sequenceNo);
            }
            complexEventList = complexEventList.getNext();
        }
    } else {
        if (throughputTracker != null && siddhiAppContext.isStatsEnabled()) {
            int messageCount = 0;
            while (complexEventList != null) {
                messageCount++;
                complexEventList = complexEventList.getNext();
            }
            throughputTracker.eventsIn(messageCount);
        }
        for (Receiver receiver : receivers) {
            receiver.receive(complexEvent);
        }
    }
}
Also used : ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) Event(org.wso2.siddhi.core.event.Event) ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent)

Example 3 with StreamJunction

use of org.wso2.siddhi.core.stream.StreamJunction in project siddhi by wso2.

the class StreamJunction method sendEvent.

public void sendEvent(Event event) {
    if (throughputTracker != null && siddhiAppContext.isStatsEnabled()) {
        throughputTracker.eventIn();
    }
    if (isTraceEnabled) {
        log.trace(event + " event is received by streamJunction " + this);
    }
    if (disruptor != null) {
        long sequenceNo = ringBuffer.next();
        try {
            Event existingEvent = ringBuffer.get(sequenceNo);
            existingEvent.copyFrom(event);
        } finally {
            ringBuffer.publish(sequenceNo);
        }
    } else {
        for (Receiver receiver : receivers) {
            receiver.receive(event);
        }
    }
}
Also used : Event(org.wso2.siddhi.core.event.Event) ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent)

Example 4 with StreamJunction

use of org.wso2.siddhi.core.stream.StreamJunction in project siddhi by wso2.

the class StreamJunction method sendEvent.

private void sendEvent(Event[] events) {
    if (throughputTracker != null && siddhiAppContext.isStatsEnabled()) {
        throughputTracker.eventsIn(events.length);
    }
    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);
        }
    }
}
Also used : Event(org.wso2.siddhi.core.event.Event) ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent)

Example 5 with StreamJunction

use of org.wso2.siddhi.core.stream.StreamJunction in project siddhi by wso2.

the class InputManager method constructInputHandler.

public InputHandler constructInputHandler(String streamId) {
    InputHandler inputHandler = new InputHandler(streamId, inputHandlerMap.size(), inputEntryValve);
    StreamJunction streamJunction = streamJunctionMap.get(streamId);
    if (streamJunction == null) {
        throw new DefinitionNotExistException("Stream with stream ID " + streamId + " has not been defined");
    }
    inputDistributor.addInputProcessor(streamJunctionMap.get(streamId).constructPublisher());
    inputHandlerMap.put(streamId, inputHandler);
    return inputHandler;
}
Also used : StreamJunction(org.wso2.siddhi.core.stream.StreamJunction) DefinitionNotExistException(org.wso2.siddhi.core.exception.DefinitionNotExistException)

Aggregations

StreamJunction (org.wso2.siddhi.core.stream.StreamJunction)10 Event (org.wso2.siddhi.core.event.Event)8 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)8 Test (org.testng.annotations.Test)5 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)5 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)5 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)4 QueryRuntime (org.wso2.siddhi.core.query.QueryRuntime)3 StreamRuntime (org.wso2.siddhi.core.query.input.stream.StreamRuntime)3 InsertIntoStreamCallback (org.wso2.siddhi.core.query.output.callback.InsertIntoStreamCallback)3 ArrayList (java.util.ArrayList)2 StreamEventPool (org.wso2.siddhi.core.event.stream.StreamEventPool)2 DefinitionNotExistException (org.wso2.siddhi.core.exception.DefinitionNotExistException)2 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)2 OutputCallback (org.wso2.siddhi.core.query.output.callback.OutputCallback)2 InsertIntoStream (org.wso2.siddhi.query.api.execution.query.output.stream.InsertIntoStream)2 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)1 StreamEventCloner (org.wso2.siddhi.core.event.stream.StreamEventCloner)1 ProcessStreamReceiver (org.wso2.siddhi.core.query.input.ProcessStreamReceiver)1