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/src/main/resources/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.

## Instance Method Summary (collapse)

- - (void) close { ... }
  Like #close but supplying a handler that will be called when the server is actually closed (or has failed).
- - (self) listen(port = nil, host = 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.
- - (::Vertx::HttpServer) request_handler { ... }
  Set the request handler for the server to requestHandler.
- - (::Vertx::HttpServerRequestStream) request_stream
  Return the request stream for the server.
- - (::Vertx::HttpServer) websocket_handler { ... }
  Set the websocket handler for the server to wsHandler.
- - (::Vertx::ServerWebSocketStream) websocket_stream
  Return the websocket stream for the server.

## Instance Method Details

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

    105
    106
    107
    108
    109
    110
    111
    112
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_server.rb', line 105

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

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

Parameters:

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

Yields:

- the listen handler

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_server.rb', line 80

    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,::Vertx::HttpServer) : 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,::Vertx::HttpServer) : 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,::Vertx::HttpServer) : nil) }))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling listen(port,host)"
    end

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

Whether the metrics are enabled for this measured object

Returns:

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

Raises:

- (`ArgumentError`)

    30
    31
    32
    33
    34
    35
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_server.rb', line 30

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

### - (`::Vertx::HttpServer`) 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:

- (`::Vertx::HttpServer`) —
  a reference to this, so the API can be used fluently

Raises:

- (`ArgumentError`)

    49
    50
    51
    52
    53
    54
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_server.rb', line 49

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

### - (`::Vertx::HttpServerRequestStream`) 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 ReadStream#handler.

Returns:

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

Raises:

- (`ArgumentError`)

    39
    40
    41
    42
    43
    44
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_server.rb', line 39

    def request_stream
      if !block_given?
        return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:requestStream, []).call(),::Vertx::HttpServerRequestStream)
      end
      raise ArgumentError, "Invalid arguments when calling request_stream()"
    end

### - (`::Vertx::HttpServer`) 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:

- (`::Vertx::HttpServer`) —
  a reference to this, so the API can be used fluently

Raises:

- (`ArgumentError`)

    68
    69
    70
    71
    72
    73
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_server.rb', line 68

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

### - (`::Vertx::ServerWebSocketStream`) 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 ReadStream#handler.

Returns:

- (`::Vertx::ServerWebSocketStream`) —
  the websocket stream

Raises:

- (`ArgumentError`)

    58
    59
    60
    61
    62
    63
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/http_server.rb', line 58

    def websocket_stream
      if !block_given?
        return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:websocketStream, []).call(),::Vertx::ServerWebSocketStream)
      end
      raise ArgumentError, "Invalid arguments when calling websocket_stream()"
    end