org.apache.http.impl.conn
Class SingleClientConnManager

java.lang.Object
  extended by org.apache.http.impl.conn.SingleClientConnManager
All Implemented Interfaces:
ClientConnectionManager

public class SingleClientConnManager
extends java.lang.Object
implements ClientConnectionManager

A connection "manager" for a single connection. This manager is good only for single-threaded use. Allocation always returns the connection immediately, even if it has not been released after the previous allocation. In that case, a warning is logged and the previously issued connection is revoked.

This class is derived from SimpleHttpConnectionManager in HttpClient 3. See there for original authors.

Since:
4.0
Version:
$Revision: 561041 $
Author:
Roland Weber, Michael Becke

Nested Class Summary
protected  class SingleClientConnManager.ConnAdapter
          The connection adapter used by this manager.
protected  class SingleClientConnManager.PoolEntry
          The pool entry for this connection manager.
 
Field Summary
protected  boolean alwaysShutDown
          Whether the connection should be shut down on release.
protected  ClientConnectionOperator connOperator
          The operator for opening and updating connections.
protected  boolean isShutDown
          Indicates whether this connection manager is shut down.
protected  long lastReleaseTime
          The time of the last connection release, or -1.
protected  SingleClientConnManager.ConnAdapter managedConn
          The currently issued managed connection, if any.
static java.lang.String MISUSE_MESSAGE
          The message to be logged on multiple allocation.
protected  org.apache.http.params.HttpParams params
          The parameters of this connection manager.
protected  SchemeRegistry schemeRegistry
          The schemes supported by this connection manager.
protected  SingleClientConnManager.PoolEntry uniquePoolEntry
          The one and only entry in this pool.
 
Constructor Summary
SingleClientConnManager(org.apache.http.params.HttpParams params, SchemeRegistry schreg)
          Creates a new simple connection manager.
 
Method Summary
protected  void assertStillUp()
          Asserts that this manager is not shut down.
 void closeIdleConnections(long idletime)
          Closes idle connections in the pool.
protected  ClientConnectionOperator createConnectionOperator(SchemeRegistry schreg)
          Hook for creating the connection operator.
 ManagedClientConnection getConnection(HttpRoute route)
          Obtains a connection.
 ManagedClientConnection getConnection(HttpRoute route, long timeout)
          Obtains a connection.
 org.apache.http.params.HttpParams getParams()
          Obtains the parameters of this manager.
 SchemeRegistry getSchemeRegistry()
          Obtains the scheme registry used by this manager.
 void releaseConnection(ManagedClientConnection conn)
          Releases a connection for use by others.
protected  void revokeConnection()
          Revokes the currently issued connection.
 void shutdown()
          Shuts down this connection manager and releases allocated resources.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MISUSE_MESSAGE

public static final java.lang.String MISUSE_MESSAGE
The message to be logged on multiple allocation.

See Also:
Constant Field Values

schemeRegistry

protected SchemeRegistry schemeRegistry
The schemes supported by this connection manager.


params

protected org.apache.http.params.HttpParams params
The parameters of this connection manager.


connOperator

protected ClientConnectionOperator connOperator
The operator for opening and updating connections.


uniquePoolEntry

protected SingleClientConnManager.PoolEntry uniquePoolEntry
The one and only entry in this pool.


managedConn

protected SingleClientConnManager.ConnAdapter managedConn
The currently issued managed connection, if any.


lastReleaseTime

protected long lastReleaseTime
The time of the last connection release, or -1.


alwaysShutDown

protected boolean alwaysShutDown
Whether the connection should be shut down on release.


isShutDown

protected volatile boolean isShutDown
Indicates whether this connection manager is shut down.

Constructor Detail

SingleClientConnManager

public SingleClientConnManager(org.apache.http.params.HttpParams params,
                               SchemeRegistry schreg)
Creates a new simple connection manager.

Parameters:
params - the parameters for this manager
schreg - the scheme registry, or null for the default registry
Method Detail

getParams

public org.apache.http.params.HttpParams getParams()
Description copied from interface: ClientConnectionManager
Obtains the parameters of this manager.

Specified by:
getParams in interface ClientConnectionManager
Returns:
the parameters, never null

getSchemeRegistry

public SchemeRegistry getSchemeRegistry()
Description copied from interface: ClientConnectionManager
Obtains the scheme registry used by this manager.

Specified by:
getSchemeRegistry in interface ClientConnectionManager
Returns:
the scheme registry, never null

createConnectionOperator

protected ClientConnectionOperator createConnectionOperator(SchemeRegistry schreg)
Hook for creating the connection operator. It is called by the constructor. Derived classes can override this method to change the instantiation of the operator. The default implementation here instantiates DefaultClientConnectionOperator.

Parameters:
schreg - the scheme registry to use, or null
Returns:
the connection operator to use

assertStillUp

protected final void assertStillUp()
                            throws java.lang.IllegalStateException
Asserts that this manager is not shut down.

Throws:
java.lang.IllegalStateException - if this manager is shut down

getConnection

public final ManagedClientConnection getConnection(HttpRoute route,
                                                   long timeout)
Obtains a connection. Maps to getConnection(HttpRoute) since this manager never blocks the caller.

Specified by:
getConnection in interface ClientConnectionManager
Parameters:
route - where the connection should point to
timeout - ignored
Returns:
a connection that can be used to communicate along the given route

getConnection

public ManagedClientConnection getConnection(HttpRoute route)
Obtains a connection. This method does not block.

Specified by:
getConnection in interface ClientConnectionManager
Parameters:
route - where the connection should point to
Returns:
a connection that can be used to communicate along the given route

releaseConnection

public void releaseConnection(ManagedClientConnection conn)
Description copied from interface: ClientConnectionManager
Releases a connection for use by others. If the argument connection has been released before, the call will be ignored.

Specified by:
releaseConnection in interface ClientConnectionManager
Parameters:
conn - the connection to release

closeIdleConnections

public void closeIdleConnections(long idletime)
Description copied from interface: ClientConnectionManager
Closes idle connections in the pool. Open connections in the pool that have not been used for the timespan given by the timeout argument will be closed. Currently allocated connections are not subject to this method.

Specified by:
closeIdleConnections in interface ClientConnectionManager
Parameters:
idletime - the idle time in milliseconds

shutdown

public void shutdown()
Description copied from interface: ClientConnectionManager
Shuts down this connection manager and releases allocated resources. This includes closing all connections, whether they are currently used or not.

Specified by:
shutdown in interface ClientConnectionManager

revokeConnection

protected void revokeConnection()
Revokes the currently issued connection. The adapter gets disconnected, the connection will be shut down.



Copyright © 2000-2007 Apache Software Foundation. All Rights Reserved.