Package org.apache.http.conn
Class BasicManagedEntity
java.lang.Object
org.apache.http.entity.HttpEntityWrapper
org.apache.http.conn.BasicManagedEntity
- All Implemented Interfaces:
ConnectionReleaseTrigger,EofSensorWatcher,HttpEntity
public class BasicManagedEntity extends HttpEntityWrapper implements ConnectionReleaseTrigger, EofSensorWatcher
An entity that releases a
connection.
A ManagedClientConnection will
typically not return a managed entity, but you can replace
the unmanaged entity in the response with a managed one.- Since:
- 4.0
- Version:
- $Revision: 672367 $
- Author:
- Roland Weber
-
Field Summary
Fields Modifier and Type Field Description protected booleanattemptReuseWhether to keep the connection alive.protected ManagedClientConnectionmanagedConnThe connection to release.Fields inherited from class org.apache.http.entity.HttpEntityWrapper
wrappedEntity -
Constructor Summary
Constructors Constructor Description BasicManagedEntity(HttpEntity entity, ManagedClientConnection conn, boolean reuse)Creates a new managed entity that can release a connection. -
Method Summary
Modifier and Type Method Description voidabortConnection()Releases the connection without the option of keep-alive.voidconsumeContent()TODO: The name of this method is misnomer.booleaneofDetected(InputStream wrapped)Indicates that EOF is detected.InputStreamgetContent()Creates a new InputStream object of the entity.booleanisRepeatable()Tells if the entity is capable to produce its data more than once.voidreleaseConnection()Releases the connection with the option of keep-alive.protected voidreleaseManagedConnection()Releases the connection gracefully.booleanstreamAbort(InputStream wrapped)Indicates that thestreamis aborted.booleanstreamClosed(InputStream wrapped)Indicates that thestreamis closed.voidwriteTo(OutputStream outstream)Writes the entity content to the output stream.Methods inherited from class org.apache.http.entity.HttpEntityWrapper
getContentEncoding, getContentLength, getContentType, isChunked, isStreaming
-
Field Details
-
managedConn
The connection to release. -
attemptReuse
protected final boolean attemptReuseWhether to keep the connection alive.
-
-
Constructor Details
-
BasicManagedEntity
Creates a new managed entity that can release a connection.- Parameters:
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.conn- the connection to releasereuse- whether the connection should be re-used
-
-
Method Details
-
isRepeatable
public boolean isRepeatable()Description copied from interface:HttpEntityTells if the entity is capable to produce its data more than once. A repeatable entity's getContent() and writeTo(OutputStream) methods can be called more than once whereas a non-repeatable entity's can not.- Specified by:
isRepeatablein interfaceHttpEntity- Overrides:
isRepeatablein classHttpEntityWrapper- Returns:
- true if the entity is repeatable, false otherwise.
-
getContent
Description copied from interface:HttpEntityCreates a new InputStream object of the entity. It is a programming error to return the same InputStream object more than once. Entities that are notrepeatablewill throw an exception if this method is called multiple times.- Specified by:
getContentin interfaceHttpEntity- Overrides:
getContentin classHttpEntityWrapper- Returns:
- a new input stream that returns the entity data.
- Throws:
IOException- if the stream could not be created
-
consumeContent
Description copied from interface:HttpEntityTODO: The name of this method is misnomer. It will be renamed to #finish() in the next major release.
This method is called to indicate that the content of this entity is no longer required. All entity implementations are expected to release all allocated resources as a result of this method invocation. Content streaming entities are also expected to dispose of the remaining content, if any. Wrapping entities should delegate this call to the wrapped entity.
This method is of particular importance for entities being received from aconnection. The entity needs to be consumed completely in order to re-use the connection with keep-alive.- Specified by:
consumeContentin interfaceHttpEntity- Overrides:
consumeContentin classHttpEntityWrapper- Throws:
IOException- if an I/O error occurs. This indicates that connection keep-alive is not possible.
-
writeTo
Description copied from interface:HttpEntityWrites the entity content to the output stream.- Specified by:
writeToin interfaceHttpEntity- Overrides:
writeToin classHttpEntityWrapper- Parameters:
outstream- the output stream to write entity content to- Throws:
IOException- if an I/O error occurs
-
releaseConnection
Description copied from interface:ConnectionReleaseTriggerReleases the connection with the option of keep-alive. This is a "graceful" release and may cause IO operations for consuming the remainder of a response entity. UseabortConnectionfor a hard release. The connection may be reused as specified by the duration.- Specified by:
releaseConnectionin interfaceConnectionReleaseTrigger- Throws:
IOException- in case of an IO problem. The connection will be released anyway.
-
abortConnection
Description copied from interface:ConnectionReleaseTriggerReleases the connection without the option of keep-alive. This is a "hard" release that implies a shutdown of the connection. UsereleaseConnectionfor a graceful release.- Specified by:
abortConnectionin interfaceConnectionReleaseTrigger- Throws:
IOException- in case of an IO problem. The connection will be released anyway.
-
eofDetected
Description copied from interface:EofSensorWatcherIndicates that EOF is detected.- Specified by:
eofDetectedin interfaceEofSensorWatcher- Parameters:
wrapped- the underlying stream which has reached EOF- Returns:
trueifwrappedshould be closed,falseif it should be left alone- Throws:
IOException- in case of an IO problem, for example if the watcher itself closes the underlying stream. The caller will leave the wrapped stream alone, as iffalsewas returned.
-
streamClosed
Description copied from interface:EofSensorWatcherIndicates that thestreamis closed. This method will be called only if EOF was not detected before closing. Otherwise,eofDetectedis called.- Specified by:
streamClosedin interfaceEofSensorWatcher- Parameters:
wrapped- the underlying stream which has not reached EOF- Returns:
trueifwrappedshould be closed,falseif it should be left alone- Throws:
IOException- in case of an IO problem, for example if the watcher itself closes the underlying stream. The caller will leave the wrapped stream alone, as iffalsewas returned.
-
streamAbort
Description copied from interface:EofSensorWatcherIndicates that thestreamis aborted. This method will be called only if EOF was not detected before aborting. Otherwise,eofDetectedis called. This method will also be invoked when an input operation causes an IOException to be thrown to make sure the input stream gets shut down.- Specified by:
streamAbortin interfaceEofSensorWatcher- Parameters:
wrapped- the underlying stream which has not reached EOF- Returns:
trueifwrappedshould be closed,falseif it should be left alone- Throws:
IOException- in case of an IO problem, for example if the watcher itself closes the underlying stream. The caller will leave the wrapped stream alone, as iffalsewas returned.
-
releaseManagedConnection
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.
-