Class List Method List File List

# Module: Vertx::WriteStream

Includes:
  StreamBase
Included in:
  AsyncFile, HttpClientRequest, HttpServerResponse, MessageProducer, NetSocket, WebSocketBase, WriteStreamImpl, VertxKafkaClient::KafkaProducer, VertxWeb::SockJSSocket
Defined in:
  /Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/write_stream.rb

## Instance Method Summary (collapse)

- - (self) drain_handler { ... }
  Set a drain handler on the stream.
- - (void) end(t = nil)
  Same as #end but writes some data to the stream before ending.
- - (self) exception_handler { ... }
  Set an exception handler on the write stream.
- - (self) set_write_queue_max_size(maxSize = nil)
  Set the maximum size of the write queue to maxSize.
- - (self) write(data = nil)
  Write some data to the stream.
- - (true, false) write_queue_full?
  This will return true if there are more bytes in the write queue than the value set using #set_write_queue_max_size.

## Instance Method Details

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

Set a drain handler on the stream. If the write queue is full, then the handler will be called when the write queue is ready to accept buffers again. See Pump for an example of this being used.

The stream implementation defines when the drain handler, for example it could be when the queue size has been reduced to `maxSize / 2`.

Yields:

- the handler

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    71
    72
    73
    74
    75
    76
    77
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/write_stream.rb', line 71

    def drain_handler
      if block_given?
        @j_del.java_method(:drainHandler, [Java::IoVertxCore::Handler.java_class]).call(Proc.new { yield })
        return self
      end
      raise ArgumentError, "Invalid arguments when calling drain_handler()"
    end

### - (`void`) end(t = nil)

This method returns an undefined value.

Same as #end but writes some data to the stream before ending.

Parameters:

- t (`Object`) (defaults to: `nil`)

Raises:

- (`ArgumentError`)

    32
    33
    34
    35
    36
    37
    38
    39
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/write_stream.rb', line 32

    def end(t=nil)
      if !block_given? && t == nil
        return @j_del.java_method(:end, []).call()
      elsif @j_arg_T.accept?(t) && !block_given?
        return @j_del.java_method(:end, [Java::java.lang.Object.java_class]).call(@j_arg_T.unwrap(t))
      end
      raise ArgumentError, "Invalid arguments when calling end(#{t})"
    end

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

Set an exception handler on the write stream.

Yields:

- the exception handler

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    10
    11
    12
    13
    14
    15
    16
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/write_stream.rb', line 10

    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`) set_write_queue_max_size(maxSize = nil)

Set the maximum size of the write queue to `maxSize`. You will still be able to write to the stream even if there is more than `maxSize` items in the write queue. This is used as an indicator by classes such as `Pump` to provide flow control.

The value is defined by the implementation of the stream, e.g in bytes for a NetSocket, the number of Message for a MessageProducer, etc...

Parameters:

- maxSize (`Fixnum`) (defaults to: `nil`) —
  the max size of the write stream

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    49
    50
    51
    52
    53
    54
    55
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/write_stream.rb', line 49

    def set_write_queue_max_size(maxSize=nil)
      if maxSize.class == Fixnum && !block_given?
        @j_del.java_method(:setWriteQueueMaxSize, [Java::int.java_class]).call(maxSize)
        return self
      end
      raise ArgumentError, "Invalid arguments when calling set_write_queue_max_size(#{maxSize})"
    end

### - (`self`) write(data = nil)

Write some data to the stream. The data is put on an internal write queue, and the write actually happens asynchronously. To avoid running out of memory by putting too much on the write queue, check the #write_queue_full method before writing. This is done automatically if using a Pump.

Parameters:

- data (`Object`) (defaults to: `nil`) —
  the data to write

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    22
    23
    24
    25
    26
    27
    28
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/write_stream.rb', line 22

    def write(data=nil)
      if @j_arg_T.accept?(data) && !block_given?
        @j_del.java_method(:write, [Java::java.lang.Object.java_class]).call(@j_arg_T.unwrap(data))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling write(#{data})"
    end

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

This will return `true` if there are more bytes in the write queue than the value set using #set_write_queue_max_size

Returns:

- (`true`, `false`) —
  true if write queue is full

Raises:

- (`ArgumentError`)

    58
    59
    60
    61
    62
    63
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/write_stream.rb', line 58

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