Class: Vertx::Pipe
- Inherits:
-
Object
- Object
- Vertx::Pipe
- Defined in:
- /Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/pipe.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 pipe 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.
Instance Method Summary (collapse)
-
- (void) close
Close the pipe.
-
- (self) end_on_complete(_end = nil)
Set to true to call WriteStream#end when the source ReadStream completes, false otherwise.
-
- (self) end_on_failure(_end = nil)
Set to true to call WriteStream#end when the source ReadStream fails, false otherwise.
-
- (self) end_on_success(_end = nil)
Set to true to call WriteStream#end when the source ReadStream succeeds, false otherwise.
-
- (void) to(dst = nil) { ... }
Start to pipe the elements to the destination WriteStream.
Instance Method Details
- (void) close
This method returns an undefined value.
Close the pipe.The streams handlers will be unset and the read stream resumed unless it is already ended.
85 86 87 88 89 90 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/pipe.rb', line 85 def close if !block_given? return @j_del.java_method(:close, []).call() end raise ArgumentError, "Invalid arguments when calling close()" end |
- (self) end_on_complete(_end = nil)
true
to call WriteStream#end when the source ReadStream
completes, false
otherwise.
Calling this overwrites #end_on_failure and #end_on_success.
60 61 62 63 64 65 66 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/pipe.rb', line 60 def end_on_complete(_end=nil) if (_end.class == TrueClass || _end.class == FalseClass) && !block_given? @j_del.java_method(:endOnComplete, [Java::boolean.java_class]).call(_end) return self end raise ArgumentError, "Invalid arguments when calling end_on_complete(#{_end})" end |
- (self) end_on_failure(_end = nil)
38 39 40 41 42 43 44 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/pipe.rb', line 38 def end_on_failure(_end=nil) if (_end.class == TrueClass || _end.class == FalseClass) && !block_given? @j_del.java_method(:endOnFailure, [Java::boolean.java_class]).call(_end) return self end raise ArgumentError, "Invalid arguments when calling end_on_failure(#{_end})" end |
- (self) end_on_success(_end = nil)
48 49 50 51 52 53 54 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/pipe.rb', line 48 def end_on_success(_end=nil) if (_end.class == TrueClass || _end.class == FalseClass) && !block_given? @j_del.java_method(:endOnSuccess, [Java::boolean.java_class]).call(_end) return self end raise ArgumentError, "Invalid arguments when calling end_on_success(#{_end})" end |
- (void) to(dst = nil) { ... }
This method returns an undefined value.
Start to pipe the elements to the destinationWriteStream
.
When the operation fails with a write error, the source stream is resumed.
73 74 75 76 77 78 79 80 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/pipe.rb', line 73 def to(dst=nil) if dst.class.method_defined?(:j_del) && !block_given? return @j_del.java_method(:to, [Java::IoVertxCoreStreams::WriteStream.java_class]).call(dst.j_del) elsif dst.class.method_defined?(:j_del) && block_given? return @j_del.java_method(:to, [Java::IoVertxCoreStreams::WriteStream.java_class,Java::IoVertxCore::Handler.java_class]).call(dst.j_del,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil) })) end raise ArgumentError, "Invalid arguments when calling to(#{dst})" end |