Class: Vertx::Pump

Inherits:
Object
  • Object
show all
Defined in:
/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/pump.rb

Overview

Pumps data from a ReadStream to a WriteStream and performs flow control where necessary to prevent the write stream buffer from getting overfull.

Instances of this class read items from a ReadStream and write them to a WriteStream. If data can be read faster than it can be written this could result in the write queue of the WriteStream growing without bound, eventually causing it to exhaust all available RAM.

To prevent this, after each write, instances of this class check whether the write queue of the WriteStream is full, and if so, the ReadStream is paused, and a drainHandler is set on the WriteStream.

When the WriteStream has processed half of its backlog, the drainHandler will be called, which results in the pump resuming the ReadStream.

This class can be used to pump from any ReadStream to any WriteStream, e.g. from an HttpServerRequest to an AsyncFile, or from NetSocket to a WebSocket.

Please see the documentation for more information.

Constant Summary

@@j_api_type =
Object.new

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Boolean) accept?(obj)

Returns:

  • (Boolean)


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

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

+ (Object) j_api_type



45
46
47
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/pump.rb', line 45

def self.j_api_type
  @@j_api_type
end

+ (Object) j_class



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

def self.j_class
  Java::IoVertxCoreStreams::Pump.java_class
end

+ (::Vertx::Pump) pump(rs = nil, ws = nil, writeQueueMaxSize = nil)

Create a new Pump with the given ReadStream and WriteStream and writeQueueMaxSize

Parameters:

  • rs (::Vertx::ReadStream) (defaults to: nil)
    the read stream
  • ws (::Vertx::WriteStream) (defaults to: nil)
    the write stream
  • writeQueueMaxSize (Fixnum) (defaults to: nil)
    the max size of the write queue

Returns:

Raises:

  • (ArgumentError)


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

def self.pump(rs=nil,ws=nil,writeQueueMaxSize=nil)
  if rs.class.method_defined?(:j_del) && ws.class.method_defined?(:j_del) && !block_given? && writeQueueMaxSize == nil
    return ::Vertx::Util::Utils.safe_create(Java::IoVertxCoreStreams::Pump.java_method(:pump, [Java::IoVertxCoreStreams::ReadStream.java_class,Java::IoVertxCoreStreams::WriteStream.java_class]).call(rs.j_del,ws.j_del),::Vertx::Pump)
  elsif rs.class.method_defined?(:j_del) && ws.class.method_defined?(:j_del) && writeQueueMaxSize.class == Fixnum && !block_given?
    return ::Vertx::Util::Utils.safe_create(Java::IoVertxCoreStreams::Pump.java_method(:pump, [Java::IoVertxCoreStreams::ReadStream.java_class,Java::IoVertxCoreStreams::WriteStream.java_class,Java::int.java_class]).call(rs.j_del,ws.j_del,writeQueueMaxSize),::Vertx::Pump)
  end
  raise ArgumentError, "Invalid arguments when calling pump(#{rs},#{ws},#{writeQueueMaxSize})"
end

+ (Object) unwrap(obj)



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

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

+ (Object) wrap(obj)



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

def @@j_api_type.wrap(obj)
  Pump.new(obj)
end

Instance Method Details

- (Fixnum) number_pumped

Return the total number of items pumped by this pump.

Returns:

  • (Fixnum)

Raises:

  • (ArgumentError)


95
96
97
98
99
100
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/pump.rb', line 95

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

- (self) set_write_queue_max_size(maxSize = nil)

Set the write queue max size to maxSize

Parameters:

  • maxSize (Fixnum) (defaults to: nil)
    the max size

Returns:

  • (self)

Raises:

  • (ArgumentError)


68
69
70
71
72
73
74
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/pump.rb', line 68

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) start

Start the Pump. The Pump can be started and stopped multiple times.

Returns:

  • (self)

Raises:

  • (ArgumentError)


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

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

- (self) stop

Stop the Pump. The Pump can be started and stopped multiple times.

Returns:

  • (self)

Raises:

  • (ArgumentError)


86
87
88
89
90
91
92
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/pump.rb', line 86

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