Top Description Fields Constructors Methods
io.vertx.core.streams.impl

public Class PumpImpl<T>

extends Object
implements Pump
Class Inheritance
All Implemented Interfaces
io.vertx.core.streams.Pump
Imports
io.vertx.core.Handler, io.vertx.core.streams.Pump, .ReadStream, .WriteStream, java.util.Objects

References Deprecated

Pump is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Pumps data from a io.vertx.core.streams.ReadStream to a io.vertx.core.streams.WriteStream and performs flow control where necessary to prevent the write stream buffer from getting overfull.

Instances of this class read bytes from a io.vertx.core.streams.ReadStream and write them to a io.vertx.core.streams.WriteStream. If data can be read faster than it can be written this could result in the write queue of the io.vertx.core.streams.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 io.vertx.core.streams.WriteStream is full, and if so, the io.vertx.core.streams.ReadStream is paused, and a drainHandler is set on the io.vertx.core.streams.WriteStream. When the io.vertx.core.streams.WriteStream has processed half of its backlog, the drainHandler will be called, which results in the pump resuming the io.vertx.core.streams.ReadStream.

This class can be used to pump from any io.vertx.core.streams.ReadStream to any io.vertx.core.streams.WriteStream, e.g. from an io.vertx.core.http.HttpServerRequest to an io.vertx.core.file.AsyncFile, or from io.vertx.core.net.NetSocket to a io.vertx.core.http.WebSocket.

Instances of this class are not thread-safe.

Author
Tim Fox

Field Summary

Modifier and TypeField and Description
private final Handler<T>
private final Handler<Void>
private int
private final ReadStream<T>
private final WriteStream<T>

Constructor Summary

AccessConstructor and Description
public
PumpImpl(ReadStream<T> rs, WriteStream<T> ws, int maxWriteQueueSize)

Create a new Pump with the given ReadStream and WriteStream.

public

Method Summary

Modifier and TypeMethod and Description
private synchronized void
public synchronized int
numberPumped()

Implements io.vertx.core.streams.Pump.numberPumped.

Return the total number of elements pumped by this pump.

public PumpImpl<T>
setWriteQueueMaxSize(int
the max size
maxSize
)

Implements io.vertx.core.streams.Pump.setWriteQueueMaxSize.

References Deprecated PumpImpl is deprecated or references (maybe indirectly) at least one deprecated element.

Set the write queue max size to maxSize

public PumpImpl<T>
start()

Implements io.vertx.core.streams.Pump.start.

References Deprecated PumpImpl is deprecated or references (maybe indirectly) at least one deprecated element.

Start the Pump.

public PumpImpl<T>
stop()

Implements io.vertx.core.streams.Pump.stop.

References Deprecated PumpImpl is deprecated or references (maybe indirectly) at least one deprecated element.

Stop the Pump.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dataHandlerback to summary
private final Handler<T> dataHandler
drainHandlerback to summary
private final Handler<Void> drainHandler
pumpedback to summary
private int pumped
readStreamback to summary
private final ReadStream<T> readStream
writeStreamback to summary
private final WriteStream<T> writeStream

Constructor Detail

PumpImplback to summary
public PumpImpl(ReadStream<T> rs, WriteStream<T> ws, int maxWriteQueueSize)

Create a new Pump with the given ReadStream and WriteStream. Set the write queue max size of the write stream to maxWriteQueueSize

PumpImplback to summary
public PumpImpl(ReadStream<T> rs, WriteStream<T> ws)

Method Detail

incPumpedback to summary
private synchronized void incPumped()
numberPumpedback to summary
public synchronized int numberPumped()

Implements io.vertx.core.streams.Pump.numberPumped.

Return the total number of elements pumped by this pump.

Annotations
@Override
setWriteQueueMaxSizeback to summary
public PumpImpl<T> setWriteQueueMaxSize(int maxSize)

Implements io.vertx.core.streams.Pump.setWriteQueueMaxSize.

References Deprecated

PumpImpl is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Set the write queue max size to maxSize

Parameters
maxSize:int

Doc from io.vertx.core.streams.Pump.setWriteQueueMaxSize.

the max size

Returns:PumpImpl<T>

Doc from io.vertx.core.streams.Pump.setWriteQueueMaxSize.

a reference to this, so the API can be used fluently

Annotations
@Override
startback to summary
public PumpImpl<T> start()

Implements io.vertx.core.streams.Pump.start.

References Deprecated

PumpImpl is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Start the Pump. The Pump can be started and stopped multiple times.

Returns:PumpImpl<T>

Doc from io.vertx.core.streams.Pump.start.

a reference to this, so the API can be used fluently

Annotations
@Override
stopback to summary
public PumpImpl<T> stop()

Implements io.vertx.core.streams.Pump.stop.

References Deprecated

PumpImpl is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Stop the Pump. The Pump can be started and stopped multiple times.

Returns:PumpImpl<T>

Doc from io.vertx.core.streams.Pump.stop.

a reference to this, so the API can be used fluently

Annotations
@Override