/** * The initialization method for {@link Source}, will be called before other methods. It used to validate * all configurations and to get initial values. * @param sourceEventListener After receiving events, the source should trigger onEvent() of this listener. * Listener will then pass on the events to the appropriate mappers for processing . * @param optionHolder Option holder containing static configuration related to the {@link Source} * @param configReader ConfigReader is used to read the {@link Source} related system configuration. * @param siddhiAppContext the context of the {@link org.wso2.siddhi.query.api.SiddhiApp} used to get Siddhi * related utility functions. */ @Override public void init(SourceEventListener sourceEventListener, OptionHolder optionHolder, String[] requestedTransportPropertyNames, ConfigReader configReader, SiddhiAppContext siddhiAppContext) { this.sourceEventListener = sourceEventListener; this.optionHolder = optionHolder; streamId = optionHolder.validateAndGetStaticValue("wso2.stream.id", null); }
@Override protected void init(StreamDefinition outputStreamDefinition, OptionHolder optionHolder, ConfigReader sinkConfigReader, SiddhiAppContext siddhiAppContext) { bootstrapServers = optionHolder.validateAndGetStaticValue(KAFKA_BROKER_LIST); optionalConfigs = optionHolder.validateAndGetStaticValue(KAFKA_OPTIONAL_CONFIGURATION_PROPERTIES, null); topicOption = optionHolder.validateAndGetOption(KAFKA_PUBLISH_TOPIC); partitionOption = optionHolder.getOrCreateOption(KAFKA_PARTITION_NO, null); sequenceId = optionHolder.validateAndGetStaticValue(SEQ_ID, null); isBinaryMessage = Boolean.parseBoolean(optionHolder.validateAndGetStaticValue(IS_BINARY_MESSAGE, "false")); isSequenced = sequenceId != null; keyOption = optionHolder.getOrCreateOption(KAFKA_MESSAGE_KEY, null); }
/** * This method will be called before the processing method. * Intention to establish connection to publish event. * such that the system will take care retrying for connection */ @Override public void connect() { if (publisherURLOption.isStatic()) { log.info(streamID + " has successfully connected to " + publisherURL); } }
@Override public void publish(Object payload, DynamicOptions transportOptions) { String topicQueueName = destination.getValue(transportOptions); executorService.execute(new JMSPublisher(topicQueueName, jmsStaticProperties, clientConnector, payload)); }
private Map<String, Object> getTrpProperties(DynamicOptions dynamicOptions) { Event event = dynamicOptions.getEvent(); Object[] data = event.getData(); List<Attribute> attributes = outputStreamDefinition.getAttributeList(); Map<String, Object> trpProperties = new HashMap<>(); for (int i = 0; i < attributes.size(); i++) { trpProperties.put(attributes.get(i).getName(), data[i]); } if (isDownloadEnabled) { trpProperties.put(HttpConstants.DOWNLOAD_PATH, downloadPath.getValue(dynamicOptions)); } return trpProperties; }
@Override protected void init(StreamDefinition outputStreamDefinition, OptionHolder optionHolder, ConfigReader sinkConfigReader, SiddhiAppContext executionPlanContext) { this.optionHolder = optionHolder; this.destination = optionHolder.getOrCreateOption(DESTINATION, null); this.jmsStaticProperties = initJMSProperties(); this.executorService = executionPlanContext.getExecutorService(); }
@Override public void mapAndSend(Event[] events, OptionHolder optionHolder, TemplateBuilder payloadTemplateBuilder, SinkListener sinkListener) { if (this.payloadTemplateBuilder != null) { for (Event event : events) { sinkListener.publish(payloadTemplateBuilder.build(event)); } } else { for (Event event : events) { sinkListener.publish(constructDefaultMapping(event)); } } }
/** * The initialization method for {@link Source}, will be called before other methods. It used to validate * all configurations and to get initial values. * @param sourceEventListener After receiving events, the source should trigger onEvent() of this listener. * Listener will then pass on the events to the appropriate mappers for processing . * @param optionHolder Option holder containing static configuration related to the {@link Source} * @param configReader ConfigReader is used to read the {@link Source} related system configuration. * @param siddhiAppContext the context of the {@link org.wso2.siddhi.query.api.SiddhiApp} used to get Siddhi * related utility functions. */ @Override public void init(SourceEventListener sourceEventListener, OptionHolder optionHolder, String[] requestedTransportPropertyNames, ConfigReader configReader, SiddhiAppContext siddhiAppContext) { this.sourceEventListener = sourceEventListener; this.optionHolder = optionHolder; streamId = optionHolder.validateAndGetStaticValue("wso2.stream.id", null); }
@Override protected void init(StreamDefinition outputStreamDefinition, OptionHolder optionHolder, ConfigReader sinkConfigReader, SiddhiAppContext siddhiAppContext) { kafkaConnect = optionHolder.validateAndGetStaticValue(KAFKA_BROKER_LIST); optionalConfigs = optionHolder.validateAndGetStaticValue(KAFKA_OPTIONAL_CONFIGURATION_PROPERTIES, null); topicOption = optionHolder.validateAndGetOption(KAFKA_PUBLISH_TOPIC); partitionOption = optionHolder.getOrCreateOption(KAFKA_PARTITION_NO, null); executorService = siddhiAppContext.getScheduledExecutorService(); }
public void getAccessToken(DynamicOptions dynamicOptions, String encodedAuth, String tokenURL) { this.tokenURL = tokenURL; HttpsClient httpsClient = new HttpsClient(); if (!HttpConstants.EMPTY_STRING.equals(oauthUsername) && !HttpConstants.EMPTY_STRING.equals(oauthUserPassword)) { httpsClient.getPasswordGrantAccessToken(tokenURL, clientStoreFile, clientStorePass, oauthUsername, oauthUserPassword, encodedAuth); } else if (!HttpConstants.EMPTY_STRING.equals(refreshToken.getValue(dynamicOptions)) || !accessTokenCache.getRefreshtoken(encodedAuth).equals(HttpConstants.EMPTY_STRING)) { httpsClient.getRefreshGrantAccessToken(tokenURL, clientStoreFile, clientStorePass, encodedAuth, refreshToken.getValue(dynamicOptions)); } else { httpsClient.getClientGrantAccessToken(tokenURL, clientStoreFile, clientStorePass, encodedAuth); } }
@Override public void mapAndSend(Event event, OptionHolder optionHolder, TemplateBuilder payloadTemplateBuilder, SinkListener sinkListener) { if (this.payloadTemplateBuilder != null) { sinkListener.publish(payloadTemplateBuilder.build(event)); } else { sinkListener.publish(constructDefaultMapping(event)); } }
@Override public void disconnect() { if (consumerKafkaGroup != null) { consumerKafkaGroup.shutdown(); LOG.info("Kafka Adapter disconnected for topic(s): " + optionHolder.validateAndGetStaticValue(ADAPTOR_SUBSCRIBER_TOPIC)); } }
/** * This method will be called when events need to be published via this sink * * @param payload payload of the event based on the supported event class exported by the extensions * @param dynamicOptions holds the dynamic options of this sink and Use this object to obtain dynamic options. * @throws ConnectionUnavailableException if end point is unavailable the ConnectionUnavailableException thrown * such that the system will take care retrying for connection */ @Override public void publish(Object payload, DynamicOptions dynamicOptions) throws ConnectionUnavailableException { String headers = httpHeaderOption.getValue(dynamicOptions); List<Header> headersList = HttpSinkUtil.getHeaders(headers); String messageId = messageIdOption.getValue(dynamicOptions); String contentType = HttpSinkUtil.getContentType(mapType, headersList); HTTPSourceRegistry. getRequestSource(sourceId).handleCallback(messageId, (String) payload, headersList, contentType); }
@Override public void pause() { if (consumerKafkaGroup != null) { consumerKafkaGroup.pause(); LOG.info("Kafka Adapter paused for topic(s): " + optionHolder.validateAndGetStaticValue (ADAPTOR_SUBSCRIBER_TOPIC)); } }
/** * This method will be called when events need to be published via this sink * * @param payload payload of the event based on the supported event class exported by the extensions * @param dynamicOptions holds the dynamic options of this sink and Use this object to obtain dynamic options. */ @Override public void publish(Object payload, DynamicOptions dynamicOptions) { //get the dynamic parameter String headers = httpHeaderOption.getValue(dynamicOptions); List<Header> headersList = HttpSinkUtil.getHeaders(headers); if (authType.equals(HttpConstants.BASIC_AUTH) || authType.equals(HttpConstants.NO_AUTH)) { sendRequest(payload, dynamicOptions, headersList); } else { sendOauthRequest(payload, dynamicOptions, headersList); } }
@Override public void resume() { if (consumerKafkaGroup != null) { consumerKafkaGroup.resume(); if (LOG.isDebugEnabled()) { LOG.debug("Kafka Adapter resumed for topic(s): " + optionHolder.validateAndGetStaticValue (ADAPTOR_SUBSCRIBER_TOPIC)); } } }
protected void initConnectorRegistry(OptionHolder optionHolder, ConfigReader configReader) { String requestSizeValidationConfigList = optionHolder .validateAndGetStaticValue(HttpConstants.REQUEST_SIZE_VALIDATION_CONFIG, HttpConstants.EMPTY_STRING); String serverBootstrapPropertiesList = optionHolder .validateAndGetStaticValue(HttpConstants.SERVER_BOOTSTRAP_CONFIGURATION, HttpConstants.EMPTY_STRING); this.httpConnectorRegistry = HttpSyncConnectorRegistry.getInstance(); this.httpConnectorRegistry.initBootstrapConfigIfFirst(configReader); this.httpConnectorRegistry.setTransportConfig(serverBootstrapPropertiesList, requestSizeValidationConfigList); }
protected void initConnectorRegistry(OptionHolder optionHolder, ConfigReader configReader) { String requestSizeValidationConfigList = optionHolder .validateAndGetStaticValue(HttpConstants.REQUEST_SIZE_VALIDATION_CONFIG, HttpConstants.EMPTY_STRING); String serverBootstrapPropertiesList = optionHolder .validateAndGetStaticValue(HttpConstants.SERVER_BOOTSTRAP_CONFIGURATION, HttpConstants.EMPTY_STRING); this.httpConnectorRegistry = HttpConnectorRegistry.getInstance(); this.httpConnectorRegistry.initBootstrapConfigIfFirst(configReader); this.httpConnectorRegistry.setTransportConfig(serverBootstrapPropertiesList, requestSizeValidationConfigList); }
protected void initSource(SourceEventListener sourceEventListener, OptionHolder optionHolder, String[] requestedTransportPropertyNames, ConfigReader configReader, SiddhiAppContext siddhiAppContext) { super.initSource(sourceEventListener, optionHolder, requestedTransportPropertyNames, configReader, siddhiAppContext); this.sourceId = optionHolder.validateAndGetStaticValue(HttpConstants.SOURCE_ID); this.connectionTimeout = Long.parseLong( optionHolder.validateAndGetStaticValue(HttpConstants.CONNECTION_TIMEOUT, "120000")); siddhiAppName = siddhiAppContext.getName(); }
@Override protected void init(StreamDefinition outputStreamDefinition, OptionHolder optionHolder, ConfigReader sinkConfigReader, SiddhiAppContext siddhiAppContext) { super.init(outputStreamDefinition, optionHolder, sinkConfigReader, siddhiAppContext); topic = optionHolder.validateAndGetStaticValue(KAFKA_PUBLISH_TOPIC); partitionNo = Integer.parseInt(optionHolder.validateAndGetStaticValue(KAFKA_PARTITION_NO, "0")); if (bootstrapServers.split(",").length != 2) { throw new SiddhiAppValidationException("There should be two servers listed in 'bootstrap.servers' " + "configuration"); } }