Module: Vertx::WriteStream

Included in:
HttpClientRequest, WebSocket
Defined in:
lib/vertx/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

#_to_write_streamObject



69
70
71
# File 'lib/vertx/streams.rb', line 69

def _to_write_stream
  @j_del
end

#drain_handler(&hndlr) ⇒ Object

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 'lib/vertx/streams.rb', line 56

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

#exception_handler(&hndlr) ⇒ Object

Set an exception handler on the stream.

Parameters:

  • hndlr. (Block)

    The exception handler



63
64
65
66
# File 'lib/vertx/streams.rb', line 63

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

#write(buff) ⇒ Object

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 'lib/vertx/streams.rb', line 28

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

#write_queue_full?Boolean

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 'lib/vertx/streams.rb', line 49

def write_queue_full?
  @j_del.writeQueueFull
end

#write_queue_max_size(size) ⇒ Object

For a fluent API



42
43
44
45
# File 'lib/vertx/streams.rb', line 42

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

#write_queue_max_size=(size) ⇒ Object

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 'lib/vertx/streams.rb', line 37

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