Class: VertxMqtt::MqttServer

Inherits:
Object
  • Object
show all
Defined in:
/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_server.rb

Overview

An MQTT server

You can accept incoming MQTT connection requests providing a #endpoint_handler. As the requests arrive, the handler will be called with an instance of MqttEndpoint in order to manage the communication with the remote MQTT client.

Constant Summary

@@j_api_type =
Object.new

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Boolean) accept?(obj)

Returns:

  • (Boolean)


26
27
28
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_server.rb', line 26

def @@j_api_type.accept?(obj)
  obj.class == MqttServer
end

+ (::VertxMqtt::MqttServer) create(vertx) + (::VertxMqtt::MqttServer) create(vertx, options)

Return an MQTT server instance

Overloads:

Returns:



78
79
80
81
82
83
84
85
86
87
88
89
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_server.rb', line 78

def self.create(*args)
  if args[0].class.method_defined?(:j_del) && !block_given? && args[1] == nil
    return ::Vertx::Util::Utils.safe_create(Java::IoVertxMqtt::MqttServer.java_method(:create, [Java::IoVertxCore::Vertx.java_class]).call(args[0].j_del),::VertxMqtt::MqttServer)
  elsif args[0].class.method_defined?(:j_del) && args[1].class == Hash && !block_given?
    return ::Vertx::Util::Utils.safe_create(Java::IoVertxMqtt::MqttServer.java_method(:create, [Java::IoVertxCore::Vertx.java_class,Java::IoVertxMqtt::MqttServerOptions.java_class]).call(args[0].j_del,Java::IoVertxMqtt::MqttServerOptions.new(::Vertx::Util::Utils.to_json_object(args[1]))),::VertxMqtt::MqttServer)
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling create(#{args[0]},#{args[1]})"
  end
end

+ (Object) j_api_type



35
36
37
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_server.rb', line 35

def self.j_api_type
  @@j_api_type
end

+ (Object) j_class



38
39
40
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_server.rb', line 38

def self.j_class
  Java::IoVertxMqtt::MqttServer.java_class
end

+ (Object) unwrap(obj)



32
33
34
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_server.rb', line 32

def @@j_api_type.unwrap(obj)
  obj.j_del
end

+ (Object) wrap(obj)



29
30
31
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_server.rb', line 29

def @@j_api_type.wrap(obj)
  MqttServer.new(obj)
end

Instance Method Details

- (Fixnum) actualPort

The actual port the server is listening on. This is useful if you bound the server specifying 0 as port number signifying an ephemeral port

Returns:

  • (Fixnum)
    the actual port the server is listening on.


61
62
63
64
65
66
67
68
69
70
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_server.rb', line 61

def actual_port
  if !block_given?
    return @j_del.java_method(:actualPort, []).call()
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling actual_port()"
  end
end

- (void) close(completionHandler) { ... }

This method returns an undefined value.

Close the server supplying an handler that will be called when the server is actually closed (or has failed).

Yields:

  • the handler called on completion


94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_server.rb', line 94

def close
  if true
    if (block_given?)
      return @j_del.java_method(:close, [Java::IoVertxCore::Handler.java_class]).call(block_given? ? Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? nil : nil) } : promise)
    else
      promise = ::Vertx::Util::Utils.promise
      @j_del.java_method(:close, [Java::IoVertxCore::Handler.java_class]).call(block_given? ? Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? nil : nil) } : promise)
      return ::Vertx::Util::Utils.safe_create(promise.future(),::Vertx::Future, nil)
    end
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling close()"
  end
end

- (self) endpointHandler(handler) { ... }

Set the endpoint handler for the server. If an MQTT client connect to the server a new MqttEndpoint instance will be created and passed to the handler

Yields:

  • the endpoint handler

Returns:

  • (self)


46
47
48
49
50
51
52
53
54
55
56
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_server.rb', line 46

def endpoint_handler
  if true
    @j_del.java_method(:endpointHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::VertxMqtt::MqttEndpoint)) unless !block_given? }))
    return self
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling endpoint_handler()"
  end
end

- (self) exceptionHandler(handler) { ... }

Set an exception handler for the server, that will be called when an error happens independantly of an accepted VertxMqtt::MqttEndpoint, like a rejected connection

Yields:

  • the exception handler

Returns:

  • (self)


115
116
117
118
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_server.rb', line 115

def exception_handler
  if true
    @j_del.java_method(:exceptionHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.from_throwable(event)) unless !block_given? }))
    return self
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling exception_handler()"
  end
end

- (self) listen(listenHandler) { ... } - (self) listen(port, listenHandler) { ... } - (self) listen(port, host, listenHandler) { ... }

Start the server listening for incoming connections on the port and host specified It ignores any options specified through the constructor

Overloads:

  • - (self) listen(listenHandler) { ... }

    Yields:

    • handler called when the asynchronous listen call ends
  • - (self) listen(port, listenHandler) { ... }

    Parameters:

    • port (Fixnum)
      the port to listen on

    Yields:

    • handler called when the asynchronous listen call ends
  • - (self) listen(port, host, listenHandler) { ... }

    Parameters:

    • port (Fixnum)
      the port to listen on
    • host (String)
      the host to listen on

    Yields:

    • handler called when the asynchronous listen call ends

Returns:

  • (self)


138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_server.rb', line 138

def listen(*args)
  if true && args[0] == nil && args[1] == nil
    if (block_given?)
      @j_del.java_method(:listen, [Java::IoVertxCore::Handler.java_class]).call(block_given? ? Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::VertxMqtt::MqttServer) : nil) } : promise)
      return self
    else
      promise = ::Vertx::Util::Utils.promise
      @j_del.java_method(:listen, [Java::IoVertxCore::Handler.java_class]).call(block_given? ? Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::VertxMqtt::MqttServer) : nil) } : promise)
      return ::Vertx::Util::Utils.safe_create(promise.future(),::Vertx::Future,::VertxMqtt::MqttServer.j_api_type)
    end
  elsif args[0].class == Fixnum && true && args[1] == nil
    if (block_given?)
      @j_del.java_method(:listen, [Java::int.java_class,Java::IoVertxCore::Handler.java_class]).call(args[0],block_given? ? Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::VertxMqtt::MqttServer) : nil) } : promise)
      return self
    else
      promise = ::Vertx::Util::Utils.promise
      @j_del.java_method(:listen, [Java::int.java_class,Java::IoVertxCore::Handler.java_class]).call(args[0],block_given? ? Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::VertxMqtt::MqttServer) : nil) } : promise)
      return ::Vertx::Util::Utils.safe_create(promise.future(),::Vertx::Future,::VertxMqtt::MqttServer.j_api_type)
    end
  elsif args[0].class == Fixnum && args[1].class == String && true
    if (block_given?)
      @j_del.java_method(:listen, [Java::int.java_class,Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(args[0],args[1],block_given? ? Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::VertxMqtt::MqttServer) : nil) } : promise)
      return self
    else
      promise = ::Vertx::Util::Utils.promise
      @j_del.java_method(:listen, [Java::int.java_class,Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(args[0],args[1],block_given? ? Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::VertxMqtt::MqttServer) : nil) } : promise)
      return ::Vertx::Util::Utils.safe_create(promise.future(),::Vertx::Future,::VertxMqtt::MqttServer.j_api_type)
    end
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling listen(#{args[0]},#{args[1]})"
  end
end