Class Pump
- java.lang.Object
-
- io.vertx.reactivex.core.streams.Pump
-
public class Pump extends Object
Pumps data from aReadStream
to aWriteStream
and performs flow control where necessary to prevent the write stream buffer from getting overfull.Instances of this class read items from a
ReadStream
and write them to aWriteStream
. If data can be read faster than it can be written this could result in the write queue of theWriteStream
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, theReadStream
is paused, and adrainHandler
is set on theWriteStream
.When the
WriteStream
has processed half of its backlog, thedrainHandler
will be called, which results in the pump resuming theReadStream
.This class can be used to pump from any
ReadStream
to anyWriteStream
, e.g. from anHttpServerRequest
to anAsyncFile
, or fromNetSocket
to aWebSocket
.Please see the documentation for more information.
NOTE: This class has been automatically generated from theoriginal
non RX-ified interface using Vert.x codegen.
-
-
Field Summary
Fields Modifier and Type Field Description static TypeArg<Pump>
__TYPE_ARG
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
Pump
getDelegate()
int
hashCode()
static Pump
newInstance(Pump arg)
int
numberPumped()
Return the total number of items pumped by this pump.static <T> Pump
pump(io.reactivex.Flowable<T> rs, WriteStream<T> ws)
Create a newPump
with the givenReadStream
andWriteStream
static <T> Pump
pump(io.reactivex.Flowable<T> rs, WriteStream<T> ws, int writeQueueMaxSize)
Create a newPump
with the givenReadStream
andWriteStream
andwriteQueueMaxSize
static <T> Pump
pump(ReadStream<T> rs, WriteStream<T> ws)
Create a newPump
with the givenReadStream
andWriteStream
static <T> Pump
pump(ReadStream<T> rs, WriteStream<T> ws, int writeQueueMaxSize)
Create a newPump
with the givenReadStream
andWriteStream
andwriteQueueMaxSize
Pump
setWriteQueueMaxSize(int maxSize)
Set the write queue max size tomaxSize
Pump
start()
Start the Pump.Pump
stop()
Stop the Pump.String
toString()
-
-
-
Method Detail
-
getDelegate
public Pump getDelegate()
-
pump
public static <T> Pump pump(ReadStream<T> rs, WriteStream<T> ws)
Create a newPump
with the givenReadStream
andWriteStream
- Parameters:
rs
- the read streamws
- the write stream- Returns:
- the pump
-
pump
public static <T> Pump pump(io.reactivex.Flowable<T> rs, WriteStream<T> ws)
Create a newPump
with the givenReadStream
andWriteStream
- Parameters:
rs
- the read streamws
- the write stream- Returns:
- the pump
-
pump
public static <T> Pump pump(ReadStream<T> rs, WriteStream<T> ws, int writeQueueMaxSize)
Create a newPump
with the givenReadStream
andWriteStream
andwriteQueueMaxSize
- Parameters:
rs
- the read streamws
- the write streamwriteQueueMaxSize
- the max size of the write queue- Returns:
- the pump
-
pump
public static <T> Pump pump(io.reactivex.Flowable<T> rs, WriteStream<T> ws, int writeQueueMaxSize)
Create a newPump
with the givenReadStream
andWriteStream
andwriteQueueMaxSize
- Parameters:
rs
- the read streamws
- the write streamwriteQueueMaxSize
- the max size of the write queue- Returns:
- the pump
-
setWriteQueueMaxSize
public Pump setWriteQueueMaxSize(int maxSize)
Set the write queue max size tomaxSize
- Parameters:
maxSize
- the max size- Returns:
- a reference to this, so the API can be used fluently
-
start
public Pump start()
Start the Pump. The Pump can be started and stopped multiple times.- Returns:
- a reference to this, so the API can be used fluently
-
stop
public Pump stop()
Stop the Pump. The Pump can be started and stopped multiple times.- Returns:
- a reference to this, so the API can be used fluently
-
numberPumped
public int numberPumped()
Return the total number of items pumped by this pump.- Returns:
-
-