Module org.eclipse.jetty.client
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 java.lang.Object implements Request.Content.Subscription
Partial implementation of
Subscription.Implements the algorithm described in
Request.Content.
-
-
Constructor Summary
Constructors Constructor Description AbstractSubscription(Request.Content.Consumer consumer, boolean emitInitialContent)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voiddemand()Demands more content, which eventually results inRequest.Content.Consumer.onContent(ByteBuffer, boolean, Callback)to be invoked.voidfail(java.lang.Throwable failure)Fails the subscription, notifying the content producer to stop producing content.protected voidnotifyContent(java.nio.ByteBuffer buffer, boolean last, org.eclipse.jetty.util.Callback callback)protected abstract booleanproduceContent(AbstractRequestContent.Producer producer)Subclasses implement this method to produce content, without worrying about demand or exception handling.java.lang.StringtoString()
-
-
-
Constructor Detail
-
AbstractSubscription
public AbstractSubscription(Request.Content.Consumer consumer, boolean emitInitialContent)
-
-
Method Detail
-
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 java.lang.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:
java.lang.Exception- when content production fails
-
fail
public void fail(java.lang.Throwable failure)
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
protected void notifyContent(java.nio.ByteBuffer buffer, boolean last, org.eclipse.jetty.util.Callback callback)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-