You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@edgent.apache.org by dl...@apache.org on 2016/07/21 13:17:23 UTC
[22/54] [abbrv] [partial] incubator-quarks git commit: add
"org.apache." prefix to edgent package names
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/a129aa16/connectors/mqtt/src/main/java/edgent/connectors/mqtt/MqttConfig.java
----------------------------------------------------------------------
diff --git a/connectors/mqtt/src/main/java/edgent/connectors/mqtt/MqttConfig.java b/connectors/mqtt/src/main/java/edgent/connectors/mqtt/MqttConfig.java
deleted file mode 100644
index 624b08d..0000000
--- a/connectors/mqtt/src/main/java/edgent/connectors/mqtt/MqttConfig.java
+++ /dev/null
@@ -1,588 +0,0 @@
-/*
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
-*/
-package edgent.connectors.mqtt;
-
-import java.nio.charset.StandardCharsets;
-import java.util.Properties;
-
-import org.eclipse.paho.client.mqttv3.MqttClientPersistence;
-import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
-import org.eclipse.paho.client.mqttv3.MqttMessage;
-
-import com.google.gson.JsonObject;
-
-import edgent.function.Consumer;
-import edgent.topology.json.JsonFunctions;
-
-/**
- * MQTT broker connector configuration.
- */
-public class MqttConfig {
- private MqttConnectOptions options = new MqttConnectOptions();
- private String clientId;
- private MqttClientPersistence persistence;
- private long actionTimeToWaitMillis = -1;
- private int idleTimeout;
- private int subscriberIdleReconnectIntervalSec = 60;
-
- /**
- * Create a new configuration from {@link Properties}.
- * <p>
- * There is a property corresponding to each {@code MqttConfig.set<name>()}
- * method. Unless otherwise stated, the property's value is a string
- * of the corresponding method's argument type.
- * Properties not specified yield a configuration value as
- * described by and their corresponding {@code set<name>()}.
- * <p>
- * Properties other than those noted are ignored.
- *
- * <h3>MQTT connector properties</h3>
- * <ul>
- * <li>mqtt.actionTimeToWaitMillis</li>
- * <li>mqtt.cleanSession</li>
- * <li>mqtt.clientId</li>
- * <li>mqtt.connectionTimeoutSec</li>
- * <li>mqtt.idleTimeoutSec</li>
- * <li>mqtt.keepAliveSec</li>
- * <li>mqtt.keyStore - optional. Only used with "ssl:" serverURL when the
- * server is configured for client auth.
- * Path to key store file in JKS format.
- * The first key in the store is used. The key must have the same
- * password as the store if any.
- * If not set, the standard JRE and javax.net.ssl system properties
- * control the SSL behavior.</li>
- * <li>mqtt.keyStorePassword - required if mqtt.keyStore is set.</li>
- * <li>mqtt.password</li>
- * <li>mqtt.persistence</li>
- * <li>mqtt.serverURLs - csv list of MQTT URLs of the form:
- * {@code tcp://<host>:<port>} or
- * {@code ssl://<host>:<port>}
- * </li>
- * <li>mqtt.subscriberIdleReconnectIntervalSec</li>
- * <li>mqtt.trustStore - optional. Only used with "ssl:" serverURL.
- * Path to trust store file in JKS format.
- * If not set, the standard JRE and javax.net.ssl system properties
- * control the SSL behavior.
- * Generally not required if server has a CA-signed certificate.</li>
- * <li>mqtt.trustStorePassword - required if mqtt.trustStore is set</li>
- * <li>mqtt.userName</li>
- * <li>mqtt.will - JSON for with the following properties:
- * <ul>
- * <li>topic - string</li>
- * <li>payload - string for byte[] in UTF8</li>
- * <li>qos - integer</li>
- * <li>retained - boolean</li>
- * </ul>
- * </li>
- * </ul>
- * @param properties properties specifying the configuration.
- *
- * @return the configuration
- * @throws IllegalArgumentException for illegal values
- */
- public static MqttConfig fromProperties(Properties properties) {
- MqttConfig config = new MqttConfig();
- Properties p = properties;
- setConfig(p, "mqtt.actionTimeToWaitMillis",
- val -> config.setActionTimeToWaitMillis(Long.valueOf(val)));
- setConfig(p, "mqtt.cleanSession",
- val -> config.setCleanSession(Boolean.valueOf(val)));
- setConfig(p, "mqtt.clientId",
- val -> config.setClientId(val));
- setConfig(p, "mqtt.connectionTimeoutSec",
- val -> config.setConnectionTimeout(Integer.valueOf(val)));
- setConfig(p, "mqtt.idleTimeoutSec",
- val -> config.setIdleTimeout(Integer.valueOf(val)));
- setConfig(p, "mqtt.keepAliveSec",
- val -> config.setKeepAliveInterval(Integer.valueOf(val)));
- setConfig(p, "mqtt.keyStore",
- val -> config.setKeyStore(val));
- setConfig(p, "mqtt.keyStorePassword",
- val -> config.setKeyStorePassword(val.toCharArray()));
-// paho MqttConnectOptions.setSslProperties() doesn't support this control
-// setConfig(p, "mqtt.keyPassword",
-// val -> config.setKeyPassword(val.toCharArray()));
-// setConfig(p, "mqtt.keyCertificateAlias",
-// val -> config.setKeyCertificateAlias(val));
- setConfig(p, "mqtt.password",
- val -> config.setPassword(val.toCharArray()));
- setConfig(p, "mqtt.persistence",
- val -> config.setPersistence(newPersistenceProvider(val)));
- setConfig(p, "mqtt.serverURLs",
- val -> config.setServerURLs(val.split(",")));
- setConfig(p, "mqtt.subscriberIdleReconnectIntervalSec",
- val -> config.setSubscriberIdleReconnectInterval(Integer.valueOf(val)));
- setConfig(p, "mqtt.trustStore",
- val -> config.setTrustStore(val));
- setConfig(p, "mqtt.trustStorePassword",
- val -> config.setTrustStorePassword(val.toCharArray()));
- setConfig(p, "mqtt.userName",
- val -> config.setUserName(val));
- setConfig(p, "mqtt.will", val -> {
- JsonObject jo = JsonFunctions.fromString().apply(val);
- String topic = jo.get("topic").getAsString();
- byte[] payload = jo.get("payload").getAsString().getBytes(StandardCharsets.UTF_8);
- int qos = jo.get("qos").getAsInt();
- boolean retained = jo.get("retained").getAsBoolean();
- config.setWill(topic, payload, qos, retained);
- });
- return config;
- }
-
- private static void setConfig(Properties p, String name, Consumer<String> setter) {
- try {
- String value = p.getProperty(name);
- if (value != null) {
- setter.accept(value);
- }
- } catch (Exception e) {
- throw new IllegalArgumentException(name, e);
- }
- }
-
- private static MqttClientPersistence newPersistenceProvider(String className) {
- Class<?> clazz = null;
- try {
- clazz = Class.forName(className);
- return (MqttClientPersistence) clazz.newInstance();
- }
- catch (Exception e) {
- throw new IllegalArgumentException(e.getLocalizedMessage(), e);
- }
- }
-
- /**
- * Create a new configuration.
- */
- public MqttConfig() { }
-
- /**
- * Create a new configuration.
- * @param serverURL the MQTT broker's URL
- * @param clientId the MQTT client's id. Auto-generated if null.
- */
- public MqttConfig(String serverURL, String clientId) {
- options.setServerURIs(new String[] {serverURL});
- this.clientId = clientId;
- }
-
- /**
- * Get the connection Client Id.
- * @return the value
- */
- public String getClientId() {
- return clientId;
- }
-
- /**
- * Get the maximum time to wait for an action (e.g., publish message) to complete.
- * @return the value
- */
- public long getActionTimeToWaitMillis() {
- return actionTimeToWaitMillis;
- }
-
- /**
- * Get the QoS 1 and 2 in-flight message persistence handler.
- * @return the value
- */
- public MqttClientPersistence getPersistence() {
- return persistence;
- }
-
- /**
- * Get the connection timeout.
- * @return the value
- */
- public int getConnectionTimeout() {
- return options.getConnectionTimeout();
- }
-
- /**
- * Get the idle connection timeout.
- * @return the value
- */
- public int getIdleTimeout() {
- return idleTimeout;
- }
-
- /**
- * Get the subscriber idle reconnect interval.
- * @return the value
- */
- public int getSubscriberIdleReconnectInterval() {
- return subscriberIdleReconnectIntervalSec;
- }
-
- /**
- * Get the connection Keep alive interval.
- * @return the value
- */
- public int getKeepAliveInterval() {
- return options.getKeepAliveInterval();
- }
-
- /**
- * Get the MQTT Server URLs
- * @return the value
- */
- public String[] getServerURLs() {
- return options.getServerURIs();
- }
-
- /**
- * Get a Last Will and Testament message's destination topic.
- * @return the value. may be null.
- */
- public String getWillDestination() {
- return options.getWillDestination();
- }
-
- /**
- * Get a Last Will and Testament message's payload.
- * @return the value. may be null.
- */
- public byte[] getWillPayload() {
- MqttMessage msg = options.getWillMessage();
- return msg==null ? null : msg.getPayload();
- }
-
- /**
- * Get a Last Will and Testament message's QOS.
- * @return the value.
- */
- public int getWillQOS() {
- MqttMessage msg = options.getWillMessage();
- return msg==null ? 0 : msg.getQos();
- }
-
- /**
- * Get a Last Will and Testament message's "retained" setting.
- * @return the value.
- */
- public boolean getWillRetained() {
- MqttMessage msg = options.getWillMessage();
- return msg==null ? false : msg.isRetained();
- }
-
- /**
- * Get the clean session setting.
- * @return the value
- */
- public boolean isCleanSession() {
- return options.isCleanSession();
- }
-
- /**
- * Get the the password to use for authentication with the server.
- * @return the value
- */
- public char[] getPassword() {
- return options.getPassword();
- }
-
- /**
- * Get the username to use for authentication with the server.
- * @return the value
- */
- public String getUserName() {
- return options.getUserName();
- }
-
- /**
- * Connection Client Id.
- * <p>
- * Optional. default null: a clientId is auto-generated.
- * @param clientId the client id
- */
- public void setClientId(String clientId) {
- this.clientId = clientId;
- }
-
- /**
- * Maximum time to wait for an action (e.g., publish message) to complete.
- * <p>
- * Optional. default: -1 no timeout. 0 also means no timeout.
- * @param actionTimeToWaitMillis the time to wait in milliseconds
- */
- public void setActionTimeToWaitMillis(long actionTimeToWaitMillis) {
- this.actionTimeToWaitMillis = actionTimeToWaitMillis;
- }
-
- /**
- * QoS 1 and 2 in-flight message persistence.
- * <p>
- * optional. default: use memory persistence.
- * @param persistence the persistence implementation
- */
- public void setPersistence(MqttClientPersistence persistence) {
- this.persistence = persistence;
- }
-
- /**
- * Clean Session.
- * <p>
- * Qptional. default: true.
- * @param cleanSession the clean session value
- */
- public void setCleanSession(boolean cleanSession) {
- options.setCleanSession(cleanSession);
- }
-
- /**
- * Connection timeout.
- * Optional. 0 disables the timeout / blocks until connected. default: 30 seconds.
- * @param connectionTimeoutSec the timeout in seconds
- */
- public void setConnectionTimeout(int connectionTimeoutSec) {
- options.setConnectionTimeout(connectionTimeoutSec);
- }
-
- /**
- * Idle connection timeout.
- * Optional. 0 disables idle connection disconnect. default: 0 seconds (disabled).
- * <p>
- * Following an idle disconnect, the connector will automatically
- * reconnect when it receives a new tuple to publish.
- * If the connector is subscribing to topics, it will also reconnect
- * as per {@link #setSubscriberIdleReconnectInterval(int)}.
- * <p>
- * @param idleTimeoutSec the timeout in seconds
- * @see #setSubscriberIdleReconnectInterval(int)
- */
- public void setIdleTimeout(int idleTimeoutSec) {
- if (idleTimeoutSec < 0)
- idleTimeoutSec = 0;
- this.idleTimeout = idleTimeoutSec;
- }
-
- /**
- * Subscriber idle reconnect interval.
- * <p>
- * Following an idle disconnect, if the connector is subscribing to topics,
- * it will reconnect after the specified interval.
- * Optional. default: 60 seconds.
- * @param seconds the interval in seconds
- */
- public void setSubscriberIdleReconnectInterval(int seconds) {
- if (seconds < 0)
- seconds = 0;
- subscriberIdleReconnectIntervalSec = seconds;
- }
-
- /**
- * Connection Keep alive.
- * <p>
- * Optional. 0 disables keepalive processing. default: 60 seconds.
- * @param keepAliveSec the interval in seconds
- */
- public void setKeepAliveInterval(int keepAliveSec) {
- options.setKeepAliveInterval(keepAliveSec);
- }
-
- /**
- * MQTT Server URLs
- * <p>
- * Required. Must be an array of one or more MQTT server URLs.
- * When connecting, the first URL that successfully connects is used.
- * @param serverUrls the URLs
- */
- public void setServerURLs(String[] serverUrls) {
- options.setServerURIs(serverUrls);
- }
-
- /**
- * Last Will and Testament.
- * <p>
- * optional. default: no last-will-and-testament.
- * @param topic topic to publish to
- * @param payload the last-will-and-testament message value
- * @param qos the quality of service to use to publish the message
- * @param retained true to retain the message across connections
- */
- public void setWill(String topic, byte[] payload, int qos, boolean retained) {
- options.setWill(topic, payload, qos, retained);
- }
-
- /**
- * Set the password to use for authentication with the server.
- * Optional. default: null.
- * @param password the password
- */
- public void setPassword(char[] password) {
- options.setPassword(password);
- }
-
- /**
- * Set the username to use for authentication with the server.
- * Optional. default: null.
- * @param userName the user name
- */
- public void setUserName(String userName) {
- options.setUserName(userName);
- }
-
- /**
- * @param name option name
- * @param value option value. null to unset.
- */
- private void setSslOption(String name, String value) {
- Properties props = options.getSSLProperties();
- if (props == null)
- props = new Properties();
- if (value == null)
- props.remove(name);
- else
- props.setProperty(name, value);
- options.setSSLProperties(props);
- }
-
- /**
- * @param name option name
- * @return option's value. null if not set.
- */
- private String getSslOption(String name) {
- Properties props = options.getSSLProperties();
- return props == null ? null : props.getProperty(name);
- }
-
- /**
- * Set the SSL trust store path.
- * <p>
- * Only used with "ssl:" serverURL.
- * Path to trust store file in JKS format.
- * If not set, the standard JRE and javax.net.ssl system properties
- * control the SSL behavior.
- * Generally not required if server has a CA-signed certificate.
- * @param path the path. null to unset.
- */
- public void setTrustStore(String path) {
- setSslOption("com.ibm.ssl.trustStore", path);
- }
-
- /**
- * Get the SSL trust store path.
- * @return the path. null if not set.
- */
- public String getTrustStore() {
- return getSslOption("com.ibm.ssl.trustStore");
- }
-
- /**
- * Set the SSL trust store password.
- * <p>
- * Required if the trust store path is set.
- *
- * @param password the password
- */
- public void setTrustStorePassword(char[] password) {
- setSslOption("com.ibm.ssl.trustStorePassword", new String(password));
- }
-
- /**
- * Get the SSL trust store path password.
- * @return the password. null if not set.
- */
- public char[] getTrustStorePassword() {
- String s = getSslOption("com.ibm.ssl.trustStorePassword");
- return s == null ? null : s.toCharArray();
- }
-
- /**
- * Set the SSL key store path.
- * <p>
- * Only used with "ssl:" serverURL when the server is configured for
- * client auth.
- * Path to trust store file in JKS format.
- * If not set, the standard JRE and javax.net.ssl system properties
- * control the SSL behavior.
- * @param path the path. null to unset.
- */
- public void setKeyStore(String path) {
- setSslOption("com.ibm.ssl.keyStore", path);
- }
-
- /**
- * Get the SSL trust store path.
- * @return the path. null if not set.
- */
- public String getKeyStore() {
- return getSslOption("com.ibm.ssl.keyStore");
- }
-
- /**
- * Set the SSL key store password.
- * <p>
- * Required if the key store path is set.
- *
- * @param password the password. null to unset.
- */
- public void setKeyStorePassword(char[] password) {
- setSslOption("com.ibm.ssl.keyStorePassword", new String(password));
- }
-
- /**
- * Get the SSL key store path password.
- * @return the password. null if not set.
- */
- public char[] getKeyStorePassword() {
- String s = getSslOption("com.ibm.ssl.keyStorePassword");
- return s == null ? null : s.toCharArray();
- }
-
-// paho MqttConnectOptions.setSslProperties() doesn't support this control
-// /**
-// * Set the SSL key password.
-// * <p>
-// * Defaults to using the key store password if not set.
-// *
-// * @param password the password. null to unset.
-// */
-// public void setKeyPassword(char[] password) {
-// setSslOption("com.ibm.ssl.XXXX-NO-SUCH-KEY-XXXX.keyPassword", new String(password));
-// }
-//
-// public char[] getKeyPassword() {
-// String s = getSslOption("com.ibm.ssl.XXXX-NO-SUCH-KEY-XXXX.keyPassword");
-// return s == null ? null : s.toCharArray();
-// }
-
- // paho MqttConnectOptions.setSslProperties() doesn't support this control
-// /**
-// * Set the SSL key certificate alias.
-// * <p>
-// * Defaults to using "default" if not set.
-// * @param alias the alias. null to unset.
-// */
-// public void setKeyCertificateAlias(String alias) {
-// setSslOption("com.ibm.ssl.XXXX-NO-SUCH-KEY-XXXX.keyCertificateAlias", alias);
-// }
-//
-// public String getKeyCertificateAlias() {
-// return getSslOption("com.ibm.ssl.XXXX-NO-SUCH-KEY-XXXX.keyCertificateAlias");
-// }
-
- /**
- * INTERNAL USE ONLY.
- * @return object
- */
- public Object options() {
- return options;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/a129aa16/connectors/mqtt/src/main/java/edgent/connectors/mqtt/MqttStreams.java
----------------------------------------------------------------------
diff --git a/connectors/mqtt/src/main/java/edgent/connectors/mqtt/MqttStreams.java b/connectors/mqtt/src/main/java/edgent/connectors/mqtt/MqttStreams.java
deleted file mode 100644
index f8dee80..0000000
--- a/connectors/mqtt/src/main/java/edgent/connectors/mqtt/MqttStreams.java
+++ /dev/null
@@ -1,221 +0,0 @@
-/*
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
-*/
-package edgent.connectors.mqtt;
-
-import java.nio.charset.StandardCharsets;
-
-import edgent.connectors.mqtt.runtime.MqttConnector;
-import edgent.connectors.mqtt.runtime.MqttPublisher;
-import edgent.connectors.mqtt.runtime.MqttSubscriber;
-import edgent.function.BiFunction;
-import edgent.function.Function;
-import edgent.function.Supplier;
-import edgent.topology.TSink;
-import edgent.topology.TStream;
-import edgent.topology.Topology;
-
-/**
- * {@code MqttStreams} is a connector to a MQTT messaging broker
- * for publishing and subscribing to topics.
- * <p>
- * For more information about MQTT see <a href="http://mqtt.org">http://mqtt.org</a>
- * <p>
- * The connector exposes all MQTT capabilities:
- * <ul>
- * <li>multiple server URLs using tcp or ssl</li>
- * <li>connection ClientId control</li>
- * <li>connection username and password based authentication</li>
- * <li>TODO SSL connection client authentication Q:expose just key/trust store path/pw or whole setSSLProperties capability? Related: expose setSocketFactory?</li>
- * <li>connection clean session control</li>
- * <li>connection keepalive control</li>
- * <li>operation/action timeout control</li>
- * <li>client last will and testament</li>
- * <li>connection in-flight message persistence control</li>
- * <li>per-published message control of topic, quality of service, payload and retain value</li>
- * <li>subscription topicFilter and maximum quality of service control</li>
- * <li>TODO multiple subscription topicFilters</li>
- * <li>access to received message's topic and payload.
- * Omitting until there's a clear demand for it: the received msg's isRetained, qos and isDuplicate values.
- * <li>TODO dynamic server URLs control, operation timeout, keepalive control</li>
- * <li>TODO dynamic subscription list control</li>
- * <li>robust connection management / reconnected</li>
- * <li>TODO fix: client's aren't gracefully disconnecting (their close() isn't getting called) issue#64</li>
- * </ul>
- * <p>
- * Sample use:
- * <pre>{@code
- * Topology t = ...;
- * String url = "tcp://localhost:1883";
- * MqttStreams mqtt = new MqttStreams(t, url);
- * TStream<String> s = top.constants("one", "two", "three");
- * mqtt.publish(s, "myTopic", 0);
- * TStream<String> rcvd = mqtt.subscribe("someTopic", 0);
- * rcvd.print();
- * }</pre>
- * <P>
- * {@code publish()} can be called zero or more times.
- * {@code subscribe()} can be called at most once.
- * <p>
- * See {@link MqttConfig} for all configuration items.
- * <p>
- * Messages are delivered with the specified Quality of Service.
- * TODO adjust the QoS-1 and 2 descriptions based on the fact that we only
- * supply a MemoryPersistence class under the covers.
- * <ul>
- * <li>Quality of Service 0 - a message should be delivered at most once
- * (zero or one times) - "fire and forget".
- * This is the fastest QoS but should only be used for messages which
- * are not valuable.</li>
- * <li>Quality of Service 1 - a message should be delivered at least once
- * (zero or more times).
- * The message will be acknowledged across the network.</li>
- * <li>Quality of Service 2 = a message should be delivered once.
- * Delivery is subject to two-phase acknowledgment across the network.</li>
- * </ul>
- * For {@code subscribe()}, the QoS is the maximum QoS used for a message.
- * If a message was published with a QoS less then the subscribe's QoS,
- * the message will be received with the published QoS,
- * otherwise it will be received with the subscribe's QoS.
- */
-public class MqttStreams {
-
- private final MqttConnector connector;
- private final Topology topology;
- private int subscribeCnt;
-
- /**
- * Create a connector to the specified server.
- * <p>
- * A convenience function.
- * Connecting to the server occurs after the
- * topology is submitted for execution.
- *
- * @param topology the connector's associated {@code Topology}.
- * @param url URL of MQTT server.
- * @param clientId the connector's MQTT clientId. auto-generated if null.
- */
- public MqttStreams(Topology topology, String url, String clientId) {
- this.topology = topology;
- MqttConfig config = new MqttConfig();
- config.setServerURLs(new String[] {url});
- config.setClientId(clientId);
- connector = new MqttConnector(() -> config);
- }
-
- /**
- * Create a connector with the specified configuration.
- * <p>
- * Connecting to the server occurs after the
- * topology is submitted for execution.
- *
- * @param topology the Topology to add to
- * @param config {@link MqttConfig} supplier.
- */
- public MqttStreams(Topology topology, Supplier<MqttConfig> config) {
- this.topology = topology;
-
- connector = new MqttConnector(config);
- }
-
- /**
- * Publish a stream's tuples as MQTT messages.
- * <p>Each tuple is published as an MQTT message with
- * the supplied functions providing the message topic, payload
- * and QoS. The topic and QoS can be generated based upon the tuple.
- *
- * @param <T> Tuple type
- * @param stream Stream to be published.
- * @param topic function to supply the message's topic.
- * @param payload function to supply the message's payload.
- * @param qos function to supply the message's delivery Quality of Service.
- * @param retain function to supply the message's retain value
- * @return TSink sink element representing termination of this stream.
- */
- public <T> TSink<T> publish(TStream<T> stream, Function<T, String> topic, Function<T, byte[]> payload,
- Function<T, Integer> qos, Function<T, Boolean> retain) {
- return stream.sink(new MqttPublisher<T>(connector, payload, topic, qos, retain));
- }
-
- /**
- * Publish a {@code TStream<String>} stream's tuples as MQTT messages.
- * <p>
- * A convenience function.
- * The payload of each message is the String tuple's value serialized as UTF-8.
- *
- * @param stream Stream to be published.
- * @param topic the fixed topic.
- * @param qos the fixed delivery Quality of Service.
- * @param retain the fixed retain value.
- * @return TSink sink element representing termination of this stream.
- */
- public TSink<String> publish(TStream<String> stream, String topic, int qos, boolean retain) {
- return publish(stream, tuple -> topic, tuple -> tuple.getBytes(StandardCharsets.UTF_8), tuple -> qos, tuple -> retain);
- }
-
- /**
- * Subscribe to the MQTT topic(s) and create a stream of tuples of type {@code T}.
- * @param <T> Tuple type
- * @param topicFilter the topic(s) to subscribe to.
- * @param qos the maximum Quality of Service to use.
- * @param message2Tuple function to convert {@code (topic, payload)} to
- * a tuple of type {@code T}
- * @return {@code TStream<T>}
- */
- public <T> TStream<T> subscribe(String topicFilter, int qos, BiFunction<String, byte[], T> message2Tuple) {
- addSubscribe();
- return topology().events(new MqttSubscriber<T>(connector, topicFilter, qos, message2Tuple));
- }
-
- /**
- * Subscribe to the MQTT topic(s) and create a {@code TStream<String>}.
- * <p>
- * A convenience function.
- * Each message's payload is expected/required to be a UTF-8 encoded string.
- * Only the converted payload is present the generated tuple.
- *
- * @param <T> Tuple type
- * @param topicFilter the topic(s) to subscribe to.
- * @param qos the maximum Quality of Service to use.
- * @return {@code TStream<String>}
- * @see #publish(TStream, String, int, boolean)
- */
- public <T> TStream<String> subscribe(String topicFilter, int qos) {
- addSubscribe();
- return topology().events(new MqttSubscriber<String>(connector, topicFilter, qos,
- (topic, payload) -> new String(payload, StandardCharsets.UTF_8)));
- }
-
- private void addSubscribe() {
- // This is in recognition of our current code that doesn't support >1 subscribe().
- // The issue is MqttClient only supports a single callback and right now
- // each MqttSubscriber registers itself... so only the last one wins,
- // and the last subscribe() rcvs all of the msgs and the others rcv none.
- // Workaround: use multiple connectors.
- if (++subscribeCnt > 1)
- throw new IllegalStateException("An MqttStreams instance supports at most one subscribe()");
- }
-
- /**
- * Get the {@link edgent.topology.Topology} the connector is associated with.
- * @return the value
- */
- public Topology topology() {
- return topology;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/a129aa16/connectors/mqtt/src/main/java/edgent/connectors/mqtt/iot/MqttDevice.java
----------------------------------------------------------------------
diff --git a/connectors/mqtt/src/main/java/edgent/connectors/mqtt/iot/MqttDevice.java b/connectors/mqtt/src/main/java/edgent/connectors/mqtt/iot/MqttDevice.java
deleted file mode 100644
index 0693a7d..0000000
--- a/connectors/mqtt/src/main/java/edgent/connectors/mqtt/iot/MqttDevice.java
+++ /dev/null
@@ -1,279 +0,0 @@
-/*
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
-*/
-package edgent.connectors.mqtt.iot;
-
-import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Properties;
-import java.util.Set;
-
-import com.google.gson.JsonObject;
-
-import edgent.connectors.iot.IotDevice;
-import edgent.connectors.mqtt.MqttConfig;
-import edgent.connectors.mqtt.MqttStreams;
-import edgent.function.Function;
-import edgent.function.UnaryOperator;
-import edgent.topology.TSink;
-import edgent.topology.TStream;
-import edgent.topology.Topology;
-import edgent.topology.json.JsonFunctions;
-
-/**
- * An MQTT based Edgent {@link IotDevice} connector.
- * <p>
- * The MQTT {@code IotDevice} is an abstraction on top of
- * the {@link MqttStreams} connector.
- * <p>
- * The connector doesn't presume a particular pattern for
- * Device MQTT "event" topic and "command" topics though default
- * patterns are provided.
- * <p>
- * Connector configuration Properties fall into two categories:
- * <ul>
- * <li>MQTT Device abstraction properties</li>
- * <li>Base MQTT connector properties - see {@link MqttConfig#fromProperties(Properties)}
- * </ul>
- *
- * <h3>Device properties</h3>
- * <ul>
- * <li>mqttDevice.id - Required. An identifier that uniquely identifies
- * the device in the device event and device command MQTT topic namespaces.
- * </li>
- * <li>mqttDevice.topic.prefix - A optional prefix that by default is used when
- * composing device event and command MQTT topics, and the client's MQTT
- * clientId. The default is no prefix.</li>
- * <li>mqttDevice.event.topic.pattern - Optional. The topic pattern used
- * for MQTT device event topics.
- * Defaults to {@code {mqttDevice.topic.prefix}id/{mqttDevice.id}/evt/{EVENTID}/fmt/json}
- * The pattern must include {EVENTID} and must end with "/fmt/json".
- * </li>
- * <li>mqttDevice.command.topic.pattern - Optional. The topic pattern used
- * for MQTT device command topics.
- * Defaults to {@code {mqttDevice.topic.prefix}id/{mqttDevice.id}/cmd/{COMMAND}/fmt/json}
- * The pattern must include {COMMAND} and must end with "/fmt/json".
- * </li>
- * <li>mqttDevice.command.qos - An optional MQTT QoS value for commands. Defaults to 0.</li>
- * <li>mqttDevice.events.retain - Optional MQTT "retain" behavior for published events. Defaults to false.</li>
- * <li>mqttDevice.mqtt.clientId - Optional value to use for the MQTT clientId.
- * Defaults to {mqttDevice.topic.prefix}id/{mqttDevice.id}.</li>
- * </ul>
- * Sample use:
- * <pre>{@code
- * // assuming a properties file containing at least:
- * // mqttDevice.id=012345678
- * // mqtt.serverURLs=tcp://myMqttBrokerHost:1883
- *
- * String propsPath = <path to properties file>;
- * Properties properties = new Properties();
- * properties.load(Files.newBufferedReader(new File(propsPath).toPath()));
-
- * Topology t = new DirectProvider();
- * MqttDevice mqttDevice = new MqttDevice(t, properties);
- *
- * // publish JSON "status" device event tuples every hour
- * TStream<JsonObject> myStatusEvents = t.poll(myGetStatusAsJson(), 1, TimeUnit.HOURS);
- * mqttDevice.events(myStatusEvents, "status", QoS.FIRE_AND_FORGET);
- *
- * // handle a device command. In this example the payload is expected
- * // to be JSON and have a "value" property containing the new threshold.
- * mqttDevice.command("setSensorThreshold")
- * .sink(json -> setSensorThreshold(json.get(CMD_PAYLOAD).getAsJsonObject().get("value").getAsString());
- * }</pre>
- */
-public class MqttDevice implements IotDevice {
-
- private final Topology topology;
- private final String deviceId;
- private String topicPrefix = "";
- private String clientId = "{mqttDevice.topic.prefix}id/{mqttDevice.id}";
- private String evtTopic = "{mqttDevice.topic.prefix}id/{mqttDevice.id}/evt/{EVENTID}/fmt/json";
- private String cmdTopic = "{mqttDevice.topic.prefix}id/{mqttDevice.id}/cmd/{COMMAND}/fmt/json";
- private int commandQoS = 0;
- private boolean retainEvents = false;
- private final MqttConfig mqttConfig;
- private final MqttStreams connector;
- private TStream<JsonObject> commandStream;
-
- /**
- * Create an MqttDevice connector.
- * <p>
- * All configuration information comes from {@code properties}.
- *
- * @param topology topology to add the connector to.
- * @param properties connector properties.
- */
- public MqttDevice(Topology topology, Properties properties) {
- this(topology, properties, null);
- }
-
- /**
- * Create an MqttDevice connector.
- * <p>
- * Uses {@code mattConfig} for the base MQTT connector configuration
- * and uses {@code properties} only for MQTT Device properties.
- *
- * @param topology topology to add the connector to.
- * @param properties connector properties. Properties beyond those
- * noted in the Device properties section above are ignored.
- * @param mqttConfig base MQTT configuration. may be null.
- */
- public MqttDevice(Topology topology, Properties properties, MqttConfig mqttConfig) {
- this.topology = topology;
- this.deviceId = properties.getProperty("mqttDevice.id");
- if (deviceId == null || deviceId.isEmpty())
- throw new IllegalArgumentException("mqttDevice.id");
- String cqos = properties.getProperty("mqttDevice.command.qos", Integer.valueOf(commandQoS).toString());
- commandQoS = Integer.valueOf(cqos);
- String eretain = properties.getProperty("mqttDevice.events.retain", Boolean.valueOf(retainEvents).toString());
- retainEvents = Boolean.valueOf(eretain);
- topicPrefix = properties.getProperty("mqttDevice.topic.prefix", topicPrefix);
- clientId = properties.getProperty("mqttDevice.mqtt.clientId", clientId);
- evtTopic = properties.getProperty("mqttDevice.event.topic.pattern", evtTopic);
- if (!evtTopic.endsWith("/fmt/json"))
- throw new IllegalArgumentException("mqttDevice.event.topic.pattern");
- cmdTopic = properties.getProperty("mqttDevice.command.topic.pattern", cmdTopic);
- if (!cmdTopic.endsWith("/fmt/json"))
- throw new IllegalArgumentException("mqttDevice.command.topic.pattern");
- initVars();
- if (mqttConfig == null) {
- mqttConfig = MqttConfig.fromProperties(properties);
- mqttConfig.setClientId(clientId);
- }
- this.mqttConfig = mqttConfig;
- this.connector = new MqttStreams(topology, () -> this.mqttConfig);
- }
-
- private void initVars() {
- clientId = clientId
- .replace("{mqttDevice.topic.prefix}", topicPrefix)
- .replace("{mqttDevice.id}", deviceId);
- evtTopic = evtTopic
- .replace("{mqttDevice.topic.prefix}", topicPrefix)
- .replace("{mqttDevice.id}", deviceId);
- cmdTopic = cmdTopic
- .replace("{mqttDevice.topic.prefix}", topicPrefix)
- .replace("{mqttDevice.id}", deviceId);
- }
-
- /**
- * Get the MQTT topic for an device event.
- * @param eventId the event id.
- * if null, returns a topic filter for all of the device's events.
- * @return the topic
- */
- public String eventTopic(String eventId) {
- if (eventId == null) {
- eventId = "+"; // retain the trailing fmt/json
- }
- return evtTopic.replace("{EVENTID}", eventId);
- }
-
- /**
- * Get the MQTT topic for a command.
- * @param command the command id.
- * if null, returns a topic filter for all of the device's commands.
- * @return the topic
- */
- public String commandTopic(String command) {
- if (command == null) {
- command = "+"; // retain the trailing fmt/json
- }
- return cmdTopic.replace("{COMMAND}", command);
- }
-
- /**
- * Get the device's {@link MqttConfig}
- * @return the config
- */
- public MqttConfig getMqttConfig() {
- return mqttConfig;
- }
-
- @Override
- public TSink<JsonObject> events(TStream<JsonObject> stream, Function<JsonObject, String> eventId,
- UnaryOperator<JsonObject> payload, Function<JsonObject, Integer> qos) {
-
- Function<JsonObject, String> topic = jo -> eventTopic(eventId.apply(jo));
- Function<JsonObject,byte[]> payloadFn =
- jo -> JsonFunctions.asBytes().apply(payload.apply(jo));
-
- return connector.publish(stream, topic, payloadFn, qos, jo -> retainEvents);
- }
-
- @Override
- public TSink<JsonObject> events(TStream<JsonObject> stream, String eventId, int qos) {
- return events(stream, jo -> eventId, jo -> jo, jo -> qos);
- }
-
- @Override
- public TStream<JsonObject> commands(String... commands) {
- TStream<JsonObject> all = allCommands();
-
- if (commands.length != 0) {
- Set<String> uniqueCommands = new HashSet<>();
- uniqueCommands.addAll(Arrays.asList(commands));
- all = all.filter(jo -> uniqueCommands.contains(jo.get(CMD_ID).getAsString()));
- }
-
- return all;
- }
-
- private TStream<JsonObject> allCommands() {
- if (commandStream == null) {
- String topicFilter = commandTopic(null);
- commandStream = connector.subscribe(topicFilter, commandQoS,
- (topic, payload) -> {
- JsonObject jo = new JsonObject();
- jo.addProperty(CMD_ID, extractCmd(topic));
- jo.addProperty(CMD_TS, System.currentTimeMillis());
- String fmt = extractCmdFmt(topic);
- jo.addProperty(CMD_FORMAT, fmt);
- if ("json".equals(fmt)) {
- jo.add(CMD_PAYLOAD, JsonFunctions.fromBytes().apply(payload));
- }
- else {
- jo.addProperty(CMD_PAYLOAD, new String(payload, StandardCharsets.UTF_8));
- }
- return jo;
- })
- .tag("allDeviceCmds");
- }
- return commandStream;
- }
-
- private String extractCmd(String topic) {
- String prefix = cmdTopic.substring(0, cmdTopic.indexOf("{COMMAND}"));
- String cmd = topic.substring(prefix.length());
- int endCmd = cmd.indexOf('/');
- if (endCmd != -1)
- cmd = cmd.substring(0, endCmd);
- return cmd;
- }
-
- private String extractCmdFmt(String cmdTopic) {
- return cmdTopic.endsWith("/fmt/json") ? "json" : "string";
- }
-
- @Override
- public Topology topology() {
- return topology;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/a129aa16/connectors/mqtt/src/main/java/edgent/connectors/mqtt/iot/package-info.java
----------------------------------------------------------------------
diff --git a/connectors/mqtt/src/main/java/edgent/connectors/mqtt/iot/package-info.java b/connectors/mqtt/src/main/java/edgent/connectors/mqtt/iot/package-info.java
deleted file mode 100644
index 8ffd440..0000000
--- a/connectors/mqtt/src/main/java/edgent/connectors/mqtt/iot/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
-*/
-/**
- * An MQTT based IotDevice connector.
- */
-package edgent.connectors.mqtt.iot;
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/a129aa16/connectors/mqtt/src/main/java/edgent/connectors/mqtt/package-info.java
----------------------------------------------------------------------
diff --git a/connectors/mqtt/src/main/java/edgent/connectors/mqtt/package-info.java b/connectors/mqtt/src/main/java/edgent/connectors/mqtt/package-info.java
deleted file mode 100644
index 4107a50..0000000
--- a/connectors/mqtt/src/main/java/edgent/connectors/mqtt/package-info.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
-*/
-
-/**
- * MQTT (lightweight messaging protocol for small sensors and mobile devices) stream connector.
- * <p>
- * Stream tuples may be published to MQTT broker topics
- * and created by subscribing to broker topics.
- * For more information about MQTT see
- * <a href="http://mqtt.org">http://mqtt.org</a>
- */
-package edgent.connectors.mqtt;
-
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/a129aa16/connectors/mqtt/src/main/java/edgent/connectors/mqtt/runtime/MqttConnector.java
----------------------------------------------------------------------
diff --git a/connectors/mqtt/src/main/java/edgent/connectors/mqtt/runtime/MqttConnector.java b/connectors/mqtt/src/main/java/edgent/connectors/mqtt/runtime/MqttConnector.java
deleted file mode 100644
index 122dffa..0000000
--- a/connectors/mqtt/src/main/java/edgent/connectors/mqtt/runtime/MqttConnector.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
-*/
-
-package edgent.connectors.mqtt.runtime;
-
-import java.util.concurrent.TimeUnit;
-
-import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
-import org.eclipse.paho.client.mqttv3.MqttCallback;
-import org.eclipse.paho.client.mqttv3.MqttClient;
-import org.eclipse.paho.client.mqttv3.MqttClientPersistence;
-import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
-import org.eclipse.paho.client.mqttv3.MqttException;
-import org.eclipse.paho.client.mqttv3.MqttMessage;
-import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import edgent.connectors.mqtt.MqttConfig;
-import edgent.connectors.runtime.Connector;
-import edgent.function.Supplier;
-
-/**
- * A connector to an MQTT server.
- */
-public class MqttConnector extends Connector<MqttClient> {
- private static final long serialVersionUID = 1L;
- private static final Logger logger = LoggerFactory.getLogger(MqttConnector.class);
- private String id;
- private final String clientId;
- private final Supplier<MqttConfig> configFn;
- private volatile MqttSubscriber<?> subscriber;
-
- private class Callback implements MqttCallback {
-
- @Override
- public void connectionLost(Throwable t) {
- MqttConnector.this.connectionLost(t);
- }
-
- @Override
- public void deliveryComplete(IMqttDeliveryToken arg0) {
- // TODO Auto-generated method stub
- }
-
- @Override
- public void messageArrived(String topic, MqttMessage message)
- throws Exception {
- // N.B. MQTT will close the connection if this unwinds
- try {
- logger.trace("{} received topic:{} qos:{} isRetained:{} {} bytes",
- id(), topic, message.getQos(), message.isRetained(),
- message.getPayload().length);
- notIdle();
- subscriber.messageArrived(topic, message);
- }
- catch (Exception e) {
- logger.error("{} messageArrived handling failed", id(), e);
- }
- }
-
- }
-
- /**
- * Create a new connector.
- *
- * @param config connector configuration.
- */
- public MqttConnector(Supplier<MqttConfig> config) {
- this.configFn = config;
-
- String cid = configFn.get().getClientId();
- if (cid == null)
- cid = MqttClient.generateClientId();
- clientId = cid;
- }
- @Override
- public Logger getLogger() {
- return logger;
- }
-
- void setSubscriber(MqttSubscriber<?> subscriber) {
- this.subscriber = subscriber;
- }
-
- @Override
- protected synchronized MqttClient doConnect(MqttClient client) throws MqttException {
- MqttConfig config = configFn.get();
-
- if (client == null)
- client = newClient(config);
-
- if (client.isConnected())
- return client;
-
- MqttConnectOptions options = (MqttConnectOptions) config.options();
-
- logger.info("{} cleanSession:{} userName:{} password:{} idleTimeout:{} idleReconnectTimeout:{} cnTimeout:{} keepalive:{} serverURIs:{} willDst:{} willMsg:{}",
- id(),
- options.isCleanSession(),
- options.getUserName(),
- options.getPassword() == null ? null : "*****",
- config.getIdleTimeout(),
- config.getSubscriberIdleReconnectInterval(),
- options.getConnectionTimeout(),
- options.getKeepAliveInterval(),
- options.getServerURIs(),
- options.getWillDestination(),
- options.getWillMessage()
- );
-
- client.connect(options);
-
- setIdleTimeout(config.getIdleTimeout(), TimeUnit.SECONDS);
-
- MqttSubscriber<?> sub = subscriber;
- if (sub != null) {
- setIdleReconnectInterval(config.getSubscriberIdleReconnectInterval());
- sub.connected(client);
- }
-
- return client;
- }
-
- private MqttClient newClient(MqttConfig config) throws MqttException {
- String url = config.getServerURLs()[0];
- MqttClientPersistence persistence = config.getPersistence();
- if (persistence == null)
- persistence = new MemoryPersistence();
- long actionTimeToWaitMillis = config.getActionTimeToWaitMillis();
-
- logger.info("{} server:{} clientId:{} actionTimeToWait:{} persistence:{}",
- id(), url, clientId, actionTimeToWaitMillis, persistence);
-
- MqttClient client = new MqttClient(url, clientId, persistence);
- client.setTimeToWait(actionTimeToWaitMillis);
- client.setCallback(new Callback());
- return client;
- }
-
- @Override
- protected synchronized void doDisconnect(MqttClient client) throws Exception {
- if (client.isConnected())
- client.disconnect();
- }
-
- @Override
- public void doClose(MqttClient client) throws Exception {
- try {
- doDisconnect(client);
- } finally {
- client.close();
- }
- }
-
- @Override
- protected String id() {
- if (id == null) {
- // include our short object Id
- id = "MQTT " + toString().substring(toString().indexOf('@') + 1)
- + " " + clientId;
- }
- return id;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/a129aa16/connectors/mqtt/src/main/java/edgent/connectors/mqtt/runtime/MqttPublisher.java
----------------------------------------------------------------------
diff --git a/connectors/mqtt/src/main/java/edgent/connectors/mqtt/runtime/MqttPublisher.java b/connectors/mqtt/src/main/java/edgent/connectors/mqtt/runtime/MqttPublisher.java
deleted file mode 100644
index 563d8ce..0000000
--- a/connectors/mqtt/src/main/java/edgent/connectors/mqtt/runtime/MqttPublisher.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
-*/
-
-package edgent.connectors.mqtt.runtime;
-
-import org.eclipse.paho.client.mqttv3.MqttMessage;
-import org.slf4j.Logger;
-
-import edgent.function.Consumer;
-import edgent.function.Function;
-
-/**
- * Consumer that publishes stream tuples of type {@code T} to an MQTT server topic.
- *
- * @param <T> stream tuple type
- */
-public class MqttPublisher<T> implements Consumer<T>, AutoCloseable {
- private static final long serialVersionUID = 1L;
- private final Logger logger;
- private transient String id;
- private final MqttConnector connector;
- private final Function<T, byte[]> payload;
- private final Function<T, String> topic;
- private final Function<T, Integer> qos;
- private final Function<T, Boolean> retain;
-
- public MqttPublisher(MqttConnector connector, Function<T, byte[]> payload, Function<T, String> topic,
- Function<T, Integer> qos, Function<T, Boolean> retain) {
- this.logger = connector.getLogger();
- this.connector = connector;
- this.payload = payload;
- this.topic = topic;
- this.qos = qos;
- this.retain = retain;
- }
-
- @Override
- public void accept(T t) {
- // right now, the caller of accept() doesn't do anything to
- // log or tolerate an unwind. address those issues here.
- String topicStr = topic.apply(t);
- try {
- MqttMessage message = new MqttMessage(payload.apply(t));
- message.setQos(qos.apply(t));
- message.setRetained(retain.apply(t));
- logger.trace("{} sending to topic:{}", id(), topicStr);
- connector.notIdle();
- connector.client().publish(topicStr, message);
- } catch (Exception e) {
- logger.error("{} sending to topic:{} failed.", id(), topicStr, e);
- }
- }
-
- protected String id() {
- if (id == null) {
- // use our short object Id
- id = connector.id() + " publisher " + toString().substring(toString().indexOf('@') + 1);
- }
- return id;
- }
-
- @Override
- public void close() throws Exception {
- connector.close();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/a129aa16/connectors/mqtt/src/main/java/edgent/connectors/mqtt/runtime/MqttSubscriber.java
----------------------------------------------------------------------
diff --git a/connectors/mqtt/src/main/java/edgent/connectors/mqtt/runtime/MqttSubscriber.java b/connectors/mqtt/src/main/java/edgent/connectors/mqtt/runtime/MqttSubscriber.java
deleted file mode 100644
index 354d71c..0000000
--- a/connectors/mqtt/src/main/java/edgent/connectors/mqtt/runtime/MqttSubscriber.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
-*/
-
-package edgent.connectors.mqtt.runtime;
-
-import org.eclipse.paho.client.mqttv3.MqttClient;
-import org.eclipse.paho.client.mqttv3.MqttException;
-import org.eclipse.paho.client.mqttv3.MqttMessage;
-import org.slf4j.Logger;
-
-import edgent.function.BiFunction;
-import edgent.function.Consumer;
-
-/**
- * Consumer that subscribes to topics from an MQTT server
- * producing a stream tuple of type {@code T} for each received message.
- *
- * @param <T> stream tuple type
- */
-public class MqttSubscriber<T> implements Consumer<Consumer<T>>, AutoCloseable {
- private static final long serialVersionUID = 1L;
- private final Logger logger;
- private transient String id;
- private final MqttConnector connector;
- private final String topicFilter;
- private final int qos;
- private BiFunction<String, byte[], T> message2Tuple;
- private Consumer<T> eventSubmitter;
-
- public MqttSubscriber(MqttConnector connector, String topicFilter, int qos, BiFunction<String, byte[], T> message2Tuple) {
- this.logger = connector.getLogger();
- this.connector = connector;
- this.topicFilter = topicFilter;
- this.qos = qos;
- this.message2Tuple = message2Tuple;
- connector.setSubscriber(this);
- }
-
- /**
- * To be called on initial connection and reconnects
- * @param client the MqttClient
- * @throws MqttException
- */
- void connected(MqttClient client) throws MqttException {
- logger.info("{} subscribe({}, {})", id(), topicFilter, qos);
- client.subscribe(topicFilter, qos);
- }
-
- @Override
- public void accept(Consumer<T> eventSubmitter) {
- this.eventSubmitter = eventSubmitter;
-
- try {
- connector.client(); // induce connecting.
- } catch (Exception e) {
- logger.error("{} setup failed topicFilter:{}", id(), topicFilter, e);
- }
- }
-
- void messageArrived(String topic, MqttMessage message) throws Exception {
- T tuple = message2Tuple.apply(topic, message.getPayload());
- eventSubmitter.accept(tuple);
- }
-
- protected String id() {
- if (id == null) {
- // use our short object Id (only single subscriber)
- id = connector.id() + " subscriber ";
- }
- return id;
- }
-
- @Override
- public void close() throws Exception {
- connector.close();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/a129aa16/connectors/mqtt/src/main/java/org/apache/edgent/connectors/mqtt/MqttConfig.java
----------------------------------------------------------------------
diff --git a/connectors/mqtt/src/main/java/org/apache/edgent/connectors/mqtt/MqttConfig.java b/connectors/mqtt/src/main/java/org/apache/edgent/connectors/mqtt/MqttConfig.java
new file mode 100644
index 0000000..4ede290
--- /dev/null
+++ b/connectors/mqtt/src/main/java/org/apache/edgent/connectors/mqtt/MqttConfig.java
@@ -0,0 +1,587 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+package org.apache.edgent.connectors.mqtt;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Properties;
+
+import org.apache.edgent.function.Consumer;
+import org.apache.edgent.topology.json.JsonFunctions;
+import org.eclipse.paho.client.mqttv3.MqttClientPersistence;
+import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
+import org.eclipse.paho.client.mqttv3.MqttMessage;
+
+import com.google.gson.JsonObject;
+
+/**
+ * MQTT broker connector configuration.
+ */
+public class MqttConfig {
+ private MqttConnectOptions options = new MqttConnectOptions();
+ private String clientId;
+ private MqttClientPersistence persistence;
+ private long actionTimeToWaitMillis = -1;
+ private int idleTimeout;
+ private int subscriberIdleReconnectIntervalSec = 60;
+
+ /**
+ * Create a new configuration from {@link Properties}.
+ * <p>
+ * There is a property corresponding to each {@code MqttConfig.set<name>()}
+ * method. Unless otherwise stated, the property's value is a string
+ * of the corresponding method's argument type.
+ * Properties not specified yield a configuration value as
+ * described by and their corresponding {@code set<name>()}.
+ * <p>
+ * Properties other than those noted are ignored.
+ *
+ * <h3>MQTT connector properties</h3>
+ * <ul>
+ * <li>mqtt.actionTimeToWaitMillis</li>
+ * <li>mqtt.cleanSession</li>
+ * <li>mqtt.clientId</li>
+ * <li>mqtt.connectionTimeoutSec</li>
+ * <li>mqtt.idleTimeoutSec</li>
+ * <li>mqtt.keepAliveSec</li>
+ * <li>mqtt.keyStore - optional. Only used with "ssl:" serverURL when the
+ * server is configured for client auth.
+ * Path to key store file in JKS format.
+ * The first key in the store is used. The key must have the same
+ * password as the store if any.
+ * If not set, the standard JRE and javax.net.ssl system properties
+ * control the SSL behavior.</li>
+ * <li>mqtt.keyStorePassword - required if mqtt.keyStore is set.</li>
+ * <li>mqtt.password</li>
+ * <li>mqtt.persistence</li>
+ * <li>mqtt.serverURLs - csv list of MQTT URLs of the form:
+ * {@code tcp://<host>:<port>} or
+ * {@code ssl://<host>:<port>}
+ * </li>
+ * <li>mqtt.subscriberIdleReconnectIntervalSec</li>
+ * <li>mqtt.trustStore - optional. Only used with "ssl:" serverURL.
+ * Path to trust store file in JKS format.
+ * If not set, the standard JRE and javax.net.ssl system properties
+ * control the SSL behavior.
+ * Generally not required if server has a CA-signed certificate.</li>
+ * <li>mqtt.trustStorePassword - required if mqtt.trustStore is set</li>
+ * <li>mqtt.userName</li>
+ * <li>mqtt.will - JSON for with the following properties:
+ * <ul>
+ * <li>topic - string</li>
+ * <li>payload - string for byte[] in UTF8</li>
+ * <li>qos - integer</li>
+ * <li>retained - boolean</li>
+ * </ul>
+ * </li>
+ * </ul>
+ * @param properties properties specifying the configuration.
+ *
+ * @return the configuration
+ * @throws IllegalArgumentException for illegal values
+ */
+ public static MqttConfig fromProperties(Properties properties) {
+ MqttConfig config = new MqttConfig();
+ Properties p = properties;
+ setConfig(p, "mqtt.actionTimeToWaitMillis",
+ val -> config.setActionTimeToWaitMillis(Long.valueOf(val)));
+ setConfig(p, "mqtt.cleanSession",
+ val -> config.setCleanSession(Boolean.valueOf(val)));
+ setConfig(p, "mqtt.clientId",
+ val -> config.setClientId(val));
+ setConfig(p, "mqtt.connectionTimeoutSec",
+ val -> config.setConnectionTimeout(Integer.valueOf(val)));
+ setConfig(p, "mqtt.idleTimeoutSec",
+ val -> config.setIdleTimeout(Integer.valueOf(val)));
+ setConfig(p, "mqtt.keepAliveSec",
+ val -> config.setKeepAliveInterval(Integer.valueOf(val)));
+ setConfig(p, "mqtt.keyStore",
+ val -> config.setKeyStore(val));
+ setConfig(p, "mqtt.keyStorePassword",
+ val -> config.setKeyStorePassword(val.toCharArray()));
+// paho MqttConnectOptions.setSslProperties() doesn't support this control
+// setConfig(p, "mqtt.keyPassword",
+// val -> config.setKeyPassword(val.toCharArray()));
+// setConfig(p, "mqtt.keyCertificateAlias",
+// val -> config.setKeyCertificateAlias(val));
+ setConfig(p, "mqtt.password",
+ val -> config.setPassword(val.toCharArray()));
+ setConfig(p, "mqtt.persistence",
+ val -> config.setPersistence(newPersistenceProvider(val)));
+ setConfig(p, "mqtt.serverURLs",
+ val -> config.setServerURLs(val.split(",")));
+ setConfig(p, "mqtt.subscriberIdleReconnectIntervalSec",
+ val -> config.setSubscriberIdleReconnectInterval(Integer.valueOf(val)));
+ setConfig(p, "mqtt.trustStore",
+ val -> config.setTrustStore(val));
+ setConfig(p, "mqtt.trustStorePassword",
+ val -> config.setTrustStorePassword(val.toCharArray()));
+ setConfig(p, "mqtt.userName",
+ val -> config.setUserName(val));
+ setConfig(p, "mqtt.will", val -> {
+ JsonObject jo = JsonFunctions.fromString().apply(val);
+ String topic = jo.get("topic").getAsString();
+ byte[] payload = jo.get("payload").getAsString().getBytes(StandardCharsets.UTF_8);
+ int qos = jo.get("qos").getAsInt();
+ boolean retained = jo.get("retained").getAsBoolean();
+ config.setWill(topic, payload, qos, retained);
+ });
+ return config;
+ }
+
+ private static void setConfig(Properties p, String name, Consumer<String> setter) {
+ try {
+ String value = p.getProperty(name);
+ if (value != null) {
+ setter.accept(value);
+ }
+ } catch (Exception e) {
+ throw new IllegalArgumentException(name, e);
+ }
+ }
+
+ private static MqttClientPersistence newPersistenceProvider(String className) {
+ Class<?> clazz = null;
+ try {
+ clazz = Class.forName(className);
+ return (MqttClientPersistence) clazz.newInstance();
+ }
+ catch (Exception e) {
+ throw new IllegalArgumentException(e.getLocalizedMessage(), e);
+ }
+ }
+
+ /**
+ * Create a new configuration.
+ */
+ public MqttConfig() { }
+
+ /**
+ * Create a new configuration.
+ * @param serverURL the MQTT broker's URL
+ * @param clientId the MQTT client's id. Auto-generated if null.
+ */
+ public MqttConfig(String serverURL, String clientId) {
+ options.setServerURIs(new String[] {serverURL});
+ this.clientId = clientId;
+ }
+
+ /**
+ * Get the connection Client Id.
+ * @return the value
+ */
+ public String getClientId() {
+ return clientId;
+ }
+
+ /**
+ * Get the maximum time to wait for an action (e.g., publish message) to complete.
+ * @return the value
+ */
+ public long getActionTimeToWaitMillis() {
+ return actionTimeToWaitMillis;
+ }
+
+ /**
+ * Get the QoS 1 and 2 in-flight message persistence handler.
+ * @return the value
+ */
+ public MqttClientPersistence getPersistence() {
+ return persistence;
+ }
+
+ /**
+ * Get the connection timeout.
+ * @return the value
+ */
+ public int getConnectionTimeout() {
+ return options.getConnectionTimeout();
+ }
+
+ /**
+ * Get the idle connection timeout.
+ * @return the value
+ */
+ public int getIdleTimeout() {
+ return idleTimeout;
+ }
+
+ /**
+ * Get the subscriber idle reconnect interval.
+ * @return the value
+ */
+ public int getSubscriberIdleReconnectInterval() {
+ return subscriberIdleReconnectIntervalSec;
+ }
+
+ /**
+ * Get the connection Keep alive interval.
+ * @return the value
+ */
+ public int getKeepAliveInterval() {
+ return options.getKeepAliveInterval();
+ }
+
+ /**
+ * Get the MQTT Server URLs
+ * @return the value
+ */
+ public String[] getServerURLs() {
+ return options.getServerURIs();
+ }
+
+ /**
+ * Get a Last Will and Testament message's destination topic.
+ * @return the value. may be null.
+ */
+ public String getWillDestination() {
+ return options.getWillDestination();
+ }
+
+ /**
+ * Get a Last Will and Testament message's payload.
+ * @return the value. may be null.
+ */
+ public byte[] getWillPayload() {
+ MqttMessage msg = options.getWillMessage();
+ return msg==null ? null : msg.getPayload();
+ }
+
+ /**
+ * Get a Last Will and Testament message's QOS.
+ * @return the value.
+ */
+ public int getWillQOS() {
+ MqttMessage msg = options.getWillMessage();
+ return msg==null ? 0 : msg.getQos();
+ }
+
+ /**
+ * Get a Last Will and Testament message's "retained" setting.
+ * @return the value.
+ */
+ public boolean getWillRetained() {
+ MqttMessage msg = options.getWillMessage();
+ return msg==null ? false : msg.isRetained();
+ }
+
+ /**
+ * Get the clean session setting.
+ * @return the value
+ */
+ public boolean isCleanSession() {
+ return options.isCleanSession();
+ }
+
+ /**
+ * Get the the password to use for authentication with the server.
+ * @return the value
+ */
+ public char[] getPassword() {
+ return options.getPassword();
+ }
+
+ /**
+ * Get the username to use for authentication with the server.
+ * @return the value
+ */
+ public String getUserName() {
+ return options.getUserName();
+ }
+
+ /**
+ * Connection Client Id.
+ * <p>
+ * Optional. default null: a clientId is auto-generated.
+ * @param clientId the client id
+ */
+ public void setClientId(String clientId) {
+ this.clientId = clientId;
+ }
+
+ /**
+ * Maximum time to wait for an action (e.g., publish message) to complete.
+ * <p>
+ * Optional. default: -1 no timeout. 0 also means no timeout.
+ * @param actionTimeToWaitMillis the time to wait in milliseconds
+ */
+ public void setActionTimeToWaitMillis(long actionTimeToWaitMillis) {
+ this.actionTimeToWaitMillis = actionTimeToWaitMillis;
+ }
+
+ /**
+ * QoS 1 and 2 in-flight message persistence.
+ * <p>
+ * optional. default: use memory persistence.
+ * @param persistence the persistence implementation
+ */
+ public void setPersistence(MqttClientPersistence persistence) {
+ this.persistence = persistence;
+ }
+
+ /**
+ * Clean Session.
+ * <p>
+ * Qptional. default: true.
+ * @param cleanSession the clean session value
+ */
+ public void setCleanSession(boolean cleanSession) {
+ options.setCleanSession(cleanSession);
+ }
+
+ /**
+ * Connection timeout.
+ * Optional. 0 disables the timeout / blocks until connected. default: 30 seconds.
+ * @param connectionTimeoutSec the timeout in seconds
+ */
+ public void setConnectionTimeout(int connectionTimeoutSec) {
+ options.setConnectionTimeout(connectionTimeoutSec);
+ }
+
+ /**
+ * Idle connection timeout.
+ * Optional. 0 disables idle connection disconnect. default: 0 seconds (disabled).
+ * <p>
+ * Following an idle disconnect, the connector will automatically
+ * reconnect when it receives a new tuple to publish.
+ * If the connector is subscribing to topics, it will also reconnect
+ * as per {@link #setSubscriberIdleReconnectInterval(int)}.
+ * <p>
+ * @param idleTimeoutSec the timeout in seconds
+ * @see #setSubscriberIdleReconnectInterval(int)
+ */
+ public void setIdleTimeout(int idleTimeoutSec) {
+ if (idleTimeoutSec < 0)
+ idleTimeoutSec = 0;
+ this.idleTimeout = idleTimeoutSec;
+ }
+
+ /**
+ * Subscriber idle reconnect interval.
+ * <p>
+ * Following an idle disconnect, if the connector is subscribing to topics,
+ * it will reconnect after the specified interval.
+ * Optional. default: 60 seconds.
+ * @param seconds the interval in seconds
+ */
+ public void setSubscriberIdleReconnectInterval(int seconds) {
+ if (seconds < 0)
+ seconds = 0;
+ subscriberIdleReconnectIntervalSec = seconds;
+ }
+
+ /**
+ * Connection Keep alive.
+ * <p>
+ * Optional. 0 disables keepalive processing. default: 60 seconds.
+ * @param keepAliveSec the interval in seconds
+ */
+ public void setKeepAliveInterval(int keepAliveSec) {
+ options.setKeepAliveInterval(keepAliveSec);
+ }
+
+ /**
+ * MQTT Server URLs
+ * <p>
+ * Required. Must be an array of one or more MQTT server URLs.
+ * When connecting, the first URL that successfully connects is used.
+ * @param serverUrls the URLs
+ */
+ public void setServerURLs(String[] serverUrls) {
+ options.setServerURIs(serverUrls);
+ }
+
+ /**
+ * Last Will and Testament.
+ * <p>
+ * optional. default: no last-will-and-testament.
+ * @param topic topic to publish to
+ * @param payload the last-will-and-testament message value
+ * @param qos the quality of service to use to publish the message
+ * @param retained true to retain the message across connections
+ */
+ public void setWill(String topic, byte[] payload, int qos, boolean retained) {
+ options.setWill(topic, payload, qos, retained);
+ }
+
+ /**
+ * Set the password to use for authentication with the server.
+ * Optional. default: null.
+ * @param password the password
+ */
+ public void setPassword(char[] password) {
+ options.setPassword(password);
+ }
+
+ /**
+ * Set the username to use for authentication with the server.
+ * Optional. default: null.
+ * @param userName the user name
+ */
+ public void setUserName(String userName) {
+ options.setUserName(userName);
+ }
+
+ /**
+ * @param name option name
+ * @param value option value. null to unset.
+ */
+ private void setSslOption(String name, String value) {
+ Properties props = options.getSSLProperties();
+ if (props == null)
+ props = new Properties();
+ if (value == null)
+ props.remove(name);
+ else
+ props.setProperty(name, value);
+ options.setSSLProperties(props);
+ }
+
+ /**
+ * @param name option name
+ * @return option's value. null if not set.
+ */
+ private String getSslOption(String name) {
+ Properties props = options.getSSLProperties();
+ return props == null ? null : props.getProperty(name);
+ }
+
+ /**
+ * Set the SSL trust store path.
+ * <p>
+ * Only used with "ssl:" serverURL.
+ * Path to trust store file in JKS format.
+ * If not set, the standard JRE and javax.net.ssl system properties
+ * control the SSL behavior.
+ * Generally not required if server has a CA-signed certificate.
+ * @param path the path. null to unset.
+ */
+ public void setTrustStore(String path) {
+ setSslOption("com.ibm.ssl.trustStore", path);
+ }
+
+ /**
+ * Get the SSL trust store path.
+ * @return the path. null if not set.
+ */
+ public String getTrustStore() {
+ return getSslOption("com.ibm.ssl.trustStore");
+ }
+
+ /**
+ * Set the SSL trust store password.
+ * <p>
+ * Required if the trust store path is set.
+ *
+ * @param password the password
+ */
+ public void setTrustStorePassword(char[] password) {
+ setSslOption("com.ibm.ssl.trustStorePassword", new String(password));
+ }
+
+ /**
+ * Get the SSL trust store path password.
+ * @return the password. null if not set.
+ */
+ public char[] getTrustStorePassword() {
+ String s = getSslOption("com.ibm.ssl.trustStorePassword");
+ return s == null ? null : s.toCharArray();
+ }
+
+ /**
+ * Set the SSL key store path.
+ * <p>
+ * Only used with "ssl:" serverURL when the server is configured for
+ * client auth.
+ * Path to trust store file in JKS format.
+ * If not set, the standard JRE and javax.net.ssl system properties
+ * control the SSL behavior.
+ * @param path the path. null to unset.
+ */
+ public void setKeyStore(String path) {
+ setSslOption("com.ibm.ssl.keyStore", path);
+ }
+
+ /**
+ * Get the SSL trust store path.
+ * @return the path. null if not set.
+ */
+ public String getKeyStore() {
+ return getSslOption("com.ibm.ssl.keyStore");
+ }
+
+ /**
+ * Set the SSL key store password.
+ * <p>
+ * Required if the key store path is set.
+ *
+ * @param password the password. null to unset.
+ */
+ public void setKeyStorePassword(char[] password) {
+ setSslOption("com.ibm.ssl.keyStorePassword", new String(password));
+ }
+
+ /**
+ * Get the SSL key store path password.
+ * @return the password. null if not set.
+ */
+ public char[] getKeyStorePassword() {
+ String s = getSslOption("com.ibm.ssl.keyStorePassword");
+ return s == null ? null : s.toCharArray();
+ }
+
+// paho MqttConnectOptions.setSslProperties() doesn't support this control
+// /**
+// * Set the SSL key password.
+// * <p>
+// * Defaults to using the key store password if not set.
+// *
+// * @param password the password. null to unset.
+// */
+// public void setKeyPassword(char[] password) {
+// setSslOption("com.ibm.ssl.XXXX-NO-SUCH-KEY-XXXX.keyPassword", new String(password));
+// }
+//
+// public char[] getKeyPassword() {
+// String s = getSslOption("com.ibm.ssl.XXXX-NO-SUCH-KEY-XXXX.keyPassword");
+// return s == null ? null : s.toCharArray();
+// }
+
+ // paho MqttConnectOptions.setSslProperties() doesn't support this control
+// /**
+// * Set the SSL key certificate alias.
+// * <p>
+// * Defaults to using "default" if not set.
+// * @param alias the alias. null to unset.
+// */
+// public void setKeyCertificateAlias(String alias) {
+// setSslOption("com.ibm.ssl.XXXX-NO-SUCH-KEY-XXXX.keyCertificateAlias", alias);
+// }
+//
+// public String getKeyCertificateAlias() {
+// return getSslOption("com.ibm.ssl.XXXX-NO-SUCH-KEY-XXXX.keyCertificateAlias");
+// }
+
+ /**
+ * INTERNAL USE ONLY.
+ * @return object
+ */
+ public Object options() {
+ return options;
+ }
+}