Search in sources :

Example 6 with Extension

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);
    }
}
Also used : InMemoryTable(io.siddhi.core.table.InMemoryTable) Table(io.siddhi.core.table.Table) InMemoryTable(io.siddhi.core.table.InMemoryTable) Attribute(io.siddhi.query.api.definition.Attribute) SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException) StreamEventFactory(io.siddhi.core.event.stream.StreamEventFactory) ConfigReader(io.siddhi.core.util.config.ConfigReader) RecordTableHandler(io.siddhi.core.table.record.RecordTableHandler) Annotation(io.siddhi.query.api.annotation.Annotation) Extension(io.siddhi.query.api.extension.Extension) StreamEventCloner(io.siddhi.core.event.stream.StreamEventCloner) RecordTableHandlerManager(io.siddhi.core.table.record.RecordTableHandlerManager) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Example 7 with Extension

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);
    }
}
Also used : Extension(io.siddhi.query.api.extension.Extension) SiddhiAppValidationException(io.siddhi.query.api.exception.SiddhiAppValidationException) ServiceDeploymentInfo(io.siddhi.core.stream.ServiceDeploymentInfo)

Aggregations

Extension (io.siddhi.query.api.extension.Extension)7 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)4 ConfigReader (io.siddhi.core.util.config.ConfigReader)4 Annotation (io.siddhi.query.api.annotation.Annotation)3 ServiceDeploymentInfo (io.siddhi.core.stream.ServiceDeploymentInfo)2 Sink (io.siddhi.core.stream.output.sink.Sink)2 OptionHolder (io.siddhi.core.util.transport.OptionHolder)2 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)1 StreamEventCloner (io.siddhi.core.event.stream.StreamEventCloner)1 StreamEventFactory (io.siddhi.core.event.stream.StreamEventFactory)1 Script (io.siddhi.core.function.Script)1 Source (io.siddhi.core.stream.input.source.Source)1 SourceHandler (io.siddhi.core.stream.input.source.SourceHandler)1 SourceHandlerManager (io.siddhi.core.stream.input.source.SourceHandlerManager)1 SourceMapper (io.siddhi.core.stream.input.source.SourceMapper)1 OutputGroupDeterminer (io.siddhi.core.stream.output.sink.OutputGroupDeterminer)1 SinkHandler (io.siddhi.core.stream.output.sink.SinkHandler)1 SinkHandlerManager (io.siddhi.core.stream.output.sink.SinkHandlerManager)1 SinkMapper (io.siddhi.core.stream.output.sink.SinkMapper)1 DistributedTransport (io.siddhi.core.stream.output.sink.distributed.DistributedTransport)1