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:
 AutoCloseable, Container, Destroyable, Dumpable, Dumpable.DumpableContainer, LifeCycle
HTTP2Client provides an asynchronous, non-blocking implementation to send HTTP/2 frames to a server.
Typical usage:
 // Create and start HTTP2Client.
 HTTP2Client http2Client = new HTTP2Client();
 http2Client.start();
 SslContextFactory sslContextFactory = http2Client.getClientConnector().getSslContextFactory();
 // Connect to host.
 String host = "webtide.com";
 int port = 443;
 CompletableFuture<Session> sessionPromise = http2Client.connect(sslContextFactory, new InetSocketAddress(host, port), new ServerSessionListener() {});
 // Obtain the client-side Session object.
 Session session = sessionPromise.get(5, TimeUnit.SECONDS);
 // Prepare the HTTP request headers.
 HttpFields.Mutable requestFields = HttpFields.build();
 requestFields.put("User-Agent", http2Client.getClass().getName() + "/" + Jetty.VERSION);
 // Prepare the HTTP request object.
 MetaData.Request request = new MetaData.Request("PUT", HttpURI.from("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 Stream.Listener()
 {
      @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.
 CompletableFuture<Stream> streamPromise = session.newStream(headersFrame, responseListener);
 Stream stream = streamPromise.get(5, TimeUnit.SECONDS);
 // Use the Stream object to send request content, if any, using a DATA frame.
 ByteBuffer content = UTF_8.encode("hello");
 DataFrame requestContent = new DataFrame(stream.getId(), content, true);
 stream.data(requestContent, Callback.NOOP);
 // When done, stop the HTTP2Client.
 http2Client.stop();
 - 
Nested Class Summary
Nested classes/interfaces inherited from class AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener, AbstractLifeCycle.StopExceptionNested classes/interfaces inherited from interface Container
Container.InheritedListener, Container.ListenerNested classes/interfaces inherited from interface Dumpable
Dumpable.DumpableContainer, Dumpable.DumpAppendableNested classes/interfaces inherited from interface LifeCycle
LifeCycle.Listener - 
Field Summary
Fields - 
Constructor Summary
Constructors - 
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(Transport transport, SslContextFactory.Client sslContextFactory, SocketChannel channel, Session.Listener listener, Promise<Session> promise) Accepts the already connectedSocketChannelfor clear-text or secure HTTP/2 with the specifiedTransport.voidaccept(SslContextFactory.Client sslContextFactory, SocketChannel channel, Session.Listener listener, Promise<Session> promise) Accepts the already connectedSocketChannelfor clear-text or secure HTTP/2.voidclose()connect(SocketAddress address, Session.Listener listener) Connect for clear-text HTTP/2.voidconnect(SocketAddress address, Session.Listener listener, Promise<Session> promise) Connect for clear-text HTTP/2.connect(Transport transport, SslContextFactory.Client sslContextFactory, SocketAddress address, Session.Listener listener) Connect for clear-text or secure HTTP/2 with the specifiedTransport.voidconnect(Transport transport, SslContextFactory.Client sslContextFactory, SocketAddress address, Session.Listener listener, Promise<Session> promise) Connect for clear-text or secure HTTP/2 with the specifiedTransport.voidconnect(Transport transport, SslContextFactory.Client sslContextFactory, SocketAddress address, Session.Listener listener, Promise<Session> promise, Map<String, Object> context) connect(SslContextFactory.Client sslContextFactory, SocketAddress address, Session.Listener listener) Connect for clear-text or secure HTTP/2.voidconnect(SslContextFactory.Client sslContextFactory, SocketAddress address, Session.Listener listener, Promise<Session> promise) Connect for clear-text or secure HTTP/2.longlongintintintintintintintintintintintintlongbooleanbooleanbooleanbooleanvoidsetApplicationProtocols(List<String> protocols) voidsetBindAddress(SocketAddress bindAddress) voidsetByteBufferPool(ByteBufferPool bufferPool) 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) voidsetMaxEncoderTableCapacity(int maxEncoderTableCapacity) Sets the limit for the encoder HPACK dynamic table capacity.voidsetMaxFrameSize(int maxFrameSize) voidsetMaxHeaderBlockFragment(int maxHeaderBlockFragment) voidsetMaxRequestHeadersSize(int maxRequestHeadersSize) voidsetMaxResponseHeadersSize(int maxResponseHeadersSize) voidsetMaxSettingsKeys(int maxSettingsKeys) voidsetScheduler(Scheduler scheduler) voidsetSelectors(int selectors) voidsetStreamIdleTimeout(long streamIdleTimeout) voidsetUseALPN(boolean useALPN) voidsetUseInputDirectByteBuffers(boolean useInputDirectByteBuffers) voidsetUseOutputDirectByteBuffers(boolean useOutputDirectByteBuffers) Methods inherited from class ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, destroy, doStart, doStop, dump, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, installBean, installBean, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans, updateBeansMethods inherited from class AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop, toStringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Container
getCachedBeans, getEventListenersMethods inherited from interface Dumpable.DumpableContainer
isDumpable 
- 
Field Details
- 
CONTEXT_KEY
 - 
SESSION_PROMISE_CONTEXT_KEY
 - 
SESSION_LISTENER_CONTEXT_KEY
 
 - 
 - 
Constructor Details
- 
HTTP2Client
public HTTP2Client() - 
HTTP2Client
 
 - 
 - 
Method Details
- 
getClientConnector
 - 
getExecutor
 - 
setExecutor
 - 
getScheduler
 - 
setScheduler
 - 
getByteBufferPool
 - 
setByteBufferPool
 - 
getFlowControlStrategyFactory
 - 
setFlowControlStrategyFactory
 - 
getSelectors
 - 
setSelectors
public void setSelectors(int selectors)  - 
getIdleTimeout
 - 
setIdleTimeout
public void setIdleTimeout(long idleTimeout)  - 
getStreamIdleTimeout
 - 
setStreamIdleTimeout
public void setStreamIdleTimeout(long streamIdleTimeout)  - 
getConnectTimeout
 - 
setConnectTimeout
public void setConnectTimeout(long connectTimeout)  - 
isConnectBlocking
 - 
setConnectBlocking
public void setConnectBlocking(boolean connectBlocking)  - 
getBindAddress
 - 
setBindAddress
 - 
getInputBufferSize
@ManagedAttribute("The size of the buffer used to read from the network") public int getInputBufferSize() - 
setInputBufferSize
public void setInputBufferSize(int inputBufferSize)  - 
getApplicationProtocols
 - 
setApplicationProtocols
 - 
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)  - 
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
 - 
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)  - 
getMaxHeaderBlockFragment
 - 
