use of io.siddhi.query.api.extension.Extension in project siddhi by wso2.
the class DefinitionParserHelper method addTable.
public static void addTable(TableDefinition tableDefinition, ConcurrentMap<String, Table> tableMap, SiddhiAppContext siddhiAppContext) {
if (!tableMap.containsKey(tableDefinition.getId())) {
MetaStreamEvent tableMetaStreamEvent = new MetaStreamEvent();
tableMetaStreamEvent.addInputDefinition(tableDefinition);
for (Attribute attribute : tableDefinition.getAttributeList()) {
tableMetaStreamEvent.addOutputData(attribute);
}
StreamEventFactory tableStreamEventFactory = new StreamEventFactory(tableMetaStreamEvent);
StreamEventCloner tableStreamEventCloner = new StreamEventCloner(tableMetaStreamEvent, tableStreamEventFactory);
Annotation annotation = AnnotationHelper.getAnnotation(SiddhiConstants.ANNOTATION_STORE, tableDefinition.getAnnotations());
Table table;
ConfigReader configReader = null;
RecordTableHandlerManager recordTableHandlerManager = null;
RecordTableHandler recordTableHandler = null;
if (annotation != null) {
annotation = updateAnnotationRef(annotation, SiddhiConstants.NAMESPACE_STORE, siddhiAppContext);
String tableType = annotation.getElement(SiddhiConstants.ANNOTATION_ELEMENT_TYPE);
if (tableType == null) {
throw new SiddhiAppCreationException("Attribute 'type' does not exist for annotation '" + annotation + "'", annotation, siddhiAppContext);
}
Extension extension = new Extension() {
@Override
public String getNamespace() {
return SiddhiConstants.NAMESPACE_STORE;
}
@Override
public String getName() {
return tableType;
}
};
recordTableHandlerManager = siddhiAppContext.getSiddhiContext().getRecordTableHandlerManager();
if (recordTableHandlerManager != null) {
recordTableHandler = recordTableHandlerManager.generateRecordTableHandler();
}
table = (Table) SiddhiClassLoader.loadExtensionImplementation(extension, TableExtensionHolder.getInstance(siddhiAppContext));
configReader = siddhiAppContext.getSiddhiContext().getConfigManager().generateConfigReader(extension.getNamespace(), extension.getName());
} else {
table = new InMemoryTable();
}
table.initTable(tableDefinition, tableStreamEventFactory, tableStreamEventCloner, configReader, siddhiAppContext, recordTableHandler);
if (recordTableHandler != null) {
recordTableHandlerManager.registerRecordTableHandler(recordTableHandler.getId(), recordTableHandler);
}
tableMap.putIfAbsent(tableDefinition.getId(), table);
}
}
use of io.siddhi.query.api.extension.Extension in project siddhi by wso2.
the class SingleClientDistributedSink method initTransport.
@Override
public void initTransport(OptionHolder sinkOptionHolder, List<OptionHolder> destinationOptionHolders, Map<String, String> deploymentProperties, List<Map<String, String>> destinationDeploymentProperties, Annotation sinkAnnotation, ConfigReader sinkConfigReader, DistributionStrategy strategy, String type, SiddhiAppContext siddhiAppContext) {
final String transportType = sinkOptionHolder.validateAndGetStaticValue(SiddhiConstants.ANNOTATION_ELEMENT_TYPE);
Extension sinkExtension = DefinitionParserHelper.constructExtension(streamDefinition, SiddhiConstants.ANNOTATION_SINK, transportType, sinkAnnotation, SiddhiConstants.NAMESPACE_SINK);
Set<String> allDynamicOptionKeys = findAllDynamicOptions(destinationOptionHolders);
destinationOptionHolders.forEach(optionHolder -> {
optionHolder.merge(sinkOptionHolder);
allDynamicOptionKeys.forEach(optionKey -> {
String optionValue = optionHolder.getOrCreateOption(optionKey, null).getValue();
if (optionValue == null || optionValue.isEmpty()) {
throw new SiddhiAppValidationException("Destination properties can only contain " + "non-empty static values.");
}
Option sinkOption = sinkOptionHolder.getOrAddStaticOption(optionKey, optionValue);
sinkOption.addVariableValue(optionValue);
destinationCount++;
});
});
this.sink = (Sink) SiddhiClassLoader.loadExtensionImplementation(sinkExtension, SinkExecutorExtensionHolder.getInstance(siddhiAppContext));
this.sink.initOnlyTransport(streamDefinition, sinkOptionHolder, sinkConfigReader, type, new SingleClientConnectionCallback(destinationCount, strategy), destinationDeploymentProperties.get(0), siddhiAppContext);
if (!this.sink.getServiceDeploymentInfoList().isEmpty()) {
((ServiceDeploymentInfo) this.sink.getServiceDeploymentInfoList().get(0)).addDeploymentProperties(deploymentProperties);
}
}
Aggregations