@Override public BatchStream drainHandler(Handler<Void> handler) { writeStream.drainHandler(handler); return this; }
/** * Stop the Pump. The Pump can be started and stopped multiple times. */ @Override public PumpImpl stop() { writeStream.drainHandler(null); readStream.handler(null); 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); } }; }
@Override public WriteStream<Buffer> drainHandler(Handler<Void> handler) { stream.drainHandler(handler); return this; } }));
/** * 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 PumpImplEx<T> stop() { writeStream.drainHandler(null); readStream.handler(null); 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); } }; }
public PumpImplEx(ReadStream<T> readStream, WriteStream<T> writeStream) { this.readStream = readStream; this.writeStream = writeStream; drainHandler = v -> readStream.resume(); dataHandler = data -> { if (data instanceof Buffer) { if (((Buffer) data).length() == 0) { return; } } writeStream.write(data); incPumped(); if (writeStream.writeQueueFull()) { readStream.pause(); writeStream.drainHandler(drainHandler); } }; }
@Override public WriteStream<Buffer> drainHandler(Handler<Void> handler) { wrappedWriteStream.drainHandler(handler); return this; } }
@Override public WriteStream<Buffer> drainHandler(Handler<Void> handler) { stream.drainHandler(handler); return this; } }));
public void drainHandler(Handler<Void> drainHandler) { this.drainHandler = drainHandler; this.writeStream.drainHandler(drainHandler); }
/** * Set a drain handler on the stream. If the write queue is full, then the handler will be called when the write * queue is ready to accept buffers again. See {@link io.vertx.rxjava.core.streams.Pump} for an example of this being used. * <p/> * The stream implementation defines when the drain handler, for example it could be when the queue size has been * reduced to <code>maxSize / 2</code>. * @param handler the handler * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.streams.WriteStream<T> drainHandler(Handler<Void> handler) { delegate.drainHandler(handler); return this; }
/** * Set a drain handler on the stream. If the write queue is full, then the handler will be called when the write * queue is ready to accept buffers again. See {@link io.vertx.rxjava.core.streams.Pump} for an example of this being used. * <p/> * The stream implementation defines when the drain handler, for example it could be when the queue size has been * reduced to <code>maxSize / 2</code>. * @param handler the handler * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.streams.WriteStream<T> drainHandler(Handler<Void> handler) { delegate.drainHandler(handler); return this; }
/** * Stop the Pump. The Pump can be started and stopped multiple times. */ @Override public MqttPump stop() { writeStream.drainHandler(null); readStream.handler(null); return this; }
public void stop() { // stop writing to socket try { w.drainHandler(null); } catch (Throwable e) { logger.error(e.getMessage(), e); } } }
@Override public GzipWriteStream drainHandler(Handler<Void> handler) { if (delegate.writeQueueFull()) { delegate.drainHandler(handler); } else { drainHandler = handler; checkDrained(); } return this; }
public void sendMessageToClient(Buffer bytes) { try { w.write(bytes); if (w.writeQueueFull()) { r.pause(); w.drainHandler( done -> r.resume() ); } } catch(Throwable e) { logger.error(e.getMessage(), e); } }
protected void sendMessageToClient(Buffer bytes, WriteStream<Buffer> writer, ReadStream<Buffer> reader) { try { writer.write(bytes); if (writer.writeQueueFull()) { reader.pause(); writer.drainHandler( done -> reader.resume() ); } } catch(Throwable e) { logger.error(e.getMessage()); } } abstract protected void closeConnection();
@Override public void onToken(byte[] token, boolean timeout) throws Exception { try { Buffer b = Buffer.buffer(token); new MQTTDecoder().dec(b); writeStream.write(b); incPumped(); if (writeStream.writeQueueFull()) { readStream.pause(); writeStream.drainHandler(drainHandler); } } catch (Throwable e) { if(listener!=null) listener.onError(e); } }
@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(); }