Search in sources :

Example 1 with DynamicOptions

use of io.siddhi.core.util.transport.DynamicOptions 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 && Level.DETAIL.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
                    mapperLatencyTracker.markIn();
                }
                mapAndSend(eventList.toArray(new Event[eventList.size()]), optionHolder, templateBuilderMap, sinkListener);
            } finally {
                trpDynamicOptions.remove();
                if (mapperLatencyTracker != null && Level.DETAIL.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
                    mapperLatencyTracker.markOut();
                }
            }
        }
    } else {
        try {
            trpDynamicOptions.set(new DynamicOptions(events[0]));
            if (mapperLatencyTracker != null && Level.DETAIL.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
                mapperLatencyTracker.markIn();
            }
            mapAndSend(events, optionHolder, templateBuilderMap, sinkListener);
        } finally {
            trpDynamicOptions.remove();
            if (mapperLatencyTracker != null && Level.DETAIL.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
                mapperLatencyTracker.markOut();
            }
        }
    }
}
Also used : DynamicOptions(io.siddhi.core.util.transport.DynamicOptions) ArrayList(java.util.ArrayList) Event(io.siddhi.core.event.Event) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with DynamicOptions

use of io.siddhi.core.util.transport.DynamicOptions in project siddhi by wso2.

the class Sink method publish.

@Override
public final void publish(Object payload) {
    if (mapperLatencyTracker != null && Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
        mapperLatencyTracker.markOut();
    }
    DynamicOptions dynamicOptions = trpDynamicOptions.get();
    if (isConnected()) {
        S state = stateHolder.getState();
        try {
            publish(payload, dynamicOptions, state);
            if (throughputTracker != null && Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
                throughputTracker.eventIn();
            }
        } catch (ConnectionUnavailableException e) {
            setConnected(false);
            if (connectionCallback != null) {
                connectionCallback.connectionFailed();
            }
            if (!isTryingToConnect.getAndSet(true)) {
                try {
                    connectAndPublish(payload, dynamicOptions, state);
                    isTryingToConnect.set(false);
                } catch (ConnectionUnavailableException e1) {
                    isTryingToConnect.set(false);
                    onError(payload, dynamicOptions, e);
                }
            } else {
                onError(payload, dynamicOptions, e);
            }
        } finally {
            stateHolder.returnState(state);
        }
    } else if (!isShutdown.get()) {
        onError(payload, dynamicOptions, new ConnectionUnavailableException("Connection unavailable at Sink '" + type + "' at '" + streamDefinition.getId() + "'. Connection retrying is in progress from a different thread"));
    }
}
Also used : DynamicOptions(io.siddhi.core.util.transport.DynamicOptions) ConnectionUnavailableException(io.siddhi.core.exception.ConnectionUnavailableException)

Example 3 with DynamicOptions

use of io.siddhi.core.util.transport.DynamicOptions in project siddhi by wso2.

the class Sink method retryPublish.

protected void retryPublish(Object payload) throws ConnectionUnavailableException {
    DynamicOptions dynamicOptions = trpDynamicOptions.get();
    S state = stateHolder.getState();
    try {
        publish(payload, dynamicOptions, state);
        if (throughputTracker != null && Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
            throughputTracker.eventIn();
        }
    } finally {
        stateHolder.returnState(state);
    }
}
Also used : DynamicOptions(io.siddhi.core.util.transport.DynamicOptions)

Example 4 with DynamicOptions

use of io.siddhi.core.util.transport.DynamicOptions in project siddhi by wso2.

the class SinkMapper method mapAndSend.

/**
 * Called to map the event and send it to {@link SinkListener} for publishing
 *
 * @param event The {@link Event} that need to be mapped
 */
final void mapAndSend(Event event) {
    try {
        trpDynamicOptions.set(new DynamicOptions(event));
        mapAndSend(event, optionHolder, templateBuilderMap, sinkListener);
    } finally {
        trpDynamicOptions.remove();
    }
}
Also used : DynamicOptions(io.siddhi.core.util.transport.DynamicOptions)

Aggregations

DynamicOptions (io.siddhi.core.util.transport.DynamicOptions)4 Event (io.siddhi.core.event.Event)1 ConnectionUnavailableException (io.siddhi.core.exception.ConnectionUnavailableException)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1