io.vertx.rxjava.core.http.HttpConnection 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.rxjava.core.http;
import rx.Observable;
import rx.Single;
import io.vertx.rx.java.RxHelper;
import io.vertx.rx.java.WriteStreamSubscriber;
import io.vertx.rx.java.SingleOnSubscribeAdapter;
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;
/**
* Represents an HTTP connection.
*
* HTTP/1.x connection provides an limited implementation, the following methods are implemented:
*
* - {@link io.vertx.rxjava.core.http.HttpConnection#close}
* - {@link io.vertx.rxjava.core.http.HttpConnection#closeHandler}
* - {@link io.vertx.rxjava.core.http.HttpConnection#exceptionHandler}
*
*
*
* NOTE: This class has been automatically generated from the {@link io.vertx.core.http.HttpConnection original} non RX-ified interface using Vert.x codegen.
*/
@RxGen(io.vertx.core.http.HttpConnection.class)
public class HttpConnection {
@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;
HttpConnection that = (HttpConnection) o;
return delegate.equals(that.delegate);
}
@Override
public int hashCode() {
return delegate.hashCode();
}
public static final TypeArg __TYPE_ARG = new TypeArg<>( obj -> new HttpConnection((io.vertx.core.http.HttpConnection) obj),
HttpConnection::getDelegate
);
private final io.vertx.core.http.HttpConnection delegate;
public HttpConnection(io.vertx.core.http.HttpConnection delegate) {
this.delegate = delegate;
}
public HttpConnection(Object delegate) {
this.delegate = (io.vertx.core.http.HttpConnection)delegate;
}
public io.vertx.core.http.HttpConnection getDelegate() {
return delegate;
}
/**
* @return the current connection window size or -1
for HTTP/1.x
*/
public int getWindowSize() {
int ret = delegate.getWindowSize();
return ret;
}
/**
* Update the current connection wide window size to a new size.
*
* Increasing this value, gives better performance when several data streams are multiplexed
*
* This is not implemented for HTTP/1.x.
* @param windowSize the new window size
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava.core.http.HttpConnection setWindowSize(int windowSize) {
delegate.setWindowSize(windowSize);
return this;
}
/**
* Like {@link io.vertx.rxjava.core.http.HttpConnection#goAway} with a last stream id -1
which means to disallow any new stream creation.
* @param errorCode
* @return
*/
public io.vertx.rxjava.core.http.HttpConnection goAway(long errorCode) {
delegate.goAway(errorCode);
return this;
}
/**
* Like {@link io.vertx.rxjava.core.http.HttpConnection#goAway} with no buffer.
* @param errorCode
* @param lastStreamId
* @return
*/
public io.vertx.rxjava.core.http.HttpConnection goAway(long errorCode, int lastStreamId) {
delegate.goAway(errorCode, lastStreamId);
return this;
}
/**
* Send a go away frame to the remote endpoint of the connection.
*
*
* - a frame is sent to the to the remote endpoint with the
errorCode
and debugData
* - any stream created after the stream identified by
lastStreamId
will be closed
* - for an is different than
0
when all the remaining streams are closed this connection will be closed automatically
*
*
* This is not implemented for HTTP/1.x.
* @param errorCode the error code
* @param lastStreamId the last stream id
* @param debugData additional debug data sent to the remote endpoint
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava.core.http.HttpConnection goAway(long errorCode, int lastStreamId, io.vertx.rxjava.core.buffer.Buffer debugData) {
delegate.goAway(errorCode, lastStreamId, debugData.getDelegate());
return this;
}
/**
* Set an handler called when a frame is received.
*
* This is not implemented for HTTP/1.x.
* @param handler the handler
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava.core.http.HttpConnection goAwayHandler(Handler handler) {
delegate.goAwayHandler(handler);
return this;
}
/**
* Set an handler called when a frame has been sent or received and all connections are closed.
*
* This is not implemented for HTTP/1.x.
* @param handler the handler
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava.core.http.HttpConnection shutdownHandler(Handler handler) {
delegate.shutdownHandler(handler);
return this;
}
/**
* Initiate a graceful connection shutdown, the connection is taken out of service and closed when all current requests
* are processed, otherwise after 30 seconds the connection will be closed. Client connection are immediately removed
* from the pool.
*
*
* - HTTP/2 connections will send a go away frame immediately to signal the other side the connection will close
* - HTTP/1.x client connection supports this feature
* - HTTP/1.x server connections do not support this feature
*
* @param handler the handler called when shutdown has completed
*/
public void shutdown(Handler> handler) {
delegate.shutdown(handler);
}
/**
* Initiate a graceful connection shutdown, the connection is taken out of service and closed when all current requests
* are processed, otherwise after 30 seconds the connection will be closed. Client connection are immediately removed
* from the pool.
*
*
* - HTTP/2 connections will send a go away frame immediately to signal the other side the connection will close
* - HTTP/1.x client connection supports this feature
* - HTTP/1.x server connections do not support this feature
*
*/
public void shutdown() {
shutdown(ar -> { });
}
/**
* Initiate a graceful connection shutdown, the connection is taken out of service and closed when all current requests
* are processed, otherwise after 30 seconds the connection will be closed. Client connection are immediately removed
* from the pool.
*
*
* - HTTP/2 connections will send a go away frame immediately to signal the other side the connection will close
* - HTTP/1.x client connection supports this feature
* - HTTP/1.x server connections do not support this feature
*
* @return
*/
public Single rxShutdown() {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
shutdown(fut);
}));
}
/**
* Like {@link io.vertx.rxjava.core.http.HttpConnection#shutdown} but with a specific timeout
in milliseconds.
* @param timeout
* @param handler
*/
public void shutdown(long timeout, Handler> handler) {
delegate.shutdown(timeout, handler);
}
/**
* Like {@link io.vertx.rxjava.core.http.HttpConnection#shutdown} but with a specific timeout
in milliseconds.
* @param timeout
*/
public void shutdown(long timeout) {
shutdown(timeout, ar -> { });
}
/**
* Like {@link io.vertx.rxjava.core.http.HttpConnection#shutdown} but with a specific timeout
in milliseconds.
* @param timeout
* @return
*/
public Single rxShutdown(long timeout) {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
shutdown(timeout, fut);
}));
}
/**
* Set a close handler. The handler will get notified when the connection is closed.
* @param handler the handler to be notified
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava.core.http.HttpConnection closeHandler(Handler handler) {
delegate.closeHandler(handler);
return this;
}
/**
* Close the connection and all the currently active streams.
*
* An HTTP/2 connection will send a frame before.
* @return a future completed with the result
*/
public io.vertx.rxjava.core.Future close() {
io.vertx.rxjava.core.Future ret = io.vertx.rxjava.core.Future.newInstance((io.vertx.core.Future)delegate.close(), TypeArg.unknown());
return ret;
}
/**
* @return the latest server settings acknowledged by the remote endpoint - this is not implemented for HTTP/1.x
*/
public io.vertx.core.http.Http2Settings settings() {
io.vertx.core.http.Http2Settings ret = delegate.settings();
return ret;
}
/**
* Send to the remote endpoint an update of this endpoint settings
*
* The completionHandler
will be notified when the remote endpoint has acknowledged the settings.
*
* This is not implemented for HTTP/1.x.
* @param settings the new settings
* @param completionHandler the handler notified when the settings have been acknowledged by the remote endpoint
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava.core.http.HttpConnection updateSettings(io.vertx.core.http.Http2Settings settings, Handler> completionHandler) {
delegate.updateSettings(settings, completionHandler);
return this;
}
/**
* Send to the remote endpoint an update of this endpoint settings
*
* The completionHandler
will be notified when the remote endpoint has acknowledged the settings.
*
* This is not implemented for HTTP/1.x.
* @param settings the new settings
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava.core.http.HttpConnection updateSettings(io.vertx.core.http.Http2Settings settings) {
return
updateSettings(settings, ar -> { });
}
/**
* Send to the remote endpoint an update of this endpoint settings
*
* The completionHandler
will be notified when the remote endpoint has acknowledged the settings.
*
* This is not implemented for HTTP/1.x.
* @param settings the new settings
* @return a reference to this, so the API can be used fluently
*/
public Single rxUpdateSettings(io.vertx.core.http.Http2Settings settings) {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
updateSettings(settings, fut);
}));
}
/**
* @return the current remote endpoint settings for this connection - this is not implemented for HTTP/1.x
*/
public io.vertx.core.http.Http2Settings remoteSettings() {
io.vertx.core.http.Http2Settings ret = delegate.remoteSettings();
return ret;
}
/**
* Set an handler that is called when remote endpoint {@link io.vertx.core.http.Http2Settings} are updated.
*
* This is not implemented for HTTP/1.x.
* @param handler the handler for remote endpoint settings
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava.core.http.HttpConnection remoteSettingsHandler(Handler handler) {
delegate.remoteSettingsHandler(handler);
return this;
}
/**
* Send a frame to the remote endpoint.
*
* This is not implemented for HTTP/1.x.
* @param data the 8 bytes data of the frame
* @param pongHandler an async result handler notified with pong reply or the failure
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava.core.http.HttpConnection ping(io.vertx.rxjava.core.buffer.Buffer data, Handler> pongHandler) {
delegate.ping(data.getDelegate(), new Handler>() {
public void handle(AsyncResult ar) {
if (ar.succeeded()) {
pongHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.core.buffer.Buffer.newInstance((io.vertx.core.buffer.Buffer)ar.result())));
} else {
pongHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
});
return this;
}
/**
* Send a frame to the remote endpoint.
*
* This is not implemented for HTTP/1.x.
* @param data the 8 bytes data of the frame
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava.core.http.HttpConnection ping(io.vertx.rxjava.core.buffer.Buffer data) {
return
ping(data, ar -> { });
}
/**
* Send a frame to the remote endpoint.
*
* This is not implemented for HTTP/1.x.
* @param data the 8 bytes data of the frame
* @return a reference to this, so the API can be used fluently
*/
public Single rxPing(io.vertx.rxjava.core.buffer.Buffer data) {
return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
ping(data, fut);
}));
}
/**
* Set an handler notified when a frame is received from the remote endpoint.
*
* This is not implemented for HTTP/1.x.
* @param handler the handler to be called when a is received
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava.core.http.HttpConnection pingHandler(Handler handler) {
delegate.pingHandler(new Handler() {
public void handle(io.vertx.core.buffer.Buffer event) {
handler.handle(io.vertx.rxjava.core.buffer.Buffer.newInstance((io.vertx.core.buffer.Buffer)event));
}
});
return this;
}
/**
* Set an handler called when a connection error happens
* @param handler the handler
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava.core.http.HttpConnection exceptionHandler(Handler handler) {
delegate.exceptionHandler(handler);
return this;
}
/**
* @return the remote address for this connection, possibly null
(e.g a server bound on a domain socket). If useProxyProtocol
is set to true
, the address returned will be of the actual connecting client.
*/
public io.vertx.rxjava.core.net.SocketAddress remoteAddress() {
if (cached_0 != null) {
return cached_0;
}
io.vertx.rxjava.core.net.SocketAddress ret = io.vertx.rxjava.core.net.SocketAddress.newInstance((io.vertx.core.net.SocketAddress)delegate.remoteAddress());
cached_0 = ret;
return ret;
}
/**
* @return the local address for this connection, possibly null
(e.g a server bound on a domain socket) If useProxyProtocol
is set to true
, the address returned will be of the proxy.
*/
public io.vertx.rxjava.core.net.SocketAddress localAddress() {
if (cached_1 != null) {
return cached_1;
}
io.vertx.rxjava.core.net.SocketAddress ret = io.vertx.rxjava.core.net.SocketAddress.newInstance((io.vertx.core.net.SocketAddress)delegate.localAddress());
cached_1 = ret;
return ret;
}
/**
* @return true if this {@link io.vertx.rxjava.core.http.HttpConnection} is encrypted via SSL/TLS.
*/
public boolean isSsl() {
boolean ret = delegate.isSsl();
return ret;
}
/**
* Returns the SNI server name presented during the SSL handshake by the client.
* @return the indicated server name
*/
public String indicatedServerName() {
String ret = delegate.indicatedServerName();
return ret;
}
/**
* @return SSLSession associated with the underlying socket. Returns null if connection is not SSL.
*/
public javax.net.ssl.SSLSession sslSession() {
javax.net.ssl.SSLSession ret = delegate.sslSession();
return ret;
}
private io.vertx.rxjava.core.net.SocketAddress cached_0;
private io.vertx.rxjava.core.net.SocketAddress cached_1;
public static HttpConnection newInstance(io.vertx.core.http.HttpConnection arg) {
return arg != null ? new HttpConnection(arg) : null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy