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
ConstructorsConstructorDescriptionAbstractSubscription(Request.Content.Consumer consumer, boolean emitInitialContent) -
Method Summary
Modifier and TypeMethodDescriptionvoiddemand()Demands more content, which eventually results inRequest.Content.Consumer.onContent(ByteBuffer, boolean, Callback)to be invoked.voidFails the subscription, notifying the content producer to stop producing content.protected voidnotifyContent(ByteBuffer buffer, boolean last, Callback callback) protected abstract booleanSubclasses 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.SubscriptionDemands more content, which eventually results in
Request.Content.Consumer.onContent(ByteBuffer, boolean, Callback)to be invoked.- Specified by:
demandin 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.SubscriptionFails 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:
failin interfaceRequest.Content.Subscription- Parameters:
failure- the reason of the failure
-
notifyContent
-
toString
-