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) endOnComplete(end)
Set to true to call WriteStream#end when the source ReadStream completes, false otherwise.
-
- (self) endOnFailure(end)
Set to true to call WriteStream#end when the source ReadStream fails, false otherwise.
-
- (self) endOnSuccess(end)
Set to true to call WriteStream#end when the source ReadStream succeeds, false otherwise.
-
- (void) to(dst, completionHandler) { ... }
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.
80 81 82 83 84 85 86 87 88 89 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/pipe.rb', line 80 def close if !block_given? return @j_del.java_method(:close, []).call() end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling close()" end end |
- (self) endOnComplete(end)
true
to call WriteStream#end when the source ReadStream
completes, false
otherwise.
Calling this overwrites #end_on_failure and #end_on_success.
96 97 98 99 100 101 102 103 104 105 106 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/pipe.rb', line 96 def end_on_complete(*args) if (args[0].class == TrueClass || args[0].class == FalseClass) && !block_given? @j_del.java_method(:endOnComplete, [Java::boolean.java_class]).call(args[0]) return self end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling end_on_complete(#{args[0]})" end end |
- (self) endOnFailure(end)
111 112 113 114 115 116 117 118 119 120 121 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/pipe.rb', line 111 def end_on_failure(*args) if (args[0].class == TrueClass || args[0].class == FalseClass) && !block_given? @j_del.java_method(:endOnFailure, [Java::boolean.java_class]).call(args[0]) return self end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling end_on_failure(#{args[0]})" end end |
- (self) endOnSuccess(end)
41 42 43 44 45 46 47 48 49 50 51 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/pipe.rb', line 41 def end_on_success(*args) if (args[0].class == TrueClass || args[0].class == FalseClass) && !block_given? @j_del.java_method(:endOnSuccess, [Java::boolean.java_class]).call(args[0]) return self end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling end_on_success(#{args[0]})" end end |
- (void) to(dst, completionHandler) { ... }
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.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/pipe.rb', line 59 def to(*args) if args[0].class.method_defined?(:j_del) && true if (block_given?) return @j_del.java_method(:to, [Java::IoVertxCoreStreams::WriteStream.java_class,Java::IoVertxCore::Handler.java_class]).call(args[0].j_del,block_given? ? Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? nil : nil) } : promise) else promise = ::Vertx::Util::Utils.promise @j_del.java_method(:to, [Java::IoVertxCoreStreams::WriteStream.java_class,Java::IoVertxCore::Handler.java_class]).call(args[0].j_del,block_given? ? Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? nil : nil) } : promise) return ::Vertx::Util::Utils.safe_create(promise.future(),::Vertx::Future, nil) end end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling to(#{args[0]})" end end |