• BlackBerry Dynamics
  • Runtime library for Android applications
  • 12.0.1.79
SingleClientConnManager Class Reference

A connection "manager" for a single connection. More...

Inheritance diagram for SingleClientConnManager:
ClientConnectionManager

Description

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.

Author
Roland Weber
Michael Becke
Version
Revision
673450
Since
4.0

Notice

The following notice applies to the original API on which this API is based, and to its documentation. The documentation of this API has been revised from the original.

/*
 * Copyright (C) 2006 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

Classes

class  ConnAdapter
 The connection adapter used by this manager. More...
 
class  PoolEntry
 The pool entry for this connection manager. More...
 

Public Member Functions

 SingleClientConnManager (HttpParams params, SchemeRegistry schreg)
 Creates a new simple connection manager. More...
 
SchemeRegistry getSchemeRegistry ()
 Obtains the scheme registry used by this manager. More...
 
final ClientConnectionRequest requestConnection (final HttpRoute route, final Object state)
 Returns a new com.good.gd.apache.http.conn.ClientConnectionRequest, from which a com.good.gd.apache.http.conn.ManagedClientConnection can be obtained or the request can be aborted.
 
ManagedClientConnection getConnection (HttpRoute route, Object state)
 Obtains a connection. More...
 
void releaseConnection (ManagedClientConnection conn, long validDuration, TimeUnit timeUnit)
 Releases a connection for use by others. More...
 
void closeExpiredConnections ()
 Closes all expired connections in the pool. More...
 
void closeIdleConnections (long idletime, TimeUnit tunit)
 Closes idle connections in the pool. More...
 
void shutdown ()
 Shuts down this connection manager and releases allocated resources. More...
 

Static Public Attributes

static final String MISUSE_MESSAGE
 The message to be logged on multiple allocation. More...
 

Protected Member Functions

ClientConnectionOperator createConnectionOperator (SchemeRegistry schreg)
 Hook for creating the connection operator. More...
 
final void assertStillUp () throws IllegalStateException
 Asserts that this manager is not shut down. More...
 
void revokeConnection ()
 Revokes the currently issued connection. More...
 

Protected Attributes

SchemeRegistry schemeRegistry
 The schemes supported by this connection manager. More...
 
ClientConnectionOperator connOperator
 The operator for opening and updating connections. More...
 
PoolEntry uniquePoolEntry
 The one and only entry in this pool. More...
 
ConnAdapter managedConn
 The currently issued managed connection, if any. More...
 
long lastReleaseTime
 The time of the last connection release, or -1. More...
 
long connectionExpiresTime
 The time the last released connection expires and shouldn't be reused. More...
 
boolean alwaysShutDown
 Whether the connection should be shut down on release. More...
 
volatile boolean isShutDown
 Indicates whether this connection manager is shut down. More...
 

Constructor & Destructor Documentation

◆ SingleClientConnManager()

Parameters
paramsthe parameters for this manager
schregthe scheme registry

Member Function Documentation

◆ getSchemeRegistry()

SchemeRegistry getSchemeRegistry ( )
Returns
the scheme registry, never null

Implements ClientConnectionManager.

◆ createConnectionOperator()

ClientConnectionOperator createConnectionOperator ( SchemeRegistry  schreg)
protected

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
schregthe scheme registry to use, or null
Returns
the connection operator to use

◆ assertStillUp()

final void assertStillUp ( ) throws IllegalStateException
protected
Exceptions
IllegalStateExceptionif this manager is shut down

◆ getConnection()

ManagedClientConnection getConnection ( HttpRoute  route,
Object  state 
)

This method does not block.

Parameters
routewhere the connection should point to
state
Returns
a connection that can be used to communicate along the given route

◆ releaseConnection()

void releaseConnection ( ManagedClientConnection  conn,
long  validDuration,
TimeUnit  timeUnit 
)

You may optionally specify how long the connection is valid to be reused. Values <= 0 are considered to be valid forever. If the connection is not marked as reusable, the connection will not be reused regardless of the valid duration.

If the connection has been released before, the call will be ignored.

Parameters
connthe connection to release
validDurationthe duration of time this connection is valid for reuse
timeUnitthe unit of time validDuration is measured in
See also
closeExpiredConnections()

Implements ClientConnectionManager.

◆ closeExpiredConnections()

void closeExpiredConnections ( )

Open connections in the pool that have not been used for the timespan defined when the connection was released will be closed. Currently allocated connections are not subject to this method. Times will be checked with milliseconds precision.

Implements ClientConnectionManager.

◆ closeIdleConnections()

void closeIdleConnections ( long  idletime,
TimeUnit  tunit 
)

Open connections in the pool that have not been used for the timespan given by the argument will be closed. Currently allocated connections are not subject to this method. Times will be checked with milliseconds precision

All expired connections will also be closed.

Parameters
idletimethe idle time of connections to be closed
tunitthe unit for the idletime
See also
closeExpiredConnections()

Implements ClientConnectionManager.

◆ shutdown()

void shutdown ( )

This includes closing all connections, whether they are currently used or not.

Implements ClientConnectionManager.

◆ revokeConnection()

void revokeConnection ( )
protected

The adapter gets disconnected, the connection will be shut down.

Member Data Documentation

◆ MISUSE_MESSAGE

final String MISUSE_MESSAGE
static
Initial value:
=
"Invalid use of SingleClientConnManager: connection still allocated.\n" +
"Make sure to release the connection before allocating another one."

◆ schemeRegistry

SchemeRegistry schemeRegistry
protected

◆ connOperator

ClientConnectionOperator connOperator
protected

◆ uniquePoolEntry

PoolEntry uniquePoolEntry
protected

◆ managedConn

ConnAdapter managedConn
protected

◆ lastReleaseTime

long lastReleaseTime
protected

◆ connectionExpiresTime

long connectionExpiresTime
protected

◆ alwaysShutDown

boolean alwaysShutDown
protected

◆ isShutDown

volatile boolean isShutDown
protected