Package org.eclipse.jetty.http2.client
Class HTTP2Client
java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.ContainerLifeCycle
org.eclipse.jetty.http2.client.HTTP2Client
- All Implemented Interfaces:
org.eclipse.jetty.util.component.Container,org.eclipse.jetty.util.component.Destroyable,org.eclipse.jetty.util.component.Dumpable,org.eclipse.jetty.util.component.Dumpable.DumpableContainer,org.eclipse.jetty.util.component.LifeCycle
@ManagedObject
public class HTTP2Client
extends org.eclipse.jetty.util.component.ContainerLifeCycle
HTTP2Client provides an asynchronous, non-blocking implementation
to send HTTP/2 frames to a server.
Typical usage:
// Create and start HTTP2Client.
HTTP2Client client = new HTTP2Client();
SslContextFactory sslContextFactory = new SslContextFactory();
client.addBean(sslContextFactory);
client.start();
// Connect to host.
String host = "webtide.com";
int port = 443;
FuturePromise<Session> sessionPromise = new FuturePromise<>();
client.connect(sslContextFactory, new InetSocketAddress(host, port), new ServerSessionListener.Adapter(), sessionPromise);
// Obtain the client Session object.
Session session = sessionPromise.get(5, TimeUnit.SECONDS);
// Prepare the HTTP request headers.
HttpFields requestFields = new HttpFields();
requestFields.put("User-Agent", client.getClass().getName() + "/" + Jetty.VERSION);
// Prepare the HTTP request object.
MetaData.Request request = new MetaData.Request("PUT", new HttpURI("https://" + host + ":" + port + "/"), HttpVersion.HTTP_2, requestFields);
// Create the HTTP/2 HEADERS frame representing the HTTP request.
HeadersFrame headersFrame = new HeadersFrame(request, null, false);
// Prepare the listener to receive the HTTP response frames.
Stream.Listener responseListener = new new Stream.Listener.Adapter()
{
@Override
public void onHeaders(Stream stream, HeadersFrame frame)
{
System.err.println(frame);
}
@Override
public void onData(Stream stream, DataFrame frame, Callback callback)
{
System.err.println(frame);
callback.succeeded();
}
};
// Send the HEADERS frame to create a stream.
FuturePromise<Stream> streamPromise = new FuturePromise<>();
session.newStream(headersFrame, streamPromise, responseListener);
Stream stream = streamPromise.get(5, TimeUnit.SECONDS);
// Use the Stream object to send request content, if any, using a DATA frame.
ByteBuffer content = ...;
DataFrame requestContent = new DataFrame(stream.getId(), content, true);
stream.data(requestContent, Callback.Adapter.INSTANCE);
// When done, stop the client.
client.stop();
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListenerNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
org.eclipse.jetty.util.component.Container.InheritedListener, org.eclipse.jetty.util.component.Container.ListenerNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
org.eclipse.jetty.util.component.Dumpable.DumpableContainerNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
org.eclipse.jetty.util.component.LifeCycle.Listener -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate SocketAddressprivate org.eclipse.jetty.io.ByteBufferPoolprivate booleanprivate org.eclipse.jetty.io.ClientConnectionFactoryprivate longprivate Executorprivate FlowControlStrategy.Factoryprivate longprivate intprivate intprivate intprivate intprivate intprivate intprivate intprivate intprivate intprivate intprivate org.eclipse.jetty.util.thread.Schedulerprivate org.eclipse.jetty.io.SelectorManagerprivate intprivate longprivate booleanFields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPINGFields inherited from interface org.eclipse.jetty.util.component.Dumpable
KEY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory, SocketChannel channel, Session.Listener listener, org.eclipse.jetty.util.Promise<Session> promise) protected voidconfigure(SocketChannel channel) voidconnect(InetSocketAddress address, Session.Listener listener, org.eclipse.jetty.util.Promise<Session> promise) voidconnect(org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory, InetSocketAddress address, Session.Listener listener, org.eclipse.jetty.util.Promise<Session> promise) voidconnect(org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory, InetSocketAddress address, Session.Listener listener, org.eclipse.jetty.util.Promise<Session> promise, Map<String, Object> context) contextFrom(org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory, InetSocketAddress address, Session.Listener listener, org.eclipse.jetty.util.Promise<Session> promise, Map<String, Object> context) protected voiddoStart()org.eclipse.jetty.io.ByteBufferPoolorg.eclipse.jetty.io.ClientConnectionFactorylonglongintintintintintintDeprecated.intintDeprecated.intintintintorg.eclipse.jetty.util.thread.Schedulerintlongbooleanbooleanprotected org.eclipse.jetty.io.SelectorManagerprotected org.eclipse.jetty.io.ClientConnectionFactorynewSslClientConnectionFactory(org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory, org.eclipse.jetty.io.ClientConnectionFactory connectionFactory) voidsetBindAddress(SocketAddress bindAddress) voidsetByteBufferPool(org.eclipse.jetty.io.ByteBufferPool bufferPool) voidsetClientConnectionFactory(org.eclipse.jetty.io.ClientConnectionFactory connectionFactory) voidsetConnectBlocking(boolean connectBlocking) voidsetConnectTimeout(long connectTimeout) voidsetExecutor(Executor executor) voidsetFlowControlStrategyFactory(FlowControlStrategy.Factory flowControlStrategyFactory) voidsetIdleTimeout(long idleTimeout) voidsetInitialSessionRecvWindow(int initialSessionRecvWindow) voidsetInitialStreamRecvWindow(int initialStreamRecvWindow) voidsetInputBufferSize(int inputBufferSize) voidsetMaxConcurrentPushedStreams(int maxConcurrentPushedStreams) voidsetMaxDecoderTableCapacity(int maxDecoderTableCapacity) voidsetMaxDynamicTableSize(int maxDynamicTableSize) Deprecated.voidsetMaxEncoderTableCapacity(int maxEncoderTableCapacity) Sets the limit for the encoder HPACK dynamic table capacity.voidsetMaxFrameLength(int maxFrameLength) Deprecated.voidsetMaxFrameSize(int maxFrameSize) voidsetMaxHeaderBlockFragment(int maxHeaderBlockFragment) voidsetMaxResponseHeadersSize(int maxResponseHeadersSize) voidsetMaxSettingsKeys(int maxSettingsKeys) voidsetProtocols(List<String> protocols) voidsetScheduler(org.eclipse.jetty.util.thread.Scheduler scheduler) voidsetSelectors(int selectors) voidsetStreamIdleTimeout(long streamIdleTimeout) voidsetTCPNoDelay(boolean tcpNoDelay) Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, destroy, doStop, dump, dump, dump, dump, dump, dumpBeans, dumpObject, dumpObjects, dumpStdErr, dumpThis, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeansMethods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.eclipse.jetty.util.component.Dumpable
dumpSelfMethods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer
isDumpable
-
Field Details
-
executor
-
scheduler
private org.eclipse.jetty.util.thread.Scheduler scheduler -
bufferPool
private org.eclipse.jetty.io.ByteBufferPool bufferPool -
connectionFactory
private org.eclipse.jetty.io.ClientConnectionFactory connectionFactory -
selector
private org.eclipse.jetty.io.SelectorManager selector -
selectors
private int selectors -
idleTimeout
private long idleTimeout -
connectTimeout
private long connectTimeout -
streamIdleTimeout
private long streamIdleTimeout -
connectBlocking
private boolean connectBlocking -
bindAddress
-
tcpNoDelay
private boolean tcpNoDelay -
inputBufferSize
private int inputBufferSize -
protocols
-
initialSessionRecvWindow
private int initialSessionRecvWindow -
initialStreamRecvWindow
private int initialStreamRecvWindow -
maxFrameSize
private int maxFrameSize -
maxConcurrentPushedStreams
private int maxConcurrentPushedStreams -
maxSettingsKeys
private int maxSettingsKeys -
maxDecoderTableCapacity
private int maxDecoderTableCapacity -
maxEncoderTableCapacity
private int maxEncoderTableCapacity -
maxHeaderBlockFragment
private int maxHeaderBlockFragment -
maxResponseHeadersSize
private int maxResponseHeadersSize -
flowControlStrategyFactory
-
-
Constructor Details
-
HTTP2Client
public HTTP2Client()
-
-
Method Details
-
doStart
- Overrides:
doStartin classorg.eclipse.jetty.util.component.ContainerLifeCycle- Throws:
Exception
-
newSelectorManager
protected org.eclipse.jetty.io.SelectorManager newSelectorManager() -
newSslClientConnectionFactory
protected org.eclipse.jetty.io.ClientConnectionFactory newSslClientConnectionFactory(org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory, org.eclipse.jetty.io.ClientConnectionFactory connectionFactory) -
getExecutor
-
setExecutor
-
getScheduler
public org.eclipse.jetty.util.thread.Scheduler getScheduler() -
setScheduler
public void setScheduler(org.eclipse.jetty.util.thread.Scheduler scheduler) -
getByteBufferPool
public org.eclipse.jetty.io.ByteBufferPool getByteBufferPool() -
setByteBufferPool
public void setByteBufferPool(org.eclipse.jetty.io.ByteBufferPool bufferPool) -
getClientConnectionFactory
public org.eclipse.jetty.io.ClientConnectionFactory getClientConnectionFactory() -
setClientConnectionFactory
public void setClientConnectionFactory(org.eclipse.jetty.io.ClientConnectionFactory connectionFactory) -
getFlowControlStrategyFactory
-
setFlowControlStrategyFactory
-
getSelectors
@ManagedAttribute("The number of selectors") public int getSelectors() -
setSelectors
public void setSelectors(int selectors) -
getIdleTimeout
@ManagedAttribute("The idle timeout in milliseconds") public long getIdleTimeout() -
setIdleTimeout
public void setIdleTimeout(long idleTimeout) -
getStreamIdleTimeout
@ManagedAttribute("The stream idle timeout in milliseconds") public long getStreamIdleTimeout() -
setStreamIdleTimeout
public void setStreamIdleTimeout(long streamIdleTimeout) -
getConnectTimeout
@ManagedAttribute("The connect timeout in milliseconds") public long getConnectTimeout() -
setConnectTimeout
public void setConnectTimeout(long connectTimeout) -
isConnectBlocking
@ManagedAttribute("Whether the connect() operation is blocking") public boolean isConnectBlocking() -
setConnectBlocking
public void setConnectBlocking(boolean connectBlocking) -
getBindAddress
-
setBindAddress
-
isTCPNoDelay
public boolean isTCPNoDelay() -
setTCPNoDelay
public void setTCPNoDelay(boolean tcpNoDelay) -
getInputBufferSize
@ManagedAttribute("The size of the buffer used to read from the network") public int getInputBufferSize() -
setInputBufferSize
public void setInputBufferSize(int inputBufferSize) -
getProtocols
-
setProtocols
-
getInitialSessionRecvWindow
@ManagedAttribute("The initial size of session\'s flow control receive window") public int getInitialSessionRecvWindow() -
setInitialSessionRecvWindow
public void setInitialSessionRecvWindow(int initialSessionRecvWindow) -
getInitialStreamRecvWindow
@ManagedAttribute("The initial size of stream\'s flow control receive window") public int getInitialStreamRecvWindow() -
setInitialStreamRecvWindow
public void setInitialStreamRecvWindow(int initialStreamRecvWindow) -
getMaxFrameLength
Deprecated. -
setMaxFrameLength
Deprecated. -
getMaxFrameSize
@ManagedAttribute("The max frame size in bytes") public int getMaxFrameSize() -
setMaxFrameSize
public void setMaxFrameSize(int maxFrameSize) -
getMaxConcurrentPushedStreams
@ManagedAttribute("The max number of concurrent pushed streams") public int getMaxConcurrentPushedStreams() -
setMaxConcurrentPushedStreams
public void setMaxConcurrentPushedStreams(int maxConcurrentPushedStreams) -
getMaxSettingsKeys
@ManagedAttribute("The max number of keys in all SETTINGS frames") public int getMaxSettingsKeys() -
setMaxSettingsKeys
public void setMaxSettingsKeys(int maxSettingsKeys) -
getMaxEncoderTableCapacity
@ManagedAttribute("The HPACK encoder dynamic table maximum capacity") public int getMaxEncoderTableCapacity() -
setMaxEncoderTableCapacity
public void setMaxEncoderTableCapacity(int maxEncoderTableCapacity) Sets the limit for the encoder HPACK dynamic table capacity.
Setting this value to
0disables the use of the dynamic table.- Parameters:
maxEncoderTableCapacity- The HPACK encoder dynamic table maximum capacity
-
getMaxDecoderTableCapacity
@ManagedAttribute("The HPACK decoder dynamic table maximum capacity") public int getMaxDecoderTableCapacity() -
setMaxDecoderTableCapacity
public void setMaxDecoderTableCapacity(int maxDecoderTableCapacity) -
getMaxDynamicTableSize
@Deprecated @ManagedAttribute("The HPACK dynamic table maximum size") public int getMaxDynamicTableSize()Deprecated. -
setMaxDynamicTableSize
Deprecated. -
getMaxHeaderBlockFragment
@ManagedAttribute("The max size of header block fragments") public int getMaxHeaderBlockFragment() -
setMaxHeaderBlockFragment
public void setMaxHeaderBlockFragment(int maxHeaderBlockFragment) -
getMaxResponseHeadersSize
@ManagedAttribute("The max size of response headers") public int getMaxResponseHeadersSize() -
setMaxResponseHeadersSize
public void setMaxResponseHeadersSize(int maxResponseHeadersSize) -
connect
public void connect(InetSocketAddress address, Session.Listener listener, org.eclipse.jetty.util.Promise<Session> promise) -
connect
public void connect(org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory, InetSocketAddress address, Session.Listener listener, org.eclipse.jetty.util.Promise<Session> promise) -
connect
public void connect(org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory, InetSocketAddress address, Session.Listener listener, org.eclipse.jetty.util.Promise<Session> promise, Map<String, Object> context) -
accept
public void accept(org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory, SocketChannel channel, Session.Listener listener, org.eclipse.jetty.util.Promise<Session> promise) -
contextFrom
private Map<String,Object> contextFrom(org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory, InetSocketAddress address, Session.Listener listener, org.eclipse.jetty.util.Promise<Session> promise, Map<String, Object> context) -
configure
- Throws:
IOException
-