Package org.eclipse.jetty.client.util
Class AbstractRequestContent.AbstractSubscription
java.lang.Object
org.eclipse.jetty.client.util.AbstractRequestContent.AbstractSubscription
- All Implemented Interfaces:
Request.Content.Subscription
- Enclosing class:
- AbstractRequestContent
public abstract class AbstractRequestContent.AbstractSubscription
extends Object
implements Request.Content.Subscription
Partial implementation of Subscription
.
Implements the algorithm described in Request.Content
.
-
Constructor Summary
ConstructorDescriptionAbstractSubscription
(Request.Content.Consumer consumer, boolean emitInitialContent) -
Method Summary
Modifier and TypeMethodDescriptionvoid
demand()
Demands more content, which eventually results inRequest.Content.Consumer.onContent(ByteBuffer, boolean, Callback)
to be invoked.void
Fails the subscription, notifying the content producer to stop producing content.protected void
notifyContent
(ByteBuffer buffer, boolean last, Callback callback) protected abstract boolean
Subclasses implement this method to produce content, without worrying about demand or exception handling.toString()
-
Constructor Details
-
AbstractSubscription
-
-
Method Details
-
demand
public void demand()Description copied from interface:Request.Content.Subscription
Demands more content, which eventually results in
Request.Content.Consumer.onContent(ByteBuffer, boolean, Callback)
to be invoked.- Specified by:
demand
in interfaceRequest.Content.Subscription
-
produceContent
protected abstract boolean produceContent(AbstractRequestContent.Producer producer) throws Exception Subclasses implement this method to produce content, without worrying about demand or exception handling.
Typical implementation (pseudo code):
protected boolean produceContent(Producer producer) throws Exception { // Step 1: try to produce content, exceptions may be thrown during production // (for example, producing content reading from an InputStream may throw). // Step 2A: content could be produced. ByteBuffer buffer = ...; boolean last = ...; Callback callback = ...; return producer.produce(buffer, last, callback); // Step 2B: content could not be produced. // (for example it is not available yet) return false; }
- Parameters:
producer
- the producer to notify when content can be produced- Returns:
- whether content production should continue
- Throws:
Exception
- when content production fails
-
fail
Description copied from interface:Request.Content.Subscription
Fails the subscription, notifying the content producer to stop producing content.
Typical failure: a proxy consumer waiting for more content (or waiting to demand content) that is failed by an error response from the server.
- Specified by:
fail
in interfaceRequest.Content.Subscription
- Parameters:
failure
- the reason of the failure
-
notifyContent
-
toString
-