FileDocCategorySizeDatePackage
BasicManagedEntity.javaAPI DocAndroid 1.5 API6553Wed May 06 22:41:10 BST 2009org.apache.http.conn

BasicManagedEntity

public class BasicManagedEntity extends HttpEntityWrapper implements EofSensorWatcher, ConnectionReleaseTrigger
An entity that releases a {@link ManagedClientConnection connection}. A {@link ManagedClientConnection} will typically not return a managed entity, but you can replace the unmanaged entity in the response with a managed one.
author
Roland Weber
version
$Revision: 672367 $
since
4.0

Fields Summary
protected ManagedClientConnection
managedConn
The connection to release.
protected final boolean
attemptReuse
Whether to keep the connection alive.
Constructors Summary
public BasicManagedEntity(HttpEntity entity, ManagedClientConnection conn, boolean reuse)
Creates a new managed entity that can release a connection.

param
entity the entity of which to wrap the content. Note that the argument entity can no longer be used afterwards, since the content will be taken by this managed entity.
param
conn the connection to release
param
reuse whether the connection should be re-used

        super(entity);

        if (conn == null)
            throw new IllegalArgumentException
                ("Connection may not be null.");

        this.managedConn = conn;
        this.attemptReuse = reuse;
    
Methods Summary
public voidabortConnection()


        if (managedConn != null) {
            try {
                managedConn.abortConnection();
            } finally {
                managedConn = null;
            }
        }
    
public voidconsumeContent()


        if (managedConn == null)
            return;

        try {
            if (attemptReuse) {
                // this will not trigger a callback from EofSensorInputStream
                wrappedEntity.consumeContent();
                managedConn.markReusable();
            }
        } finally {
            releaseManagedConnection();
        }
    
public booleaneofDetected(java.io.InputStream wrapped)


        try {
            if (attemptReuse && (managedConn != null)) {
                // there may be some cleanup required, such as
                // reading trailers after the response body:
                wrapped.close();
                managedConn.markReusable();
            }
        } finally {
            releaseManagedConnection();
        }
        return false;
    
public java.io.InputStreamgetContent()


        return new EofSensorInputStream(wrappedEntity.getContent(), this);
    
public booleanisRepeatable()

        return false;
    
public voidreleaseConnection()


        this.consumeContent();
    
protected voidreleaseManagedConnection()
Releases the connection gracefully. The connection attribute will be nullified. Subsequent invocations are no-ops.

throws
IOException in case of an IO problem. The connection attribute will be nullified anyway.


        if (managedConn != null) {
            try {
                managedConn.releaseConnection();
            } finally {
                managedConn = null;
            }
        }
    
public booleanstreamAbort(java.io.InputStream wrapped)


        if (managedConn != null) {
            managedConn.abortConnection();
        }
        return false;
    
public booleanstreamClosed(java.io.InputStream wrapped)


        try {
            if (attemptReuse && (managedConn != null)) {
                // this assumes that closing the stream will
                // consume the remainder of the response body:
                wrapped.close();
                managedConn.markReusable();
            }
        } finally {
            releaseManagedConnection();
        }
        return false;
    
public voidwriteTo(java.io.OutputStream outstream)

        super.writeTo(outstream);
        consumeContent();