Class: Vertx::HttpServer
- Inherits:
-
Object
- Object
- Vertx::HttpServer
- Includes:
- Measured
- Defined in:
- /Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/http_server.rb
Overview
An HTTP and WebSockets server.
You receive HTTP requests by providing a #request_handler. As requests arrive on the server the handler will be called with the requests.
You receive WebSockets by providing a #websocket_handler. As WebSocket connections arrive on the server, the WebSocket is passed to the handler.
Constant Summary
- @@j_api_type =
Object.new
Class Method Summary (collapse)
- + (Boolean) accept?(obj)
- + (Object) j_api_type
- + (Object) j_class
- + (Object) unwrap(obj)
- + (Object) wrap(obj)
Instance Method Summary (collapse)
-
- (Fixnum) actualPort
The actual port the server is listening on.
-
- (void) close(completionHandler) { ... }
Like #close but supplying a handler that will be called when the server is actually closed (or has failed).
-
- (self) connectionHandler(handler) { ... }
Set a connection handler for the server.
-
- (self) exceptionHandler(handler) { ... }
Set an exception handler called for socket errors happening before the HTTP connection is established, e.g during the TLS handshake.
-
- (self) listen(*args)
Like #listen but supplying a handler that will be called when the server is actually listening (or has failed).
-
- (true, false) isMetricsEnabled
Whether the metrics are enabled for this measured object.
-
- (self) requestHandler(handler) { ... }
Set the request handler for the server to requestHandler.
-
- (::Vertx::ReadStream) requestStream
Return the request stream for the server.
-
- (self) websocketHandler(handler) { ... }
Set the websocket handler for the server to wsHandler.
-
- (::Vertx::ReadStream) websocketStream
Return the websocket stream for the server.
Class Method Details
+ (Boolean) accept?(obj)
32 33 34 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/http_server.rb', line 32 def @@j_api_type.accept?(obj) obj.class == HttpServer end |
+ (Object) j_api_type
41 42 43 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/http_server.rb', line 41 def self.j_api_type @@j_api_type end |
+ (Object) j_class
44 45 46 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/http_server.rb', line 44 def self.j_class Java::IoVertxCoreHttp::HttpServer.java_class end |
+ (Object) unwrap(obj)
38 39 40 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/http_server.rb', line 38 def @@j_api_type.unwrap(obj) obj.j_del end |
+ (Object) wrap(obj)
35 36 37 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/http_server.rb', line 35 def @@j_api_type.wrap(obj) HttpServer.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
97 98 99 100 101 102 103 104 105 106 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/http_server.rb', line 97 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.
Like #close but supplying a handler that will be called when the server is actually closed (or has failed).
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/http_server.rb', line 159 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) connectionHandler(handler) { ... }
Set a connection handler for the server.
111 112 113 114 115 116 117 118 119 120 121 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/http_server.rb', line 111 def connection_handler if true @j_del.java_method(:connectionHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::Vertx::HttpConnection)) unless !block_given? })) return self end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling connection_handler()" end end |
- (self) exceptionHandler(handler) { ... }
Set an exception handler called for socket errors happening before the HTTP connection
is established, e.g during the TLS handshake.
180 181 182 183 184 185 186 187 188 189 190 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/http_server.rb', line 180 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(address, listenHandler) { ... } - (self) listen(port, listenHandler) { ... } - (self) listen(port, host, listenHandler) { ... }
Like #listen but supplying a handler that will be called when the server is actually
listening (or has failed).
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/http_server.rb', line 206 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,::Vertx::HttpServer) : 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,::Vertx::HttpServer) : nil) } : promise) return ::Vertx::Util::Utils.safe_create(promise.future(),::Vertx::Future,::Vertx::HttpServer.j_api_type) end elsif args[0].class.method_defined?(:j_del) && true && args[1] == nil if (block_given?) @j_del.java_method(:listen, [Java::IoVertxCoreNet::SocketAddress.java_class,Java::IoVertxCore::Handler.java_class]).call(args[0].j_del,block_given? ? Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::Vertx::HttpServer) : nil) } : promise) return self else promise = ::Vertx::Util::Utils.promise @j_del.java_method(:listen, [Java::IoVertxCoreNet::SocketAddress.java_class,Java::IoVertxCore::Handler.java_class]).call(args[0].j_del,block_given? ? Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::Vertx::HttpServer) : nil) } : promise) return ::Vertx::Util::Utils.safe_create(promise.future(),::Vertx::Future,::Vertx::HttpServer.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,::Vertx::HttpServer) : 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,::Vertx::HttpServer) : nil) } : promise) return ::Vertx::Util::Utils.safe_create(promise.future(),::Vertx::Future,::Vertx::HttpServer.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,::Vertx::HttpServer) : 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,::Vertx::HttpServer) : nil) } : promise) return ::Vertx::Util::Utils.safe_create(promise.future(),::Vertx::Future,::Vertx::HttpServer.j_api_type) end end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling listen(#{args[0]},#{args[1]})" end end |
- (true, false) isMetricsEnabled
Whether the metrics are enabled for this measured object
50 51 52 53 54 55 56 57 58 59 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/http_server.rb', line 50 def metrics_enabled? if !block_given? return @j_del.java_method(:isMetricsEnabled, []).call() end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling metrics_enabled?()" end end |
- (self) requestHandler(handler) { ... }
Set the request handler for the server to
requestHandler
. As HTTP requests are received by the server,
instances of Vertx::HttpServerRequest will be created and passed to this handler.
65 66 67 68 69 70 71 72 73 74 75 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/http_server.rb', line 65 def request_handler if true @j_del.java_method(:requestHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::Vertx::HttpServerRequest)) unless !block_given? })) return self end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling request_handler()" end end |
- (::Vertx::ReadStream) requestStream
Return the request stream for the server. As HTTP requests are received by the server,
instances of Vertx::HttpServerRequest will be created and passed to the stream .
126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/http_server.rb', line 126 def request_stream if !block_given? if @cached_request_stream != nil return @cached_request_stream end return @cached_request_stream = ::Vertx::Util::Utils.safe_create(@j_del.java_method(:requestStream, []).call(),::Vertx::ReadStreamImpl,::Vertx::HttpServerRequest.j_api_type) end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling request_stream()" end end |
- (self) websocketHandler(handler) { ... }
Set the websocket handler for the server to
wsHandler
. If a websocket connect handshake is successful a
new ServerWebSocket instance will be created and passed to the handler.
144 145 146 147 148 149 150 151 152 153 154 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/http_server.rb', line 144 def websocket_handler if true @j_del.java_method(:websocketHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::Vertx::ServerWebSocket)) unless !block_given? })) return self end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling websocket_handler()" end end |
- (::Vertx::ReadStream) websocketStream
Return the websocket stream for the server. If a websocket connect handshake is successful a
new ServerWebSocket instance will be created and passed to the stream .
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/http_server.rb', line 80 def websocket_stream if !block_given? if @cached_websocket_stream != nil return @cached_websocket_stream end return @cached_websocket_stream = ::Vertx::Util::Utils.safe_create(@j_del.java_method(:websocketStream, []).call(),::Vertx::ReadStreamImpl,::Vertx::ServerWebSocket.j_api_type) end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling websocket_stream()" end end |