Class: Vertx::Pump
- Inherits:
-
Object
- Object
- Vertx::Pump
- Defined in:
- /Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/pump.rb
Overview
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.
Class Method Summary (collapse)
-
+ (::Vertx::Pump) pump(rs = nil, ws = nil, writeQueueMaxSize = nil)
Create a new Pump with the given ReadStream and WriteStream and writeQueueMaxSize.
Instance Method Summary (collapse)
-
- (Fixnum) number_pumped
Return the total number of items pumped by this pump.
-
- (self) set_write_queue_max_size(maxSize = nil)
Set the write queue max size to maxSize.
-
- (self) start
Start the Pump.
-
- (self) stop
Stop the Pump.
Class Method Details
+ (::Vertx::Pump) pump(rs = nil, ws = nil, writeQueueMaxSize = nil)
Pump
with the given ReadStream
and WriteStream
and
writeQueueMaxSize
41 42 43 44 45 46 47 48 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/pump.rb', line 41 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::Pump.new(Java::IoVertxCoreStreams::Pump.java_method(:pump, [Java::IoVertxCoreStreams::ReadStream.java_class,Java::IoVertxCoreStreams::WriteStream.java_class]).call(rs.j_del,ws.j_del)) elsif rs.class.method_defined?(:j_del) && ws.class.method_defined?(:j_del) && writeQueueMaxSize.class == Fixnum && !block_given? return ::Vertx::Pump.new(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)) end raise ArgumentError, "Invalid arguments when calling pump(rs,ws,writeQueueMaxSize)" end |
Instance Method Details
- (Fixnum) number_pumped
79 80 81 82 83 84 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/pump.rb', line 79 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)
maxSize
52 53 54 55 56 57 58 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/pump.rb', line 52 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
61 62 63 64 65 66 67 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/pump.rb', line 61 def start if !block_given? @j_del.java_method(:start, []).call() return self end raise ArgumentError, "Invalid arguments when calling start()" end |
- (self) stop
70 71 72 73 74 75 76 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/pump.rb', line 70 def stop if !block_given? @j_del.java_method(:stop, []).call() return self end raise ArgumentError, "Invalid arguments when calling stop()" end |