public FutureConnection futureConnection() { return new FutureConnection(callbackConnection()); } public BlockingConnection blockingConnection() {
private void connectMqtt() throws Exception { String clientId = this.topologyName + "-" + this.context.getThisComponentId() + "-" + this.context.getThisTaskId(); MQTT client = MqttUtils.configureClient(this.options, clientId, this.keyStoreLoader); this.connection = client.callbackConnection(); this.connection.listener(this); this.connection.connect(new ConnectCallback()); while (!this.mqttConnected && !this.mqttConnectFailed) { LOG.info("Waiting for connection..."); Thread.sleep(500); } if (this.mqttConnected) { List<String> topicList = this.options.getTopics(); Topic[] topics = new Topic[topicList.size()]; QoS qos = MqttUtils.qosFromInt(this.options.getQos()); for (int i = 0; i < topicList.size(); i++) { topics[i] = new Topic(topicList.get(i), qos); } connection.subscribe(topics, new SubscribeCallback()); } }
private void execute() { final CallbackConnection connection = mqtt.callbackConnection();
private void execute() { final CallbackConnection connection = mqtt.callbackConnection();
public FutureConnection futureConnection() { return new FutureConnection(callbackConnection()); } public BlockingConnection blockingConnection() {
private CallbackConnection createConnection(String host, String clientId, boolean durable) throws URISyntaxException { MQTT client = new MQTT(); client.setHost(host); client.setClientId(clientId); client.setCleanSession(!durable); return client.callbackConnection(); }
private void execute() { final CallbackConnection connection = mqtt.callbackConnection();
private void execute() { final CallbackConnection connection = mqtt.callbackConnection();
private CallbackConnection createConnection(String host, String clientId, boolean durable, String user, String password) throws URISyntaxException { MQTT client = new MQTT(); client.setHost(host); client.setClientId(clientId); client.setUserName(user); client.setPassword(password); client.setCleanSession(!durable); return client.callbackConnection(); }
@Override public FuseChannel build() throws Exception { final URI broker = Objects.requireNonNull(broker(), "Broker must be set"); final String clientId = Strings.nonEmptyText(clientId(), "clientId"); final MqttNamespace namespace = Objects.requireNonNull(namespace(), "Namespace must be set"); final BinaryPayloadCodec codec = Objects.requireNonNull(codec(), "Codec must be set"); final MQTT mqtt = new MQTT(); mqtt.setCleanSession(false); mqtt.setHost(broker); mqtt.setClientId(clientId); final Object credentials = credentials(); if (credentials == null) { // none } else if (credentials instanceof UserAndPassword) { final UserAndPassword userAndPassword = (UserAndPassword) credentials; mqtt.setUserName(userAndPassword.getUsername()); mqtt.setPassword(userAndPassword.getPasswordAsString()); } else { throw new IllegalStateException( String.format("Unknown credentials type: %s", credentials.getClass().getName())); } final CallbackConnection connection = mqtt.callbackConnection(); final FuseChannel result = new FuseChannel(clientId, namespace, codec, connection); return result; } }
@Override public FuseChannel build() throws Exception { final URI broker = Objects.requireNonNull(broker(), "Broker must be set"); final String clientId = Strings.nonEmptyText(clientId(), "clientId"); final MqttNamespace namespace = Objects.requireNonNull(namespace(), "Namespace must be set"); final BinaryPayloadCodec codec = Objects.requireNonNull(codec(), "Codec must be set"); final MQTT mqtt = new MQTT(); mqtt.setCleanSession(false); mqtt.setHost(broker); mqtt.setClientId(clientId); final Object credentials = credentials(); if (credentials == null) { // none } else if (credentials instanceof UserAndPassword) { final UserAndPassword userAndPassword = (UserAndPassword) credentials; mqtt.setUserName(userAndPassword.getUsername()); mqtt.setPassword(userAndPassword.getPasswordAsString()); } else { throw new IllegalStateException( String.format("Unknown credentials type: %s", credentials.getClass().getName())); } final CallbackConnection connection = mqtt.callbackConnection(); final FuseChannel result = new FuseChannel(clientId, namespace, codec, connection); return result; } }
connection = mqtt.callbackConnection(); createListener(); connection.connect(new Callback<Void>() {
connection = mqtt.callbackConnection(); createListener(); connection.connect(new Callback<Void>() {