Class List Method List File List

# Class: VertxMqtt::MqttClient

Inherits:
  Object
  - Object
  - VertxMqtt::MqttClient
  show all
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)

Returns:

- (`Boolean`)

    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

Parameters:

- vertx (`::Vertx::Vertx`) (defaults to: `nil`) —
  Vert.x instance
- options (`Hash`) (defaults to: `nil`) —
  MQTT client options

Returns:

- (`::VertxMqtt::MqttClient`) —
  MQTT client instance

Raises:

- (`ArgumentError`)

    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,options=nil)
      if vertx.class.method_defined?(:j_del) && !block_given? && options == 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) && options.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(options))),::VertxMqtt::MqttClient)
      end
      raise ArgumentError, "Invalid arguments when calling create(#{vertx},#{options})"
    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

Returns:

- (`String`) —
  the client identifier

Raises:

- (`ArgumentError`)

    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

Yields:

- handler to call

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    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

Parameters:

- port (`Fixnum`) (defaults to: `nil`) —
  port of the MQTT server
- host (`String`) (defaults to: `nil`) —
  hostname/ip address of the MQTT server
- serverName (`String`) (defaults to: `nil`) —
  the SNI server name

Yields:

- handler called when the asynchronous connect call ends

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    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

Returns:

- (`true`, `false`) —
  if the connection between client and remote server is established/open

Raises:

- (`ArgumentError`)

    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

Yields:

- handler called when asynchronous disconnect call ends

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    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

Yields:

- the exception handler

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    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

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    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

Yields:

- handler to call

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    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

Parameters:

- topic (`String`) (defaults to: `nil`) —
  topic on which the message is published
- payload (`::Vertx::Buffer`) (defaults to: `nil`) —
  message payload
- qosLevel (`:AT_MOST_ONCE`, `:AT_LEAST_ONCE`, `:EXACTLY_ONCE`, `:FAILURE`) (defaults to: `nil`) —
  QoS level
- isDup (`true`, `false`) (defaults to: `nil`) —
  if the message is a duplicate
- isRetain (`true`, `false`) (defaults to: `nil`) —
  if the message needs to be retained

Yields:

- handler called after PUBLISH packet sent with packetid (not when QoS 0)

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    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

Yields:

- handler called with the packetId

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    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

Yields:

- handler to call

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    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

Overloads:

- - (`self`) subscribe(topics)

  Parameters:

  - topics (`Hash{String => Fixnum}`) —
    topics and related QoS levels to subscribe to
- - (`self`) subscribe(topic, qos)

  Parameters:

  - topic (`String`) —
    topic you subscribe on
  - qos (`Fixnum`) —
    QoS level
- - (`self`) subscribe(topics, subscribeSentHandler) { ... }

  Parameters:

  - topics (`Hash{String => Fixnum}`) —
    topics you subscribe on

  Yields:

  - handler called after SUBSCRIBE packet sent with packetid
- - (`self`) subscribe(topic, qos, subscribeSentHandler) { ... }

  Parameters:

  - topic (`String`) —
    topic you subscribe on
  - qos (`Fixnum`) —
    QoS level

  Yields:

  - handler called after SUBSCRIBE packet sent with packetid

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    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

Yields:

- handler to call. List inside is a granted QoS array

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    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

Parameters:

- topic (`String`) (defaults to: `nil`) —
  Topic you want to unsubscribe from

Yields:

- handler called after UNSUBSCRIBE packet sent

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    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

Yields:

- handler to call with the packetid

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    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