Class: VertxMqtt::MqttServer
- Inherits:
-
Object
- Object
- VertxMqtt::MqttServer
- 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)
- + (Boolean) accept?(obj)
-
+ (::VertxMqtt::MqttServer) create(vertx = nil, options = nil)
Return an MQTT server instance.
- + (Object) j_api_type
- + (Object) j_class
- + (Object) unwrap(obj)
- + (Object) wrap(obj)
Instance Method Summary (collapse)
-
- (Fixnum) actual_port
The actual port the server is listening on.
-
- (void) close { ... }
Close the server supplying an handler that will be called when the server is actually closed (or has failed).
-
- (self) endpoint_handler { ... }
Set the endpoint handler for the server.
-
- (self) exception_handler { ... }
Set an exception handler for the server, that will be called when an error happens independantly of an accepted MqttEndpoint, like a rejected connection.
-
- (self) listen(port = nil, host = nil) { ... }
Start the server listening for incoming connections on the port and host specified It ignores any options specified through the constructor.
Class Method Details
+ (Boolean) accept?(obj)
24 25 26 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_server.rb', line 24 def @@j_api_type.accept?(obj) obj.class == MqttServer end |
+ (::VertxMqtt::MqttServer) create(vertx = nil, options = nil)
Return an MQTT server instance
43 44 45 46 47 48 49 50 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_server.rb', line 43 def self.create(vertx=nil,=nil) if vertx.class.method_defined?(:j_del) && !block_given? && == nil return ::Vertx::Util::Utils.safe_create(Java::IoVertxMqtt::MqttServer.java_method(:create, [Java::IoVertxCore::Vertx.java_class]).call(vertx.j_del),::VertxMqtt::MqttServer) elsif vertx.class.method_defined?(:j_del) && .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(vertx.j_del,Java::IoVertxMqtt::MqttServerOptions.new(::Vertx::Util::Utils.to_json_object())),::VertxMqtt::MqttServer) end raise ArgumentError, "Invalid arguments when calling create(#{vertx},#{})" end |
+ (Object) j_api_type
33 34 35 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_server.rb', line 33 def self.j_api_type @@j_api_type end |
+ (Object) j_class
36 37 38 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_server.rb', line 36 def self.j_class Java::IoVertxMqtt::MqttServer.java_class end |
+ (Object) unwrap(obj)
30 31 32 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_server.rb', line 30 def @@j_api_type.unwrap(obj) obj.j_del end |
+ (Object) wrap(obj)
27 28 29 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_server.rb', line 27 def @@j_api_type.wrap(obj) MqttServer.new(obj) end |
Instance Method Details
- (Fixnum) actual_port
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
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 104 def actual_port if !block_given? return @j_del.java_method(:actualPort, []).call() end raise ArgumentError, "Invalid arguments when calling actual_port()" end |
- (void) close { ... }
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).
113 114 115 116 117 118 119 120 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_server.rb', line 113 def close if !block_given? return @j_del.java_method(:close, []).call() elsif block_given? return @j_del.java_method(:close, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |ar| yield(ar.failed ? ar.cause : nil) })) end raise ArgumentError, "Invalid arguments when calling close()" end |
- (self) endpoint_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
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 83 def endpoint_handler if block_given? @j_del.java_method(:endpointHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::VertxMqtt::MqttEndpoint)) })) return self end raise ArgumentError, "Invalid arguments when calling endpoint_handler()" end |
- (self) exception_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
94 95 96 97 98 99 100 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_server.rb', line 94 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) listen(port = nil, host = nil) { ... }
Start the server listening for incoming connections on the port and host specified
It ignores any options specified through the constructor
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_server.rb', line 57 def listen(port=nil,host=nil) if !block_given? && port == nil && host == nil @j_del.java_method(:listen, []).call() return self elsif port.class == Fixnum && !block_given? && host == nil @j_del.java_method(:listen, [Java::int.java_class]).call(port) return self elsif block_given? && port == nil && host == nil @j_del.java_method(:listen, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::VertxMqtt::MqttServer) : nil) })) return self elsif port.class == Fixnum && host.class == String && !block_given? @j_del.java_method(:listen, [Java::int.java_class,Java::java.lang.String.java_class]).call(port,host) return self elsif port.class == Fixnum && block_given? && host == nil @j_del.java_method(:listen, [Java::int.java_class,Java::IoVertxCore::Handler.java_class]).call(port,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::VertxMqtt::MqttServer) : nil) })) return self elsif port.class == Fixnum && host.class == String && block_given? @j_del.java_method(:listen, [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::MqttServer) : nil) })) return self end raise ArgumentError, "Invalid arguments when calling listen(#{port},#{host})" end |