Search in sources :

Example 1 with DynamicOptions

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

the class DefinitionParserHelper method isMultiClientDistributedTransport.

private static boolean isMultiClientDistributedTransport(Sink clientTransport, StreamDefinition streamDefinition, Annotation distributionAnnotation, SiddhiAppContext siddhiAppContext) {
    // fetch the @distribution annotations from the @sink annotation
    List<OptionHolder> destinationOptHolders = createDestinationOptionHolders(distributionAnnotation, streamDefinition, clientTransport, siddhiAppContext);
    List<String> dynamicOptions = Arrays.asList(clientTransport.getSupportedDynamicOptions());
    // If at least one of the @destination contains a static option then multi client transport should be used
    for (OptionHolder optionHolder : destinationOptHolders) {
        for (String key : optionHolder.getDynamicOptionsKeys()) {
            if (!dynamicOptions.contains(key)) {
                return true;
            }
        }
        for (String key : optionHolder.getStaticOptionsKeys()) {
            if (!dynamicOptions.contains(key)) {
                return true;
            }
        }
    }
    return false;
}
Also used : OptionHolder(org.wso2.siddhi.core.util.transport.OptionHolder)

Example 2 with DynamicOptions

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

the class DefinitionParserHelper method constructOptionHolder.

private static OptionHolder constructOptionHolder(StreamDefinition streamDefinition, Annotation annotation, org.wso2.siddhi.annotation.Extension extension, String[] supportedDynamicOptions) {
    List<String> supportedDynamicOptionList = new ArrayList<>();
    if (supportedDynamicOptions != null) {
        supportedDynamicOptionList = Arrays.asList(supportedDynamicOptions);
    }
    Map<String, String> options = new HashMap<String, String>();
    Map<String, String> dynamicOptions = new HashMap<String, String>();
    for (Element element : annotation.getElements()) {
        if (Pattern.matches("(.*?)\\{\\{.*?\\}\\}(.*?)", element.getValue())) {
            if (supportedDynamicOptionList.contains(element.getKey())) {
                dynamicOptions.put(element.getKey(), element.getValue());
            } else {
                throw new SiddhiAppCreationException("'" + element.getKey() + "' is not a supported " + "DynamicOption " + "for the Extension '" + extension.namespace() + ":" + extension.name() + "', it only supports following as its DynamicOptions: " + supportedDynamicOptionList, annotation.getQueryContextStartIndex(), annotation.getQueryContextEndIndex());
            }
        } else {
            options.put(element.getKey(), element.getValue());
        }
    }
    return new OptionHolder(streamDefinition, options, dynamicOptions, extension);
}
Also used : HashMap(java.util.HashMap) OptionHolder(org.wso2.siddhi.core.util.transport.OptionHolder) SiddhiAppCreationException(org.wso2.siddhi.core.exception.SiddhiAppCreationException) Element(org.wso2.siddhi.query.api.annotation.Element) ArrayList(java.util.ArrayList)

Example 3 with DynamicOptions

use of org.wso2.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 && siddhiAppContext.isStatsEnabled()) {
        mapperLatencyTracker.markOut();
    }
    if (isConnected.get()) {
        try {
            DynamicOptions dynamicOptions = trpDynamicOptions.get();
            publish(payload, dynamicOptions);
            if (throughputTracker != null && siddhiAppContext.isStatsEnabled()) {
                throughputTracker.eventIn();
            }
        } catch (ConnectionUnavailableException e) {
            isConnected.set(false);
            LOG.error(ExceptionUtil.getMessageWithContext(e, siddhiAppContext) + " Connection unavailable at Sink '" + type + "' at '" + streamDefinition.getId() + "', will retry connection immediately.", e);
            connectWithRetry();
            publish(payload);
        }
    } else if (isTryingToConnect.get()) {
        LOG.error("Error on '" + siddhiAppContext.getName() + "'. Dropping event at Sink '" + type + "' at '" + streamDefinition.getId() + "' as its still trying to reconnect!, events dropped '" + payload + "'");
    } else {
        connectWithRetry();
        publish(payload);
    }
}
Also used : DynamicOptions(org.wso2.siddhi.core.util.transport.DynamicOptions) ConnectionUnavailableException(org.wso2.siddhi.core.exception.ConnectionUnavailableException)

Example 4 with DynamicOptions

use of org.wso2.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(org.wso2.siddhi.core.util.transport.DynamicOptions)

Example 5 with DynamicOptions

use of org.wso2.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 && 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

DynamicOptions (org.wso2.siddhi.core.util.transport.DynamicOptions)3 ArrayList (java.util.ArrayList)2 OptionHolder (org.wso2.siddhi.core.util.transport.OptionHolder)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Event (org.wso2.siddhi.core.event.Event)1 ConnectionUnavailableException (org.wso2.siddhi.core.exception.ConnectionUnavailableException)1 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)1 Element (org.wso2.siddhi.query.api.annotation.Element)1