Search in sources :

Example 11 with OptionHolder

use of org.wso2.siddhi.core.util.transport.OptionHolder in project siddhi by wso2.

the class SinkMapper method mapAndSend.

/**
 * Called to map the events and send them to {@link SinkListener} for publishing
 *
 * @param events {@link Event}s that need to be mapped
 */
final void mapAndSend(Event[] events) {
    if (groupDeterminer != null) {
        LinkedHashMap<String, ArrayList<Event>> eventMap = new LinkedHashMap<>();
        for (Event event : events) {
            String key = groupDeterminer.decideGroup(event);
            ArrayList<Event> eventList = eventMap.computeIfAbsent(key, k -> new ArrayList<>());
            eventList.add(event);
        }
        for (ArrayList<Event> eventList : eventMap.values()) {
            try {
                trpDynamicOptions.set(new DynamicOptions(eventList.get(0)));
                if (mapperLatencyTracker != null && siddhiAppContext.isStatsEnabled()) {
                    mapperLatencyTracker.markIn();
                }
                mapAndSend(eventList.toArray(new Event[eventList.size()]), optionHolder, templateBuilderMap, sinkListener);
            } finally {
                trpDynamicOptions.remove();
                if (mapperLatencyTracker != null && siddhiAppContext.isStatsEnabled()) {
                    mapperLatencyTracker.markOut();
                }
            }
        }
    } else {
        try {
            trpDynamicOptions.set(new DynamicOptions(events[0]));
            if (mapperLatencyTracker != null && siddhiAppContext.isStatsEnabled()) {
                mapperLatencyTracker.markIn();
            }
            mapAndSend(events, optionHolder, templateBuilderMap, sinkListener);
        } finally {
            trpDynamicOptions.remove();
            if (mapperLatencyTracker != null && siddhiAppContext.isStatsEnabled()) {
                mapperLatencyTracker.markOut();
            }
        }
    }
}
Also used : DynamicOptions(org.wso2.siddhi.core.util.transport.DynamicOptions) ArrayList(java.util.ArrayList) Event(org.wso2.siddhi.core.event.Event) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ArrayList (java.util.ArrayList)4 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)4 OptionHolder (org.wso2.siddhi.core.util.transport.OptionHolder)4 Extension (org.wso2.siddhi.query.api.extension.Extension)4 Element (org.wso2.siddhi.query.api.annotation.Element)3 OutputGroupDeterminer (org.wso2.siddhi.core.stream.output.sink.OutputGroupDeterminer)2 Sink (org.wso2.siddhi.core.stream.output.sink.Sink)2 ConfigReader (org.wso2.siddhi.core.util.config.ConfigReader)2 DynamicOptions (org.wso2.siddhi.core.util.transport.DynamicOptions)2 Option (org.wso2.siddhi.core.util.transport.Option)2 Annotation (org.wso2.siddhi.query.api.annotation.Annotation)2 SiddhiAppValidationException (org.wso2.siddhi.query.api.exception.SiddhiAppValidationException)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Event (org.wso2.siddhi.core.event.Event)1 Source (org.wso2.siddhi.core.stream.input.source.Source)1 SourceHandler (org.wso2.siddhi.core.stream.input.source.SourceHandler)1 SourceHandlerManager (org.wso2.siddhi.core.stream.input.source.SourceHandlerManager)1 SourceMapper (org.wso2.siddhi.core.stream.input.source.SourceMapper)1 DynamicOptionGroupDeterminer (org.wso2.siddhi.core.stream.output.sink.DynamicOptionGroupDeterminer)1