PumpImpl(ReadStream<T> rs, WriteStream<T> ws) { this.readStream = rs; this.writeStream = ws; drainHandler = v-> readStream.resume(); dataHandler = data -> { writeStream.write(data); incPumped(); if (writeStream.writeQueueFull()) { readStream.pause(); writeStream.drainHandler(drainHandler); } }; }
if (ar.succeeded()) { WriteStream<Buffer> ws = ar.result(); ws.exceptionHandler(t -> fail(t.getMessage())); ws.write(buff); ar.result().close(ar2 -> { if (ar2.failed()) {
public void send() { if (countDown > 0) { try { stream.write(data); } catch (Exception e) { if (error == null) { error = e; return; } } context.runOnContext(v -> send()); } }
out.end(); fileClosed.set(true); progress.setCurrent(bytesWritten.get()); }; file.exceptionHandler(exceptionHandler); out.exceptionHandler(exceptionHandler); out.write(data.getDelegate()); progress.setCurrent(bytesWritten.getAndAdd(data.length())); if (out.writeQueueFull()) { file.pause(); out.drainHandler(v -> file.resume());
@Override public void end() { writeStream.end(); }
@Override public BatchStream drainHandler(Handler<Void> handler) { writeStream.drainHandler(handler); return this; }
@Override public boolean writeQueueFull() { return writeStream.writeQueueFull(); }
writeStream.write(mapping.apply(r)); synchronized (this) { outstanding--; if (!writeStream.writeQueueFull()) { requestMore();
@Override public GzipWriteStream drainHandler(Handler<Void> handler) { if (delegate.writeQueueFull()) { delegate.drainHandler(handler); } else { drainHandler = handler; checkDrained(); } return this; }
/** * Create a new {@code Pump} with the given {@code ReadStream} and {@code WriteStream}. Set the write queue max size * of the write stream to {@code maxWriteQueueSize} */ PumpImpl(ReadStream<T> rs, WriteStream<T> ws, int maxWriteQueueSize) { this(rs, ws); this.writeStream.setWriteQueueMaxSize(maxWriteQueueSize); }
public BatchStream(ReadStream<Buffer> rs, WriteStream<Buffer> ws) { Objects.requireNonNull(rs, "ReadStream"); Objects.requireNonNull(ws, "WriteStream"); recordParser = RecordParser.newFixed(4, rs); writeStream = ws; // Propagate exceptions to the current stream recordParser.exceptionHandler(throwable -> { if (exceptionHandler != null) { exceptionHandler.handle(throwable); } }); writeStream.exceptionHandler(throwable -> { if (exceptionHandler != null) { exceptionHandler.handle(throwable); } }); }
@Override public void onSubscribe(Subscription subscription) { Objects.requireNonNull(subscription, "subscription"); if (!setSubscription(subscription)) { subscription.cancel(); SubscriptionHelper.reportSubscriptionSet(); return; } writeStream.exceptionHandler(t -> { if (!setDone()) { RxJavaPlugins.onError(t); return; } getSubscription().cancel(); Consumer<? super Throwable> c; synchronized (this) { c = this.writeStreamExceptionHandler; } if (c != null) { try { c.accept(t); } catch (Exception e) { RxJavaPlugins.onError(e); } } }); writeStream.drainHandler(v -> requestMore()); requestMore(); }
@Override public BatchStream write(Batch batch) { if (batch == null) { if (exceptionHandler != null) { exceptionHandler.handle(new NullPointerException()); } } else { Buffer protocol = Buffer.buffer(); protocol.appendInt(0); protocol.appendByte((byte) batch.getType()); protocol.appendBuffer(batch.getRaw()); protocol.setInt(0, protocol.length() - 4); writeStream.write(protocol); } return this; }
@Override public void end() { if (stream instanceof AsyncFile) { AsyncFile file = (AsyncFile) stream; file.close(ar -> { if (ar.succeeded()) { fut.tryComplete(); } else { fut.tryFail(ar.cause()); } }); } else { stream.end(); fut.tryComplete(); } }
/** * Stop the Pump. The Pump can be started and stopped multiple times. */ @Override public PumpImpl stop() { writeStream.drainHandler(null); readStream.handler(null); return this; }
@Override public boolean writeQueueFull() { return stream.writeQueueFull(); }
/** * Set the write queue max size to {@code maxSize} */ @Override public PumpImpl setWriteQueueMaxSize(int maxSize) { writeStream.setWriteQueueMaxSize(maxSize); return this; }
@Override public WriteStream<Buffer> exceptionHandler(Handler<Throwable> handler) { stream.exceptionHandler(handler); return this; }
PumpImpl(ReadStream<T> rs, WriteStream<T> ws) { this.readStream = rs; this.writeStream = ws; drainHandler = v-> readStream.resume(); dataHandler = data -> { writeStream.write(data); incPumped(); if (writeStream.writeQueueFull()) { readStream.pause(); writeStream.drainHandler(drainHandler); } }; }