setMaxHeaderBlockFragment
public void setMaxHeaderBlockFragment(int maxHeaderBlockFragment)  - 
getMaxRequestHeadersSize
 - 
setMaxRequestHeadersSize
public void setMaxRequestHeadersSize(int maxRequestHeadersSize)  - 
getMaxResponseHeadersSize
 - 
setMaxResponseHeadersSize
public void setMaxResponseHeadersSize(int maxResponseHeadersSize)  - 
isUseInputDirectByteBuffers
@ManagedAttribute("Whether to use direct ByteBuffers for reading") public boolean isUseInputDirectByteBuffers() - 
setUseInputDirectByteBuffers
public void setUseInputDirectByteBuffers(boolean useInputDirectByteBuffers)  - 
isUseOutputDirectByteBuffers
@ManagedAttribute("Whether to use direct ByteBuffers for writing") public boolean isUseOutputDirectByteBuffers() - 
setUseOutputDirectByteBuffers
public void setUseOutputDirectByteBuffers(boolean useOutputDirectByteBuffers)  - 
isUseALPN
@ManagedAttribute("Whether ALPN should be used when establishing connections") public boolean isUseALPN() - 
setUseALPN
public void setUseALPN(boolean useALPN)  - 
connect
Connect for clear-text HTTP/2.
- Parameters:
 address- the address to connect tolistener- the listener to notify of session events- Returns:
 - a 
CompletableFuturethat is completed when the connect operation is complete 
 - 
connect
Connect for clear-text HTTP/2.
- Parameters:
 address- the address to connect tolistener- the listener to notify of session eventspromise- thePromisethat is completed when the connect operation is complete
 - 
connect
public CompletableFuture<Session> connect(SslContextFactory.Client sslContextFactory, SocketAddress address, Session.Listener listener) Connect for clear-text or secure HTTP/2.
- Parameters:
 sslContextFactory-nullfor clear-text, non-nullfor secure HTTP/2address- the address to connect tolistener- the listener to notify of session events- Returns:
 - a 
CompletableFuturethat is completed when the connect operation is complete 
 - 
connect
public void connect(SslContextFactory.Client sslContextFactory, SocketAddress address, Session.Listener listener, Promise<Session> promise) Connect for clear-text or secure HTTP/2.
- Parameters:
 sslContextFactory-nullfor clear-text, non-nullfor secure HTTP/2address- the address to connect tolistener- the listener to notify of session eventspromise- thePromisethat is completed when the connect operation is complete
 - 
connect
public CompletableFuture<Session> connect(Transport transport, SslContextFactory.Client sslContextFactory, SocketAddress address, Session.Listener listener) Connect for clear-text or secure HTTP/2 with the specified
Transport.- Parameters:
 transport- theTransportto usesslContextFactory-nullfor clear-text, non-nullfor secure HTTP/2address- the address to connect tolistener- the listener to notify of session events- Returns:
 - a 
CompletableFuturethat is completed when the connect operation is complete 
 - 
connect
public void connect(Transport transport, SslContextFactory.Client sslContextFactory, SocketAddress address, Session.Listener listener, Promise<Session> promise) Connect for clear-text or secure HTTP/2 with the specified
Transport.- Parameters:
 transport- theTransportto usesslContextFactory-nullfor clear-text, non-nullfor secure HTTP/2address- the address to connect tolistener- the listener to notify of session eventspromise- thePromisethat is completed when the connect operation is complete
 - 
connect
public void connect(Transport transport, SslContextFactory.Client sslContextFactory, SocketAddress address, Session.Listener listener, Promise<Session> promise, Map<String, Object> context)  - 
accept
public void accept(SslContextFactory.Client sslContextFactory, SocketChannel channel, Session.Listener listener, Promise<Session> promise) Accepts the already connected
SocketChannelfor clear-text or secure HTTP/2.- Parameters:
 sslContextFactory-nullfor clear-text, non-nullfor secure HTTP/2channel- the already connectedSocketChannellistener- the listener to notify of session eventspromise- thePromisethat is completed when the connect operation is complete
 - 
accept
public void accept(Transport transport, SslContextFactory.Client sslContextFactory, SocketChannel channel, Session.Listener listener, Promise<Session> promise) Accepts the already connected
SocketChannelfor clear-text or secure HTTP/2 with the specifiedTransport.- Parameters:
 transport- theTransportto usesslContextFactory-nullfor clear-text, non-nullfor secure HTTP/2channel- the already connectedSocketChannellistener- the listener to notify of session eventspromise- thePromisethat is completed when the connect operation is complete
 - 
close
- Specified by:
 closein interfaceAutoCloseable- Throws:
 Exception
 
 -