com.ning.http.client.providers.grizzly
Class FeedableBodyGenerator

java.lang.Object
  extended by com.ning.http.client.providers.grizzly.FeedableBodyGenerator
All Implemented Interfaces:
BodyGenerator

public class FeedableBodyGenerator
extends Object
implements 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
static class FeedableBodyGenerator.BaseFeeder
          Base class for FeedableBodyGenerator.Feeder implementations.
static interface FeedableBodyGenerator.Feeder
          Specifies the functionality all Feeders must implement.
static class FeedableBodyGenerator.NonBlockingFeeder
          Implementations of this class provide the framework to read data from some source and feed data to the FeedableBodyGenerator without blocking.
static class FeedableBodyGenerator.SimpleFeeder
          This simple FeedableBodyGenerator.Feeder implementation allows the implementation to feed data in whatever fashion is deemed appropriate.
 
Field Summary
static int DEFAULT
          Defer to whatever the connection has been configured for max pending bytes.
static int UNBOUND
          There is no limit on bytes waiting to be written.
 
Constructor Summary
FeedableBodyGenerator()
           
 
Method Summary
 Body createBody()
          Creates a new instance of the request body to be read.
 void setFeeder(FeedableBodyGenerator.Feeder feeder)
          Add a FeedableBodyGenerator.Feeder implementation that will be invoked when writing without blocking is possible.
 void setMaxPendingBytes(int maxPendingBytes)
          Configured the maximum number of bytes that may be pending to be written to the wire.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNBOUND

public static final int UNBOUND
There 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:
Constant Field Values

DEFAULT

public static final int DEFAULT
Defer to whatever the connection has been configured for max pending bytes.

See Also:
Constant Field Values
Constructor Detail

FeedableBodyGenerator

public FeedableBodyGenerator()
Method Detail

createBody

public Body createBody()
                throws IOException
Creates 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:
createBody in interface BodyGenerator
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 after initializeAsynchronousTransfer(FilterChainContext, HttpRequestPacket) has been called by the GrizzlyAsyncHttpProvider.
IllegalArgumentException - if maxPendingBytes is less than zero and is not UNBOUND or DEFAULT.

setFeeder

public void setFeeder(FeedableBodyGenerator.Feeder feeder)
Add a FeedableBodyGenerator.Feeder implementation 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 - the FeedableBodyGenerator.Feeder responsible for providing data.
Throws:
IllegalStateException - if called after initializeAsynchronousTransfer(FilterChainContext, HttpRequestPacket) has been called by the GrizzlyAsyncHttpProvider.
IllegalArgumentException - if feeder is null


Copyright © 2014. All Rights Reserved.