Class List Method List File List

# Class: Vertx::HttpServer

Inherits:
  Object
  - Object
  - Vertx::HttpServer
  show all
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 #web_socket_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) actual_port
  The actual port the server is listening on.
- - (void) close { ... }
  Like #close but supplying a handler that will be called when the server is actually closed (or has failed).
- - (self) connection_handler { ... }
  Set a connection handler for the server.
- - (self) exception_handler { ... }
  Set an exception handler called for socket errors happening before the HTTP connection is established, e.g during the TLS handshake.
- - (self) listen(param_1 = nil, param_2 = nil)
  Like #listen but supplying a handler that will be called when the server is actually listening (or has failed).
- - (true, false) metrics_enabled?
  Whether the metrics are enabled for this measured object.
- - (self) request_handler { ... }
  Set the request handler for the server to requestHandler.
- - (::Vertx::ReadStream) request_stream
  Return the request stream for the server.
- - (self) web_socket_handler { ... }
  Set the WebSocket handler for the server to wsHandler.
- - (::Vertx::ReadStream) web_socket_stream
  Return the WebSocket stream for the server.
- - (self) websocket_handler { ... }
  Set the WebSocket handler for the server to wsHandler.
- - (::Vertx::ReadStream) websocket_stream
  Return the WebSocket stream for the server.

## Class Method Details

### + (`Boolean`) accept?(obj)

Returns:

- (`Boolean`)

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

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

### + (`Object`) j_api_type

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

    def self.j_api_type
      @@j_api_type
    end

### + (`Object`) j_class

    42
    43
    44
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/http_server.rb', line 42

    def self.j_class
      Java::IoVertxCoreHttp::HttpServer.java_class
    end

### + (`Object`) unwrap(obj)

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

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

### + (`Object`) wrap(obj)

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

    def @@j_api_type.wrap(obj)
      HttpServer.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

Returns:

- (`Fixnum`) —
  the actual port the server is listening on.

Raises:

- (`ArgumentError`)

    203
    204
    205
    206
    207
    208
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/http_server.rb', line 203

    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.

Like #close but supplying a handler that will be called when the server is actually closed (or has failed).

Yields:

- the handler

Raises:

- (`ArgumentError`)

    192
    193
    194
    195
    196
    197
    198
    199
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/http_server.rb', line 192

    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`) connection_handler { ... }

Set a connection handler for the server.

Yields:

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    79
    80
    81
    82
    83
    84
    85
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/http_server.rb', line 79

    def connection_handler
      if block_given?
        @j_del.java_method(:connectionHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::Vertx::HttpConnection)) }))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling connection_handler()"
    end

### - (`self`) exception_handler { ... }

Set an exception handler called for socket errors happening before the HTTP connection is established, e.g during the TLS handshake.

Yields:

- the handler to set

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    90
    91
    92
    93
    94
    95
    96
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/http_server.rb', line 90

    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 - (`self`) listen(port) - (`self`) listen(listenHandler) { ... } - (`self`) listen(port, host) - (`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).

Overloads:

- - (`self`) listen(port)

  Parameters:

  - port (`Fixnum`) —
    the port to listen on
- - (`self`) listen(listenHandler) { ... }

  Yields:

  - the listen handler
- - (`self`) listen(port, host)

  Parameters:

  - port (`Fixnum`) —
    the port to listen on
  - host (`String`) —
    the host to listen on
- - (`self`) listen(address, listenHandler) { ... }

  Parameters:

  - address (`::Vertx::SocketAddress`) —
    the address to listen on

  Yields:

  - the listen handler
