io.vertx.rxjava3.core.streams.Pump Maven / Gradle / Ivy
/*
* Copyright 2014 Red Hat, Inc.
*
* Red Hat licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.vertx.rxjava3.core.streams;
import io.vertx.rxjava3.RxHelper;
import io.vertx.rxjava3.ObservableHelper;
import io.vertx.rxjava3.FlowableHelper;
import io.vertx.rxjava3.impl.AsyncResultMaybe;
import io.vertx.rxjava3.impl.AsyncResultSingle;
import io.vertx.rxjava3.impl.AsyncResultCompletable;
import io.vertx.rxjava3.WriteStreamObserver;
import io.vertx.rxjava3.WriteStreamSubscriber;
import java.util.Map;
import java.util.Set;
import java.util.List;
import java.util.Iterator;
import java.util.function.Function;
import java.util.stream.Collectors;
import io.vertx.core.Handler;
import io.vertx.core.AsyncResult;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;
import io.vertx.lang.rx.RxGen;
import io.vertx.lang.rx.TypeArg;
import io.vertx.lang.rx.MappingIterator;
/**
* Pumps data from a {@link io.vertx.rxjava3.core.streams.ReadStream} to a {@link io.vertx.rxjava3.core.streams.WriteStream} and performs flow control where necessary to
* prevent the write stream buffer from getting overfull.
*
* Instances of this class read items from a {@link io.vertx.rxjava3.core.streams.ReadStream} and write them to a {@link io.vertx.rxjava3.core.streams.WriteStream}. If data
* can be read faster than it can be written this could result in the write queue of the {@link io.vertx.rxjava3.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 {@link io.vertx.rxjava3.core.streams.WriteStream} is full, and if so, the {@link io.vertx.rxjava3.core.streams.ReadStream} is paused, and a drainHandler
is set on the
* {@link io.vertx.rxjava3.core.streams.WriteStream}.
*
* When the {@link io.vertx.rxjava3.core.streams.WriteStream} has processed half of its backlog, the drainHandler
will be
* called, which results in the pump resuming the {@link io.vertx.rxjava3.core.streams.ReadStream}.
*
* This class can be used to pump from any {@link io.vertx.rxjava3.core.streams.ReadStream} to any {@link io.vertx.rxjava3.core.streams.WriteStream},
* e.g. from an {@link io.vertx.rxjava3.core.http.HttpServerRequest} to an {@link io.vertx.rxjava3.core.file.AsyncFile},
* or from {@link io.vertx.rxjava3.core.net.NetSocket} to a {@link io.vertx.rxjava3.core.http.WebSocket}.
*
* Please see the documentation for more information.
*
*
* NOTE: This class has been automatically generated from the {@link io.vertx.core.streams.Pump original} non RX-ified interface using Vert.x codegen.
*/
@RxGen(io.vertx.core.streams.Pump.class)
public class Pump {
@Override
public String toString() {
return delegate.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Pump that = (Pump) o;
return delegate.equals(that.delegate);
}
@Override
public int hashCode() {
return delegate.hashCode();
}
public static final TypeArg __TYPE_ARG = new TypeArg<>( obj -> new Pump((io.vertx.core.streams.Pump) obj),
Pump::getDelegate
);
private final io.vertx.core.streams.Pump delegate;
public Pump(io.vertx.core.streams.Pump delegate) {
this.delegate = delegate;
}
public Pump(Object delegate) {
this.delegate = (io.vertx.core.streams.Pump)delegate;
}
public io.vertx.core.streams.Pump getDelegate() {
return delegate;
}
/**
* Create a new Pump
with the given ReadStream
and WriteStream
* @param rs the read stream
* @param ws the write stream
* @return the pump
*/
@Deprecated()
public static io.vertx.rxjava3.core.streams.Pump pump(io.reactivex.rxjava3.core.Flowable rs, io.vertx.rxjava3.core.streams.WriteStream ws) {
io.vertx.rxjava3.core.streams.Pump ret = io.vertx.rxjava3.core.streams.Pump.newInstance((io.vertx.core.streams.Pump)io.vertx.core.streams.Pump.pump(io.vertx.rxjava3.impl.ReadStreamSubscriber.asReadStream(rs, obj -> obj).resume(), ws.getDelegate()));
return ret;
}
/**
* Create a new Pump
with the given ReadStream
and WriteStream
and
* writeQueueMaxSize
* @param rs the read stream
* @param ws the write stream
* @param writeQueueMaxSize the max size of the write queue
* @return the pump
*/
@Deprecated()
public static io.vertx.rxjava3.core.streams.Pump pump(io.reactivex.rxjava3.core.Flowable rs, io.vertx.rxjava3.core.streams.WriteStream ws, int writeQueueMaxSize) {
io.vertx.rxjava3.core.streams.Pump ret = io.vertx.rxjava3.core.streams.Pump.newInstance((io.vertx.core.streams.Pump)io.vertx.core.streams.Pump.pump(io.vertx.rxjava3.impl.ReadStreamSubscriber.asReadStream(rs, obj -> obj).resume(), ws.getDelegate(), writeQueueMaxSize));
return ret;
}
/**
* Set the write queue max size to maxSize
* @param maxSize the max size
* @return a reference to this, so the API can be used fluently
*/
@Deprecated()
public io.vertx.rxjava3.core.streams.Pump setWriteQueueMaxSize(int maxSize) {
delegate.setWriteQueueMaxSize(maxSize);
return this;
}
/**
* Start the Pump. The Pump can be started and stopped multiple times.
* @return a reference to this, so the API can be used fluently
*/
@Deprecated()
public io.vertx.rxjava3.core.streams.Pump start() {
delegate.start();
return this;
}
/**
* Stop the Pump. The Pump can be started and stopped multiple times.
* @return a reference to this, so the API can be used fluently
*/
@Deprecated()
public io.vertx.rxjava3.core.streams.Pump stop() {
delegate.stop();
return this;
}
/**
* Return the total number of items pumped by this pump.
* @return
*/
@Deprecated()
public int numberPumped() {
int ret = delegate.numberPumped();
return ret;
}
public static Pump newInstance(io.vertx.core.streams.Pump arg) {
return arg != null ? new Pump(arg) : null;
}
}