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