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:
Container
,Destroyable
,Dumpable
,Dumpable.DumpableContainer
,LifeCycle
@ManagedObject public class HTTP2Client extends 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 classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
Container.InheritedListener, Container.Listener
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainer
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
LifeCycle.Listener
-
-
Constructor Summary
Constructors Constructor Description HTTP2Client()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
accept(SslContextFactory sslContextFactory, java.nio.channels.SocketChannel channel, Session.Listener listener, Promise<Session> promise)
protected void
configure(java.nio.channels.SocketChannel channel)
void
connect(java.net.InetSocketAddress address, Session.Listener listener, Promise<Session> promise)
void
connect(SslContextFactory sslContextFactory, java.net.InetSocketAddress address, Session.Listener listener, Promise<Session> promise)
void
connect(SslContextFactory sslContextFactory, java.net.InetSocketAddress address, Session.Listener listener, Promise<Session> promise, java.util.Map<java.lang.String,java.lang.Object> context)
protected void
doStart()
Starts the managed lifecycle beans in the order they were added.java.net.SocketAddress
getBindAddress()
ByteBufferPool
getByteBufferPool()
ClientConnectionFactory
getClientConnectionFactory()
long
getConnectTimeout()
java.util.concurrent.Executor
getExecutor()
FlowControlStrategy.Factory
getFlowControlStrategyFactory()
long
getIdleTimeout()
int
getInitialSessionRecvWindow()
int
getInitialStreamRecvWindow()
int
getInputBufferSize()
int
getMaxConcurrentPushedStreams()
int
getMaxDecoderTableCapacity()
int
getMaxDynamicTableSize()
Deprecated.int
getMaxEncoderTableCapacity()
int
getMaxFrameLength()
Deprecated.int
getMaxFrameSize()
int
getMaxHeaderBlockFragment()
int
getMaxResponseHeadersSize()
int
getMaxSettingsKeys()
java.util.List<java.lang.String>
getProtocols()
Scheduler
getScheduler()
int
getSelectors()
long
getStreamIdleTimeout()
boolean
isConnectBlocking()
boolean
isTCPNoDelay()
protected SelectorManager
newSelectorManager()
protected ClientConnectionFactory
newSslClientConnectionFactory(SslContextFactory sslContextFactory, ClientConnectionFactory connectionFactory)
void
setBindAddress(java.net.SocketAddress bindAddress)
void
setByteBufferPool(ByteBufferPool bufferPool)
void
setClientConnectionFactory(ClientConnectionFactory connectionFactory)
void
setConnectBlocking(boolean connectBlocking)
void
setConnectTimeout(long connectTimeout)
void
setExecutor(java.util.concurrent.Executor executor)
void
setFlowControlStrategyFactory(FlowControlStrategy.Factory flowControlStrategyFactory)
void
setIdleTimeout(long idleTimeout)
void
setInitialSessionRecvWindow(int initialSessionRecvWindow)
void
setInitialStreamRecvWindow(int initialStreamRecvWindow)
void
setInputBufferSize(int inputBufferSize)
void
setMaxConcurrentPushedStreams(int maxConcurrentPushedStreams)
void
setMaxDecoderTableCapacity(int maxDecoderTableCapacity)
void
setMaxDynamicTableSize(int maxDynamicTableSize)
Deprecated.void
setMaxEncoderTableCapacity(int maxEncoderTableCapacity)
Sets the limit for the encoder HPACK dynamic table capacity.void
setMaxFrameLength(int maxFrameLength)
Deprecated.void
setMaxFrameSize(int maxFrameSize)
void
setMaxHeaderBlockFragment(int maxHeaderBlockFragment)
void
setMaxResponseHeadersSize(int maxResponseHeadersSize)
void
setMaxSettingsKeys(int maxSettingsKeys)
void
setProtocols(java.util.List<java.lang.String> protocols)
void
setScheduler(Scheduler scheduler)
void
setSelectors(int selectors)
void
setStreamIdleTimeout(long streamIdleTimeout)
void
setTCPNoDelay(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, updateBeans
-
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer
isDumpable
-
-
-
-
Method Detail
-
doStart
protected void doStart() throws java.lang.Exception
Description copied from class:ContainerLifeCycle
Starts the managed lifecycle beans in the order they were added.- Overrides:
doStart
in classContainerLifeCycle
- Throws:
java.lang.Exception
-
newSelectorManager
protected SelectorManager newSelectorManager()
-
newSslClientConnectionFactory
protected ClientConnectionFactory newSslClientConnectionFactory(SslContextFactory sslContextFactory, ClientConnectionFactory connectionFactory)
-
getExecutor
public java.util.concurrent.Executor getExecutor()
-
setExecutor
public void setExecutor(java.util.concurrent.Executor executor)
-
getScheduler
public Scheduler getScheduler()
-
setScheduler
public void setScheduler(Scheduler scheduler)
-
getByteBufferPool
public ByteBufferPool getByteBufferPool()
-
setByteBufferPool
public void setByteBufferPool(ByteBufferPool bufferPool)
-
getClientConnectionFactory
public ClientConnectionFactory getClientConnectionFactory()
-
setClientConnectionFactory
public void setClientConnectionFactory(ClientConnectionFactory connectionFactory)
-
getFlowControlStrategyFactory
public FlowControlStrategy.Factory getFlowControlStrategyFactory()
-
setFlowControlStrategyFactory
public void setFlowControlStrategyFactory(FlowControlStrategy.Factory flowControlStrategyFactory)
-
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
public java.net.SocketAddress getBindAddress()
-
setBindAddress
public void setBindAddress(java.net.SocketAddress bindAddress)
-
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
@ManagedAttribute("The ALPN protocol list") public java.util.List<java.lang.String> getProtocols()
-
setProtocols
public void setProtocols(java.util.List<java.lang.String> protocols)
-
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 @ManagedAttribute("The max frame length in bytes") public int getMaxFrameLength()
Deprecated.
-
setMaxFrameLength
@Deprecated public void setMaxFrameLength(int maxFrameLength)
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
0
disables 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 public void setMaxDynamicTableSize(int maxDynamicTableSize)
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(java.net.InetSocketAddress address, Session.Listener listener, Promise<Session> promise)
-
connect
public void connect(SslContextFactory sslContextFactory, java.net.InetSocketAddress address, Session.Listener listener, Promise<Session> promise)
-
connect
public void connect(SslContextFactory sslContextFactory, java.net.InetSocketAddress address, Session.Listener listener, Promise<Session> promise, java.util.Map<java.lang.String,java.lang.Object> context)
-
accept
public void accept(SslContextFactory sslContextFactory, java.nio.channels.SocketChannel channel, Session.Listener listener, Promise<Session> promise)
-
configure
protected void configure(java.nio.channels.SocketChannel channel) throws java.io.IOException
- Throws:
java.io.IOException
-
-