Class FeedableBodyGenerator
java.lang.Object
com.ning.http.client.providers.grizzly.FeedableBodyGenerator
- All Implemented Interfaces:
BodyGenerator
A Grizzly-specific
BodyGenerator that allows data to be fed to the
connection in blocking or non-blocking fashion via the use of a FeedableBodyGenerator.Feeder.
This class provides two FeedableBodyGenerator.Feeder implementations for rapid prototyping.
First is the FeedableBodyGenerator.SimpleFeeder which is simply a listener that asynchronous
data transferring has been initiated. The second is the FeedableBodyGenerator.NonBlockingFeeder
which allows reading and feeding data in a non-blocking fashion.- Since:
- 1.7.0
- Author:
- The Grizzly Team
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBase class forFeedableBodyGenerator.Feederimplementations.static interfaceSpecifies the functionality all Feeders must implement.static classImplementations of this class provide the framework to read data from some source and feed data to theFeedableBodyGeneratorwithout blocking.static classThis simpleFeedableBodyGenerator.Feederimplementation allows the implementation to feed data in whatever fashion is deemed appropriate. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreates a new instance of the request body to be read.voidAdd aFeedableBodyGenerator.Feederimplementation that will be invoked when writing without blocking is possible.voidsetMaxPendingBytes(int maxPendingBytes) Configured the maximum number of bytes that may be pending to be written to the wire.
-
Field Details
-
UNBOUND
public static final int UNBOUNDThere is no limit on bytes waiting to be written. This configuration value should be used with caution as it could lead to out-of-memory conditions.- See Also:
-
DEFAULT
public static final int DEFAULTDefer to whatever the connection has been configured for max pending bytes.- See Also:
-
-
Constructor Details
-
FeedableBodyGenerator
public FeedableBodyGenerator()
-
-
Method Details
-
createBody
Description copied from interface:BodyGeneratorCreates a new instance of the request body to be read. While each invocation of this method is supposed to create a fresh instance of the body, the actual contents of all these body instances is the same. For example, the body needs to be resend after an authentication challenge of a redirect.- Specified by:
createBodyin interfaceBodyGenerator- Returns:
- The request body, never
null. - Throws:
IOException- If the body could not be created.
-
setMaxPendingBytes
public void setMaxPendingBytes(int maxPendingBytes) Configured the maximum number of bytes that may be pending to be written to the wire. If not explicitly configured, the connection's current configuration will be used instead. Once all data has been fed, the connection's max pending bytes configuration will be restored to its original value.- Parameters:
maxPendingBytes- maximum number of bytes that may be queued to be written to the wire.- Throws:
IllegalStateException- if called afterinitializeAsynchronousTransfer(FilterChainContext, HttpRequestPacket)has been called by theGrizzlyAsyncHttpProvider.IllegalArgumentException- if maxPendingBytes is less than zero and is notUNBOUNDorDEFAULT.
-
setFeeder
Add aFeedableBodyGenerator.Feederimplementation that will be invoked when writing without blocking is possible. This method must be set before dispatching the request this feeder is associated with.- Parameters:
feeder- theFeedableBodyGenerator.Feederresponsible for providing data.- Throws:
IllegalStateException- if called afterinitializeAsynchronousTransfer(FilterChainContext, HttpRequestPacket)has been called by theGrizzlyAsyncHttpProvider.IllegalArgumentException- iffeederisnull
-