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();
}
}
}
}
Aggregations