/*
* Copyright 2014 Red Hat, Inc.
*
* Red Hat 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 io.vertx.reactivex.mqtt;
import java.util.Map;
import io.reactivex.Observable;
import io.reactivex.Flowable;
import io.reactivex.Single;
import io.reactivex.Completable;
import io.reactivex.Maybe;
import io.netty.handler.codec.mqtt.MqttQoS;
import io.vertx.mqtt.MqttClientOptions;
import java.util.Map;
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
An MQTT client
NOTE: This class has been automatically generated from the original
non RX-ified interface using Vert.x codegen. /**
* An MQTT client
*
* <p/>
* NOTE: This class has been automatically generated from the {@link io.vertx.mqtt.MqttClient original} non RX-ified interface using Vert.x codegen.
*/
@io.vertx.lang.rx.RxGen(io.vertx.mqtt.MqttClient.class)
public class MqttClient {
@Override
public String toString() {
return delegate.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MqttClient that = (MqttClient) o;
return delegate.equals(that.delegate);
}
@Override
public int hashCode() {
return delegate.hashCode();
}
public static final io.vertx.lang.rx.TypeArg<MqttClient> __TYPE_ARG = new io.vertx.lang.rx.TypeArg<>( obj -> new MqttClient((io.vertx.mqtt.MqttClient) obj),
MqttClient::getDelegate
);
private final io.vertx.mqtt.MqttClient delegate;
public MqttClient(io.vertx.mqtt.MqttClient delegate) {
this.delegate = delegate;
}
public io.vertx.mqtt.MqttClient getDelegate() {
return delegate;
}
Return an MQTT client instance
Params: - vertx – Vert.x instance
- options – MQTT client options
Returns: MQTT client instance
/**
* Return an MQTT client instance
* @param vertx Vert.x instance
* @param options MQTT client options
* @return MQTT client instance
*/
public static io.vertx.reactivex.mqtt.MqttClient create(io.vertx.reactivex.core.Vertx vertx, MqttClientOptions options) {
io.vertx.reactivex.mqtt.MqttClient ret = io.vertx.reactivex.mqtt.MqttClient.newInstance(io.vertx.mqtt.MqttClient.create(vertx.getDelegate(), options));
return ret;
}
Return an MQTT client instance using the default options
Params: - vertx – Vert.x instance
Returns: MQTT client instance
/**
* Return an MQTT client instance using the default options
* @param vertx Vert.x instance
* @return MQTT client instance
*/
public static io.vertx.reactivex.mqtt.MqttClient create(io.vertx.reactivex.core.Vertx vertx) {
io.vertx.reactivex.mqtt.MqttClient ret = io.vertx.reactivex.mqtt.MqttClient.newInstance(io.vertx.mqtt.MqttClient.create(vertx.getDelegate()));
return ret;
}
Connects to an MQTT server calling connectHandler after connection
Params: - port – port of the MQTT server
- host – hostname/ip address of the MQTT server
- connectHandler – handler called when the asynchronous connect call ends
Returns: current MQTT client instance
/**
* Connects to an MQTT server calling connectHandler after connection
* @param port port of the MQTT server
* @param host hostname/ip address of the MQTT server
* @param connectHandler handler called when the asynchronous connect call ends
* @return current MQTT client instance
*/
public io.vertx.reactivex.mqtt.MqttClient connect(int port, String host, Handler<AsyncResult<io.vertx.reactivex.mqtt.messages.MqttConnAckMessage>> connectHandler) {
delegate.connect(port, host, new Handler<AsyncResult<io.vertx.mqtt.messages.MqttConnAckMessage>>() {
public void handle(AsyncResult<io.vertx.mqtt.messages.MqttConnAckMessage> ar) {
if (ar.succeeded()) {
connectHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.reactivex.mqtt.messages.MqttConnAckMessage.newInstance(ar.result())));
} else {
connectHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
return this;
}
Connects to an MQTT server calling connectHandler after connection
Params: - port – port of the MQTT server
- host – hostname/ip address of the MQTT server
Returns: current MQTT client instance
/**
* Connects to an MQTT server calling connectHandler after connection
* @param port port of the MQTT server
* @param host hostname/ip address of the MQTT server
* @return current MQTT client instance
*/
public Single<io.vertx.reactivex.mqtt.messages.MqttConnAckMessage> rxConnect(int port, String host) {
return io.vertx.reactivex.impl.AsyncResultSingle.toSingle(handler -> {
connect(port, host, handler);
});
}
Connects to an MQTT server calling connectHandler after connection
Params: - port – port of the MQTT server
- host – hostname/ip address of the MQTT server
- serverName – the SNI server name
- connectHandler – handler called when the asynchronous connect call ends
Returns: current MQTT client instance
/**
* Connects to an MQTT server calling connectHandler after connection
* @param port port of the MQTT server
* @param host hostname/ip address of the MQTT server
* @param serverName the SNI server name
* @param connectHandler handler called when the asynchronous connect call ends
* @return current MQTT client instance
*/
public io.vertx.reactivex.mqtt.MqttClient connect(int port, String host, String serverName, Handler<AsyncResult<io.vertx.reactivex.mqtt.messages.MqttConnAckMessage>> connectHandler) {
delegate.connect(port, host, serverName, new Handler<AsyncResult<io.vertx.mqtt.messages.MqttConnAckMessage>>() {
public void handle(AsyncResult<io.vertx.mqtt.messages.MqttConnAckMessage> ar) {
if (ar.succeeded()) {
connectHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.reactivex.mqtt.messages.MqttConnAckMessage.newInstance(ar.result())));
} else {
connectHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
return this;
}
Connects to an MQTT server calling connectHandler after connection
Params: - port – port of the MQTT server
- host – hostname/ip address of the MQTT server
- serverName – the SNI server name
Returns: current MQTT client instance
/**
* Connects to an MQTT server calling connectHandler after connection
* @param port port of the MQTT server
* @param host hostname/ip address of the MQTT server
* @param serverName the SNI server name
* @return current MQTT client instance
*/
public Single<io.vertx.reactivex.mqtt.messages.MqttConnAckMessage> rxConnect(int port, String host, String serverName) {
return io.vertx.reactivex.impl.AsyncResultSingle.toSingle(handler -> {
connect(port, host, serverName, handler);
});
}
Disconnects from the MQTT server
Returns: current MQTT client instance
/**
* Disconnects from the MQTT server
* @return current MQTT client instance
*/
public io.vertx.reactivex.mqtt.MqttClient disconnect() {
delegate.disconnect();
return this;
}
Disconnects from the MQTT server calling disconnectHandler after disconnection
Params: - disconnectHandler – handler called when asynchronous disconnect call ends
Returns: current MQTT client instance
/**
* Disconnects from the MQTT server calling disconnectHandler after disconnection
* @param disconnectHandler handler called when asynchronous disconnect call ends
* @return current MQTT client instance
*/
public io.vertx.reactivex.mqtt.MqttClient disconnect(Handler<AsyncResult<Void>> disconnectHandler) {
delegate.disconnect(disconnectHandler);
return this;
}
Disconnects from the MQTT server calling disconnectHandler after disconnection
Returns: current MQTT client instance
/**
* Disconnects from the MQTT server calling disconnectHandler after disconnection
* @return current MQTT client instance
*/
public Completable rxDisconnect() {
return io.vertx.reactivex.impl.AsyncResultCompletable.toCompletable(handler -> {
disconnect(handler);
});
}
Sends the PUBLISH message to the remote MQTT server
Params: - topic – topic on which the message is published
- payload – message payload
- qosLevel – QoS level
- isDup – if the message is a duplicate
- isRetain – if the message needs to be retained
Returns: current MQTT client instance
/**
* Sends the PUBLISH message to the remote MQTT server
* @param topic topic on which the message is published
* @param payload message payload
* @param qosLevel QoS level
* @param isDup if the message is a duplicate
* @param isRetain if the message needs to be retained
* @return current MQTT client instance
*/
public io.vertx.reactivex.mqtt.MqttClient publish(String topic, io.vertx.reactivex.core.buffer.Buffer payload, MqttQoS qosLevel, boolean isDup, boolean isRetain) {
delegate.publish(topic, payload.getDelegate(), qosLevel, isDup, isRetain);
return this;
}
Sends the PUBLISH message to the remote MQTT server
Params: - topic – topic on which the message is published
- payload – message payload
- qosLevel – QoS level
- isDup – if the message is a duplicate
- isRetain – if the message needs to be retained
- publishSentHandler – handler called after PUBLISH packet sent with packetid (not when QoS 0)
Returns: current MQTT client instance
/**
* Sends the PUBLISH message to the remote MQTT server
* @param topic topic on which the message is published
* @param payload message payload
* @param qosLevel QoS level
* @param isDup if the message is a duplicate
* @param isRetain if the message needs to be retained
* @param publishSentHandler handler called after PUBLISH packet sent with packetid (not when QoS 0)
* @return current MQTT client instance
*/
public io.vertx.reactivex.mqtt.MqttClient publish(String topic, io.vertx.reactivex.core.buffer.Buffer payload, MqttQoS qosLevel, boolean isDup, boolean isRetain, Handler<AsyncResult<Integer>> publishSentHandler) {
delegate.publish(topic, payload.getDelegate(), qosLevel, isDup, isRetain, publishSentHandler);
return this;
}
Sends the PUBLISH message to the remote MQTT server
Params: - topic – topic on which the message is published
- payload – message payload
- qosLevel – QoS level
- isDup – if the message is a duplicate
- isRetain – if the message needs to be retained
Returns: current MQTT client instance
/**
* Sends the PUBLISH message to the remote MQTT server
* @param topic topic on which the message is published
* @param payload message payload
* @param qosLevel QoS level
* @param isDup if the message is a duplicate
* @param isRetain if the message needs to be retained
* @return current MQTT client instance
*/
public Single<Integer> rxPublish(String topic, io.vertx.reactivex.core.buffer.Buffer payload, MqttQoS qosLevel, boolean isDup, boolean isRetain) {
return io.vertx.reactivex.impl.AsyncResultSingle.toSingle(handler -> {
publish(topic, payload, qosLevel, isDup, isRetain, handler);
});
}
Sets handler which will be called each time publish is completed
Params: - publishCompletionHandler – handler called with the packetId
Returns: current MQTT client instance
/**
* Sets handler which will be called each time publish is completed
* @param publishCompletionHandler handler called with the packetId
* @return current MQTT client instance
*/
public io.vertx.reactivex.mqtt.MqttClient publishCompletionHandler(Handler<Integer> publishCompletionHandler) {
delegate.publishCompletionHandler(publishCompletionHandler);
return this;
}
Sets handler which will be called each time server publish something to client
Params: - publishHandler – handler to call
Returns: current MQTT client instance
/**
* Sets handler which will be called each time server publish something to client
* @param publishHandler handler to call
* @return current MQTT client instance
*/
public io.vertx.reactivex.mqtt.MqttClient publishHandler(Handler<io.vertx.reactivex.mqtt.messages.MqttPublishMessage> publishHandler) {
delegate.publishHandler(new Handler<io.vertx.mqtt.messages.MqttPublishMessage>() {
public void handle(io.vertx.mqtt.messages.MqttPublishMessage event) {
publishHandler.handle(io.vertx.reactivex.mqtt.messages.MqttPublishMessage.newInstance(event));
}
});
return this;
}
Sets handler which will be called after SUBACK packet receiving
Params: - subscribeCompletionHandler – handler to call. List inside is a granted QoS array
Returns: current MQTT client instance
/**
* Sets handler which will be called after SUBACK packet receiving
* @param subscribeCompletionHandler handler to call. List inside is a granted QoS array
* @return current MQTT client instance
*/
public io.vertx.reactivex.mqtt.MqttClient subscribeCompletionHandler(Handler<io.vertx.reactivex.mqtt.messages.MqttSubAckMessage> subscribeCompletionHandler) {
delegate.subscribeCompletionHandler(new Handler<io.vertx.mqtt.messages.MqttSubAckMessage>() {
public void handle(io.vertx.mqtt.messages.MqttSubAckMessage event) {
subscribeCompletionHandler.handle(io.vertx.reactivex.mqtt.messages.MqttSubAckMessage.newInstance(event));
}
});
return this;
}
Subscribes to the topic with a specified QoS level
Params: - topic – topic you subscribe on
- qos – QoS level
Returns: current MQTT client instance
/**
* Subscribes to the topic with a specified QoS level
* @param topic topic you subscribe on
* @param qos QoS level
* @return current MQTT client instance
*/
public io.vertx.reactivex.mqtt.MqttClient subscribe(String topic, int qos) {
delegate.subscribe(topic, qos);
return this;
}
Subscribes to the topic with a specified QoS level
Params: - topic – topic you subscribe on
- qos – QoS level
- subscribeSentHandler – handler called after SUBSCRIBE packet sent with packetid
Returns: current MQTT client instance
/**
* Subscribes to the topic with a specified QoS level
* @param topic topic you subscribe on
* @param qos QoS level
* @param subscribeSentHandler handler called after SUBSCRIBE packet sent with packetid
* @return current MQTT client instance
*/
public io.vertx.reactivex.mqtt.MqttClient subscribe(String topic, int qos, Handler<AsyncResult<Integer>> subscribeSentHandler) {
delegate.subscribe(topic, qos, subscribeSentHandler);
return this;
}
Subscribes to the topic with a specified QoS level
Params: - topic – topic you subscribe on
- qos – QoS level
Returns: current MQTT client instance
/**
* Subscribes to the topic with a specified QoS level
* @param topic topic you subscribe on
* @param qos QoS level
* @return current MQTT client instance
*/
public Single<Integer> rxSubscribe(String topic, int qos) {
return io.vertx.reactivex.impl.AsyncResultSingle.toSingle(handler -> {
subscribe(topic, qos, handler);
});
}
Subscribes to the topics with related QoS levels
Params: - topics – topics and related QoS levels to subscribe to
Returns: current MQTT client instance
/**
* Subscribes to the topics with related QoS levels
* @param topics topics and related QoS levels to subscribe to
* @return current MQTT client instance
*/
public io.vertx.reactivex.mqtt.MqttClient subscribe(Map<String, Integer> topics) {
delegate.subscribe(topics);
return this;
}
Subscribes to the topic and adds a handler which will be called after the request is sent
Params: - topics – topics you subscribe on
- subscribeSentHandler – handler called after SUBSCRIBE packet sent with packetid
Returns: current MQTT client instance
/**
* Subscribes to the topic and adds a handler which will be called after the request is sent
* @param topics topics you subscribe on
* @param subscribeSentHandler handler called after SUBSCRIBE packet sent with packetid
* @return current MQTT client instance
*/
public io.vertx.reactivex.mqtt.MqttClient subscribe(Map<String, Integer> topics, Handler<AsyncResult<Integer>> subscribeSentHandler) {
delegate.subscribe(topics, subscribeSentHandler);
return this;
}
Subscribes to the topic and adds a handler which will be called after the request is sent
Params: - topics – topics you subscribe on
Returns: current MQTT client instance
/**
* Subscribes to the topic and adds a handler which will be called after the request is sent
* @param topics topics you subscribe on
* @return current MQTT client instance
*/
public Single<Integer> rxSubscribe(Map<String, Integer> topics) {
return io.vertx.reactivex.impl.AsyncResultSingle.toSingle(handler -> {
subscribe(topics, handler);
});
}
Sets handler which will be called after UNSUBACK packet receiving
Params: - unsubscribeCompletionHandler – handler to call with the packetid
Returns: current MQTT client instance
/**
* Sets handler which will be called after UNSUBACK packet receiving
* @param unsubscribeCompletionHandler handler to call with the packetid
* @return current MQTT client instance
*/
public io.vertx.reactivex.mqtt.MqttClient unsubscribeCompletionHandler(Handler<Integer> unsubscribeCompletionHandler) {
delegate.unsubscribeCompletionHandler(unsubscribeCompletionHandler);
return this;
}
Unsubscribe from receiving messages on given topic
Params: - topic – Topic you want to unsubscribe from
Returns: current MQTT client instance
/**
* Unsubscribe from receiving messages on given topic
* @param topic Topic you want to unsubscribe from
* @return current MQTT client instance
*/
public io.vertx.reactivex.mqtt.MqttClient unsubscribe(String topic) {
delegate.unsubscribe(topic);
return this;
}
Unsubscribe from receiving messages on given topic
Params: - topic – Topic you want to unsubscribe from
- unsubscribeSentHandler – handler called after UNSUBSCRIBE packet sent
Returns: current MQTT client instance
/**
* Unsubscribe from receiving messages on given topic
* @param topic Topic you want to unsubscribe from
* @param unsubscribeSentHandler handler called after UNSUBSCRIBE packet sent
* @return current MQTT client instance
*/
public io.vertx.reactivex.mqtt.MqttClient unsubscribe(String topic, Handler<AsyncResult<Integer>> unsubscribeSentHandler) {
delegate.unsubscribe(topic, unsubscribeSentHandler);
return this;
}
Unsubscribe from receiving messages on given topic
Params: - topic – Topic you want to unsubscribe from
Returns: current MQTT client instance
/**
* Unsubscribe from receiving messages on given topic
* @param topic Topic you want to unsubscribe from
* @return current MQTT client instance
*/
public Single<Integer> rxUnsubscribe(String topic) {
return io.vertx.reactivex.impl.AsyncResultSingle.toSingle(handler -> {
unsubscribe(topic, handler);
});
}
Sets handler which will be called after PINGRESP packet receiving
Params: - pingResponseHandler – handler to call
Returns: current MQTT client instance
/**
* Sets handler which will be called after PINGRESP packet receiving
* @param pingResponseHandler handler to call
* @return current MQTT client instance
*/
public io.vertx.reactivex.mqtt.MqttClient pingResponseHandler(Handler<Void> pingResponseHandler) {
delegate.pingResponseHandler(pingResponseHandler);
return this;
}
Set an exception handler for the client, that will be called when an error happens
in internal netty structures.
io.netty.handler.codec.DecoderException
can be one of the cause
Params: - handler – the exception handler
Returns: current MQTT client instance
/**
* Set an exception handler for the client, that will be called when an error happens
* in internal netty structures.
*
* <code>io.netty.handler.codec.DecoderException</code> can be one of the cause
* @param handler the exception handler
* @return current MQTT client instance
*/
public io.vertx.reactivex.mqtt.MqttClient exceptionHandler(Handler<Throwable> handler) {
delegate.exceptionHandler(handler);
return this;
}
Set a handler that will be called when the connection with server is closed
Params: - closeHandler – handler to call
Returns: current MQTT client instance
/**
* Set a handler that will be called when the connection with server is closed
* @param closeHandler handler to call
* @return current MQTT client instance
*/
public io.vertx.reactivex.mqtt.MqttClient closeHandler(Handler<Void> closeHandler) {
delegate.closeHandler(closeHandler);
return this;
}
This method is needed by the client in order to avoid server closes the
connection due to the keep alive timeout if client has no messages to send
Returns: current MQTT client instance
/**
* This method is needed by the client in order to avoid server closes the
* connection due to the keep alive timeout if client has no messages to send
* @return current MQTT client instance
*/
public io.vertx.reactivex.mqtt.MqttClient ping() {
delegate.ping();
return this;
}
Returns: the client identifier
/**
* @return the client identifier
*/
public String clientId() {
String ret = delegate.clientId();
return ret;
}
Returns: if the connection between client and remote server is established/open
/**
* @return if the connection between client and remote server is established/open
*/
public boolean isConnected() {
boolean ret = delegate.isConnected();
return ret;
}
public static MqttClient newInstance(io.vertx.mqtt.MqttClient arg) {
return arg != null ? new MqttClient(arg) : null;
}
}