Module: Vertx::WriteStream

Included in:
AsyncFile, HttpClientRequest, HttpServerResponse, NetSocket, SockJSSocket, WebSocket
Defined in:
src/main/api_shim/core/streams.rb

Overview

A mixin module which represents a stream of data that can be written to. Any class that mixes in this module can be used by a Pump to pump data from a ReadStream to it.

Author:

Instance Method Summary (collapse)

Instance Method Details

- (Object) drain_handler(&hndlr)

Set a drain handler on the stream. If the write queue is full, then the handler will be called when the write queue has been reduced to maxSize / 2. See Pump for an example of this being used.

Parameters:

  • hndlr. (Block)
    The drain handler


56
57
58
59
# File 'src/main/api_shim/core/streams.rb', line 56

def drain_handler(&hndlr)
  @j_del.drainHandler(hndlr)
  self
end

- (Object) exception_handler(&hndlr)

Set an exception handler on the stream.

Parameters:

  • hndlr. (Block)
    The exception handler


63
64
65
66
# File 'src/main/api_shim/core/streams.rb', line 63

def exception_handler(&hndlr)
  @j_del.exceptionHandler(hndlr)
  self
end

- (Object) write(buff)

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:

  • . (Buffer)
    The buffer to write.


28
29
30
31
# File 'src/main/api_shim/core/streams.rb', line 28

def write(buff)
  @j_del.write(buff._to_java_buffer)
  self
end

- (Boolean) write_queue_full?

Is the write queue full?

Returns:

  • (Boolean)
    true if there are more bytes in the write queue than the max write queue size.


49
50
51
# File 'src/main/api_shim/core/streams.rb', line 49

def write_queue_full?
  @j_del.writeQueueFull
end

- (Object) write_queue_max_size(size)

For a fluent API


42
43
44
45
# File 'src/main/api_shim/core/streams.rb', line 42

def write_queue_max_size(size)
  @j_del.setWriteQueueMaxSize(size)
  self
end

- (Object) write_queue_max_size=(size)

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

Parameters:

  • size. (FixNum)
    The maximum size, in bytes.


37
38
39
# File 'src/main/api_shim/core/streams.rb', line 37

def write_queue_max_size=(size)
  @j_del.setWriteQueueMaxSize(size)
end