Class: VertxMqttServer::MqttClient
- Inherits:
-
Object
- Object
- VertxMqttServer::MqttClient
- Defined in:
- /Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-mqtt-server/mqtt_client.rb
Overview
An MQTT client
Constant Summary
- @@j_api_type =
Object.new
Class Method Summary (collapse)
- + (Boolean) accept?(obj)
-
+ (::VertxMqttServer::MqttClient) create(vertx = nil, options = nil)
Return an MQTT client instance.
- + (Object) j_api_type
- + (Object) j_class
- + (Object) unwrap(obj)
- + (Object) wrap(obj)
Instance Method Summary (collapse)
-
- (String) client_id
The client identifier.
-
- (self) close_handler { ... }
Set a handler that will be called when the connection with server is closed.
-
- (self) connect { ... }
Connects to an MQTT server calling connectHandler after connection.
-
- (self) disconnect { ... }
Disconnects from the MQTT server calling disconnectHandler after disconnection.
-
- (self) exception_handler { ... }
Set an exception handler for the client, that will be called when an error happens in internal netty structures.
-
- (self) ping
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.
-
- (self) ping_response_handler { ... }
Sets handler which will be called after PINGRESP packet receiving.
-
- (self) publish(topic = nil, payload = nil, qosLevel = nil, isDup = nil, isRetain = nil) { ... }
Sends the PUBLISH message to the remote MQTT server.
-
- (self) publish_complete_handler { ... }
Sets handler which will be called each time publish is completed.
-
- (self) publish_handler { ... }
Sets handler which will be called each time server publish something to client.
-
- (self) subscribe(param_1 = nil, param_2 = nil)
Subscribes to the topic with a specified QoS level.
-
- (self) subscribe_complete_handler { ... }
Sets handler which will be called after SUBACK packet receiving.
-
- (self) unsubscribe(topic = nil) { ... }
Unsubscribe from receiving messages on given topic.
-
- (self) unsubscribe_complete_handler { ... }
Sets handler which will be called after UNSUBACK packet receiving.
Class Method Details
+ (Boolean) accept?(obj)
22 23 24 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-mqtt-server/mqtt_client.rb', line 22 def @@j_api_type.accept?(obj) obj.class == MqttClient end |
+ (::VertxMqttServer::MqttClient) create(vertx = nil, options = nil)
Return an MQTT client instance
41 42 43 44 45 46 47 48 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-mqtt-server/mqtt_client.rb', line 41 def self.create(vertx=nil,=nil) if vertx.class.method_defined?(:j_del) && !block_given? && == nil return ::Vertx::Util::Utils.safe_create(Java::IoVertxMqtt::MqttClient.java_method(:create, [Java::IoVertxCore::Vertx.java_class]).call(vertx.j_del),::VertxMqttServer::MqttClient) elsif vertx.class.method_defined?(:j_del) && .class == Hash && !block_given? return ::Vertx::Util::Utils.safe_create(Java::IoVertxMqtt::MqttClient.java_method(:create, [Java::IoVertxCore::Vertx.java_class,Java::IoVertxMqtt::MqttClientOptions.java_class]).call(vertx.j_del,Java::IoVertxMqtt::MqttClientOptions.new(::Vertx::Util::Utils.to_json_object())),::VertxMqttServer::MqttClient) end raise ArgumentError, "Invalid arguments when calling create(#{vertx},#{})" end |
+ (Object) j_api_type
31 32 33 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-mqtt-server/mqtt_client.rb', line 31 def self.j_api_type @@j_api_type end |
+ (Object) j_class
34 35 36 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-mqtt-server/mqtt_client.rb', line 34 def self.j_class Java::IoVertxMqtt::MqttClient.java_class end |
+ (Object) unwrap(obj)
28 29 30 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-mqtt-server/mqtt_client.rb', line 28 def @@j_api_type.unwrap(obj) obj.j_del end |
+ (Object) wrap(obj)
25 26 27 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-mqtt-server/mqtt_client.rb', line 25 def @@j_api_type.wrap(obj) MqttClient.new(obj) end |
Instance Method Details
- (String) client_id
Returns the client identifier
221 222 223 224 225 226 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-mqtt-server/mqtt_client.rb', line 221 def client_id if !block_given? return @j_del.java_method(:clientId, []).call() end raise ArgumentError, "Invalid arguments when calling client_id()" end |
- (self) close_handler { ... }
Set a handler that will be called when the connection with server is closed
203 204 205 206 207 208 209 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-mqtt-server/mqtt_client.rb', line 203 def close_handler if block_given? @j_del.java_method(:closeHandler, [Java::IoVertxCore::Handler.java_class]).call(Proc.new { yield }) return self end raise ArgumentError, "Invalid arguments when calling close_handler()" end |
- (self) connect { ... }
Connects to an MQTT server calling connectHandler after connection
52 53 54 55 56 57 58 59 60 61 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-mqtt-server/mqtt_client.rb', line 52 def connect if !block_given? @j_del.java_method(:connect, []).call() return self elsif block_given? @j_del.java_method(:connect, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::VertxMqttServer::MqttConnAckMessage) : nil) })) return self end raise ArgumentError, "Invalid arguments when calling connect()" end |
- (self) disconnect { ... }
Disconnects from the MQTT server calling disconnectHandler after disconnection
65 66 67 68 69 70 71 72 73 74 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-mqtt-server/mqtt_client.rb', line 65 def disconnect if !block_given? @j_del.java_method(:disconnect, []).call() return self elsif block_given? @j_del.java_method(:disconnect, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |ar| yield(ar.failed ? ar.cause : nil) })) return self end raise ArgumentError, "Invalid arguments when calling disconnect()" end |
- (self) exception_handler { ... }
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
193 194 195 196 197 198 199 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-mqtt-server/mqtt_client.rb', line 193 def exception_handler if block_given? @j_del.java_method(:exceptionHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.from_throwable(event)) })) return self end raise ArgumentError, "Invalid arguments when calling exception_handler()" end |
- (self) ping
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
213 214 215 216 217 218 219 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-mqtt-server/mqtt_client.rb', line 213 def ping if !block_given? @j_del.java_method(:ping, []).call() return self end raise ArgumentError, "Invalid arguments when calling ping()" end |
- (self) ping_response_handler { ... }
Sets handler which will be called after PINGRESP packet receiving
180 181 182 183 184 185 186 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-mqtt-server/mqtt_client.rb', line 180 def ping_response_handler if block_given? @j_del.java_method(:pingResponseHandler, [Java::IoVertxCore::Handler.java_class]).call(Proc.new { yield }) return self end raise ArgumentError, "Invalid arguments when calling ping_response_handler()" end |
- (self) publish(topic = nil, payload = nil, qosLevel = nil, isDup = nil, isRetain = nil) { ... }
Sends the PUBLISH message to the remote MQTT server
83 84 85 86 87 88 89 90 91 92 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-mqtt-server/mqtt_client.rb', line 83 def publish(topic=nil,payload=nil,qosLevel=nil,isDup=nil,isRetain=nil) if topic.class == String && payload.class.method_defined?(:j_del) && qosLevel.class == Symbol && (isDup.class == TrueClass || isDup.class == FalseClass) && (isRetain.class == TrueClass || isRetain.class == FalseClass) && !block_given? @j_del.java_method(:publish, [Java::java.lang.String.java_class,Java::IoVertxCoreBuffer::Buffer.java_class,Java::IoNettyHandlerCodecMqtt::MqttQoS.java_class,Java::boolean.java_class,Java::boolean.java_class]).call(topic,payload.j_del,Java::IoNettyHandlerCodecMqtt::MqttQoS.valueOf(qosLevel.to_s),isDup,isRetain) return self elsif topic.class == String && payload.class.method_defined?(:j_del) && qosLevel.class == Symbol && (isDup.class == TrueClass || isDup.class == FalseClass) && (isRetain.class == TrueClass || isRetain.class == FalseClass) && block_given? @j_del.java_method(:publish, [Java::java.lang.String.java_class,Java::IoVertxCoreBuffer::Buffer.java_class,Java::IoNettyHandlerCodecMqtt::MqttQoS.java_class,Java::boolean.java_class,Java::boolean.java_class,Java::IoVertxCore::Handler.java_class]).call(topic,payload.j_del,Java::IoNettyHandlerCodecMqtt::MqttQoS.valueOf(qosLevel.to_s),isDup,isRetain,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result : nil) })) return self end raise ArgumentError, "Invalid arguments when calling publish(#{topic},#{payload},#{qosLevel},#{isDup},#{isRetain})" end |
- (self) publish_complete_handler { ... }
Sets handler which will be called each time publish is completed
96 97 98 99 100 101 102 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-mqtt-server/mqtt_client.rb', line 96 def publish_complete_handler if block_given? @j_del.java_method(:publishCompleteHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(event) })) return self end raise ArgumentError, "Invalid arguments when calling publish_complete_handler()" end |
- (self) publish_handler { ... }
Sets handler which will be called each time server publish something to client
106 107 108 109 110 111 112 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-mqtt-server/mqtt_client.rb', line 106 def publish_handler if block_given? @j_del.java_method(:publishHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::VertxMqttServer::MqttPublishMessage)) })) return self end raise ArgumentError, "Invalid arguments when calling publish_handler()" end |
- (self) subscribe(topics) - (self) subscribe(topic, qos) - (self) subscribe(topics, subscribeSentHandler) { ... } - (self) subscribe(topic, qos, subscribeSentHandler) { ... }
Subscribes to the topic with a specified QoS level
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-mqtt-server/mqtt_client.rb', line 137 def subscribe(param_1=nil,param_2=nil) if param_1.class == Hash && !block_given? && param_2 == nil @j_del.java_method(:subscribe, [Java::JavaUtil::Map.java_class]).call(Hash[param_1.map { |k,v| [k,::Vertx::Util::Utils.to_integer(v)] }]) return self elsif param_1.class == String && param_2.class == Fixnum && !block_given? @j_del.java_method(:subscribe, [Java::java.lang.String.java_class,Java::int.java_class]).call(param_1,param_2) return self elsif param_1.class == Hash && block_given? && param_2 == nil @j_del.java_method(:subscribe, [Java::JavaUtil::Map.java_class,Java::IoVertxCore::Handler.java_class]).call(Hash[param_1.map { |k,v| [k,::Vertx::Util::Utils.to_integer(v)] }],(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result : nil) })) return self elsif param_1.class == String && param_2.class == Fixnum && block_given? @j_del.java_method(:subscribe, [Java::java.lang.String.java_class,Java::int.java_class,Java::IoVertxCore::Handler.java_class]).call(param_1,param_2,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result : nil) })) return self end raise ArgumentError, "Invalid arguments when calling subscribe(#{param_1},#{param_2})" end |
- (self) subscribe_complete_handler { ... }
Sets handler which will be called after SUBACK packet receiving
116 117 118 119 120 121 122 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-mqtt-server/mqtt_client.rb', line 116 def subscribe_complete_handler if block_given? @j_del.java_method(:subscribeCompleteHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::VertxMqttServer::MqttSubAckMessage)) })) return self end raise ArgumentError, "Invalid arguments when calling subscribe_complete_handler()" end |
- (self) unsubscribe(topic = nil) { ... }
Unsubscribe from receiving messages on given topic
167 168 169 170 171 172 173 174 175 176 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-mqtt-server/mqtt_client.rb', line 167 def unsubscribe(topic=nil) if topic.class == String && !block_given? @j_del.java_method(:unsubscribe, [Java::java.lang.String.java_class]).call(topic) return self elsif topic.class == String && block_given? @j_del.java_method(:unsubscribe, [Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(topic,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result : nil) })) return self end raise ArgumentError, "Invalid arguments when calling unsubscribe(#{topic})" end |
- (self) unsubscribe_complete_handler { ... }
Sets handler which will be called after UNSUBACK packet receiving
156 157 158 159 160 161 162 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-mqtt-server/mqtt_client.rb', line 156 def unsubscribe_complete_handler if block_given? @j_del.java_method(:unsubscribeCompleteHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(event) })) return self end raise ArgumentError, "Invalid arguments when calling unsubscribe_complete_handler()" end |