Class: VertxMqtt::MqttClient
- Inherits:
-
Object
- Object
- VertxMqtt::MqttClient
- Defined in:
- /Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb
Overview
An MQTT client
Constant Summary
- @@j_api_type =
Object.new
Class Method Summary (collapse)
- + (Boolean) accept?(obj)
-
+ (::VertxMqtt::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(port = nil, host = nil, serverName = nil) { ... }
Connects to an MQTT server calling connectHandler after connection.
-
- (true, false) connected?
If the connection between client and remote server is established/open.
-
- (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_completion_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_completion_handler { ... }
Sets handler which will be called after SUBACK packet receiving.
-
- (self) unsubscribe(topic = nil) { ... }
Unsubscribe from receiving messages on given topic.
-
- (self) unsubscribe_completion_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-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 22 def @@j_api_type.accept?(obj) obj.class == MqttClient end |
+ (::VertxMqtt::MqttClient) create(vertx = nil, options = nil)
Return an MQTT client instance
41 42 43 44 45 46 47 48 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/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),::VertxMqtt::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())),::VertxMqtt::MqttClient) end raise ArgumentError, "Invalid arguments when calling create(#{vertx},#{})" end |
+ (Object) j_api_type
31 32 33 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/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-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/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-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/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-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/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
224 225 226 227 228 229 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 224 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
206 207 208 209 210 211 212 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 206 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(port = nil, host = nil, serverName = nil) { ... }
Connects to an MQTT server calling connectHandler after connection
55 56 57 58 59 60 61 62 63 64 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 55 def connect(port=nil,host=nil,serverName=nil) if port.class == Fixnum && host.class == String && block_given? && serverName == nil @j_del.java_method(:connect, [Java::int.java_class,Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(port,host,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::VertxMqtt::MqttConnAckMessage) : nil) })) return self elsif port.class == Fixnum && host.class == String && serverName.class == String && block_given? @j_del.java_method(:connect, [Java::int.java_class,Java::java.lang.String.java_class,Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(port,host,serverName,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::VertxMqtt::MqttConnAckMessage) : nil) })) return self end raise ArgumentError, "Invalid arguments when calling connect(#{port},#{host},#{serverName})" end |
- (true, false) connected?
Returns if the connection between client and remote server is established/open
231 232 233 234 235 236 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 231 def connected? if !block_given? return @j_del.java_method(:isConnected, []).call() end raise ArgumentError, "Invalid arguments when calling connected?()" end |
- (self) disconnect { ... }
Disconnects from the MQTT server calling disconnectHandler after disconnection
68 69 70 71 72 73 74 75 76 77 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 68 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
196 197 198 199 200 201 202 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 196 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
216 217 218 219 220 221 222 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 216 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
183 184 185 186 187 188 189 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 183 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
86 87 88 89 90 91 92 93 94 95 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 86 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_completion_handler { ... }
Sets handler which will be called each time publish is completed
99 100 101 102 103 104 105 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 99 def publish_completion_handler if block_given? @j_del.java_method(:publishCompletionHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(event) })) return self end raise ArgumentError, "Invalid arguments when calling publish_completion_handler()" end |
- (self) publish_handler { ... }
Sets handler which will be called each time server publish something to client
109 110 111 112 113 114 115 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 109 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,::VertxMqtt::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
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 140 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_completion_handler { ... }
Sets handler which will be called after SUBACK packet receiving
119 120 121 122 123 124 125 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 119 def subscribe_completion_handler if block_given? @j_del.java_method(:subscribeCompletionHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::VertxMqtt::MqttSubAckMessage)) })) return self end raise ArgumentError, "Invalid arguments when calling subscribe_completion_handler()" end |
- (self) unsubscribe(topic = nil) { ... }
Unsubscribe from receiving messages on given topic
170 171 172 173 174 175 176 177 178 179 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 170 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_completion_handler { ... }
Sets handler which will be called after UNSUBACK packet receiving
159 160 161 162 163 164 165 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 159 def unsubscribe_completion_handler if block_given? @j_del.java_method(:unsubscribeCompletionHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(event) })) return self end raise ArgumentError, "Invalid arguments when calling unsubscribe_completion_handler()" end |