Class DeferredContentProvider
- All Implemented Interfaces:
Closeable,AutoCloseable,Iterable<ByteBuffer>,ContentProvider,AsyncContentProvider,Callback,Invocable
ContentProvider that allows to add content after Request.send(Response.CompleteListener)
has been called, therefore providing the request content at a later time.
DeferredContentProvider can only be used in conjunction with
Request.send(Response.CompleteListener) (and not with its blocking counterpart Request.send())
because it provides content asynchronously.
The deferred content is provided once and then fully consumed.
Invocations to the iterator() method after the first will return an "empty" iterator
because the stream has been consumed on the first invocation.
However, it is possible for subclasses to override offer(ByteBuffer) and close() to copy
the content to another location (for example a file) and be able to support multiple invocations
of of iterator() returning the iterator provided by this
class on the first invocation, and an iterator on the bytes copied to the other location
for subsequent invocations.
Typical usage of DeferredContentProvider is in asynchronous proxies, where HTTP headers arrive
separately from HTTP content chunks.
The deferred content must be provided through offer(ByteBuffer), which can be invoked multiple
times, and when all content has been provided it must be signaled with a call to close().
Example usage:
HttpClient httpClient = ...;
// Use try-with-resources to autoclose DeferredContentProvider
try (DeferredContentProvider content = new DeferredContentProvider())
{
httpClient.newRequest("localhost", 8080)
.content(content)
.send(new Response.CompleteListener()
{
@Override
public void onComplete(Result result)
{
// Your logic here
}
});
// At a later time...
content.offer(ByteBuffer.wrap("some content".getBytes()));
}
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface org.eclipse.jetty.client.AsyncContentProvider
AsyncContentProvider.ListenerNested classes/interfaces inherited from interface org.eclipse.jetty.util.Callback
Callback.Completable, Callback.Completing, Callback.NestedNested classes/interfaces inherited from interface org.eclipse.jetty.client.api.ContentProvider
ContentProvider.TypedNested classes/interfaces inherited from interface org.eclipse.jetty.util.thread.Invocable
Invocable.InvocationType, Invocable.ReadyTask, Invocable.Task -
Field Summary
Fields inherited from interface org.eclipse.jetty.util.thread.Invocable
__nonBlocking -
Constructor Summary
ConstructorsConstructorDescriptionDeferredContentProvider(ByteBuffer... buffers) Deprecated.Creates a newDeferredContentProviderwith the given initial content -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Deprecated.No more content will be added to this content provider and notifies the listener that no more content is available.voidDeprecated.Callback invoked when the operation fails.voidflush()Deprecated.longDeprecated.booleanisClosed()Deprecated.iterator()Deprecated.booleanoffer(ByteBuffer buffer) Deprecated.Adds the given content buffer to this content provider and notifies the listener that content is available.booleanoffer(ByteBuffer buffer, Callback callback) Deprecated.voidsetListener(AsyncContentProvider.Listener listener) Deprecated.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.eclipse.jetty.util.Callback
completeWith, succeededMethods inherited from interface org.eclipse.jetty.client.api.ContentProvider
isReproducibleMethods inherited from interface org.eclipse.jetty.util.thread.Invocable
getInvocationTypeMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
DeferredContentProvider
Deprecated.Creates a newDeferredContentProviderwith the given initial content- Parameters:
buffers- the initial content
-
-
Method Details
-
setListener
Deprecated.- Specified by:
setListenerin interfaceAsyncContentProvider- Parameters:
listener- the listener to be notified of content availability
-
getLength
public long getLength()Deprecated.- Specified by:
getLengthin interfaceContentProvider- Returns:
- the content length, if known, or -1 if the content length is unknown
-
offer
Deprecated.Adds the given content buffer to this content provider and notifies the listener that content is available.- Parameters:
buffer- the content to add- Returns:
- true if the content was added, false otherwise
-
offer
Deprecated. -
flush
Deprecated.- Throws:
IOException
-
close
public void close()Deprecated.No more content will be added to this content provider and notifies the listener that no more content is available.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
isClosed
public boolean isClosed()Deprecated. -
failed
Deprecated.Description copied from interface:CallbackCallback invoked when the operation fails.
-
iterator
Deprecated.- Specified by:
iteratorin interfaceIterable<ByteBuffer>
-
AsyncRequestContentinstead.