- - (`self`) listen(port, listenHandler) { ... }

  Parameters:

  - port (`Fixnum`) —
    the port to listen on

  Yields:

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

  Parameters:

  - port (`Fixnum`) —
    the port to listen on
  - host (`String`) —
    the host to listen on

  Yields:

  - the listen handler

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/http_server.rb', line 164

    def listen(param_1=nil,param_2=nil)
      if !block_given? && param_1 == nil && param_2 == nil
        @j_del.java_method(:listen, []).call()
        return self
      elsif param_1.class == Fixnum && !block_given? && param_2 == nil
        @j_del.java_method(:listen, [Java::int.java_class]).call(param_1)
        return self
      elsif block_given? && param_1 == nil && param_2 == 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,::Vertx::HttpServer) : nil) }))
        return self
      elsif param_1.class == Fixnum && param_2.class == String && !block_given?
        @j_del.java_method(:listen, [Java::int.java_class,Java::java.lang.String.java_class]).call(param_1,param_2)
        return self
      elsif param_1.class.method_defined?(:j_del) && block_given? && param_2 == nil
        @j_del.java_method(:listen, [Java::IoVertxCoreNet::SocketAddress.java_class,Java::IoVertxCore::Handler.java_class]).call(param_1.j_del,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::Vertx::HttpServer) : nil) }))
        return self
      elsif param_1.class == Fixnum && block_given? && param_2 == nil
        @j_del.java_method(:listen, [Java::int.java_class,Java::IoVertxCore::Handler.java_class]).call(param_1,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::Vertx::HttpServer) : nil) }))
        return self
      elsif param_1.class == Fixnum && param_2.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(param_1,param_2,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::Vertx::HttpServer) : nil) }))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling listen(#{param_1},#{param_2})"
    end

### - (`true`, `false`) metrics_enabled?

Whether the metrics are enabled for this measured object

Returns:

- (`true`, `false`) —
  `true` if metrics are enabled

Raises:

- (`ArgumentError`)

    47
    48
    49
    50
    51
    52
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/http_server.rb', line 47

    def metrics_enabled?
      if !block_given?
        return @j_del.java_method(:isMetricsEnabled, []).call()
      end
      raise ArgumentError, "Invalid arguments when calling metrics_enabled?()"
    end

### - (`self`) request_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.

Yields:

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    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 69

    def request_handler
      if block_given?
        @j_del.java_method(:requestHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::Vertx::HttpServerRequest)) }))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling request_handler()"
    end

### - (`::Vertx::ReadStream`) request_stream

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 .

Returns:

- (`::Vertx::ReadStream`) —
  the request stream

Raises:

- (`ArgumentError`)

    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/http_server.rb', line 56

    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
      raise ArgumentError, "Invalid arguments when calling request_stream()"
    end

### - (`self`) web_socket_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.

Yields:

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    136
    137
    138
    139
    140
    141
    142
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/http_server.rb', line 136

    def web_socket_handler
      if block_given?
        @j_del.java_method(:webSocketHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::Vertx::ServerWebSocket)) }))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling web_socket_handler()"
    end

### - (`::Vertx::ReadStream`) web_socket_stream

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 .

Returns:

- (`::Vertx::ReadStream`) —
  the WebSocket stream

Raises:

- (`ArgumentError`)

    112
    113
    114
    115
    116
    117
    118
    119
    120
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/http_server.rb', line 112

    def web_socket_stream
      if !block_given?
        if @cached_web_socket_stream != nil
          return @cached_web_socket_stream
        end
        return @cached_web_socket_stream = ::Vertx::Util::Utils.safe_create(@j_del.java_method(:webSocketStream, []).call(),::Vertx::ReadStreamImpl,::Vertx::ServerWebSocket.j_api_type)
      end
      raise ArgumentError, "Invalid arguments when calling web_socket_stream()"
    end

### - (`self`) websocket_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.

Yields:

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    125
    126
    127
    128
    129
    130
    131
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/http_server.rb', line 125

    def websocket_handler
      if block_given?
        @j_del.java_method(:websocketHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::Vertx::ServerWebSocket)) }))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling websocket_handler()"
    end

### - (`::Vertx::ReadStream`) websocket_stream

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 .

Returns:

- (`::Vertx::ReadStream`) —
  the WebSocket stream

Raises:

- (`ArgumentError`)

    100
    101
    102
    103
    104
    105
    106
    107
    108
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/http_server.rb', line 100

    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
      raise ArgumentError, "Invalid arguments when calling websocket_stream()"
    end