• BlackBerry Dynamics
  • Runtime library for Android applications
  • 12.0.1.79
AbstractClientConnAdapter Class Referenceabstract

Abstract adapter from operated to managed client connections. More...

Inheritance diagram for AbstractClientConnAdapter:
ManagedClientConnection HttpClientConnection HttpInetConnection ConnectionReleaseTrigger HttpConnection HttpConnection AbstractPooledConnAdapter SingleClientConnManager.ConnAdapter BasicPooledConnAdapter

Description

Read and write methods are delegated to the wrapped connection. Operations affecting the connection state have to be implemented by derived classes. Operations for querying the connection state are delegated to the wrapped connection if there is one, or return a default value if there is none.
This adapter tracks the checkpoints for reusable communication states, as indicated by markReusable and queried by isMarkedReusable . All send and receive operations will automatically clear the mark.
Connection release calls are delegated to the connection manager, if there is one. abortConnection will clear the reusability mark first. The connection manager is expected to tolerate multiple calls to the release method.

Author
Roland Weber
Version
Revision
672969
Date
2008-06-30 18:09:50 -0700 (Mon, 30 Jun 2008)
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.
 */

Public Member Functions

boolean isOpen ()
 Checks if this connection is open. More...
 
boolean isStale ()
 Checks whether this connection has gone down. More...
 
void setSocketTimeout (int timeout)
 Sets the socket timeout value. More...
 
int getSocketTimeout ()
 Returns the socket timeout value. More...
 
HttpConnectionMetrics getMetrics ()
 Returns a collection of connection metrcis. More...
 
void flush () throws IOException
 Writes out all pending buffered data over the open connection. More...
 
boolean isResponseAvailable (int timeout) throws IOException
 Checks if response data is available from the connection. More...
 
void receiveResponseEntity (HttpResponse response) throws HttpException, IOException
 Receives the next response entity available from this connection and attaches it to an existing HttpResponse object. More...
 
HttpResponse receiveResponseHeader () throws HttpException, IOException
 Receives the request line and headers of the next response available from this connection. More...
 
void sendRequestEntity (HttpEntityEnclosingRequest request) throws HttpException, IOException
 Sends the request entity over the connection. More...
 
void sendRequestHeader (HttpRequest request) throws HttpException, IOException
 Sends the request line and all headers over the connection. More...
 
boolean isSecure ()
 Indicates whether this connection is secure. More...
 
SSLSession getSSLSession ()
 Obtains the SSL session of the underlying connection, if any. More...
 
void markReusable ()
 Marks this connection as being in a reusable communication state. More...
 
void unmarkReusable ()
 Marks this connection as not being in a reusable state. More...
 
boolean isMarkedReusable ()
 Indicates whether this connection is in a reusable communication state. More...
 
void setIdleDuration (long duration, TimeUnit unit)
 Sets the duration that this connection can remain idle before it is reused. More...
 
void releaseConnection ()
 Releases the connection with the option of keep-alive. More...
 
void abortConnection ()
 Releases the connection without the option of keep-alive. More...
 
- Public Member Functions inherited from ManagedClientConnection
HttpRoute getRoute ()
 Obtains the current route of this connection. More...
 
void open (HttpRoute route, HttpContext context, HttpParams params) throws IOException
 Opens this connection according to the given route. More...
 
void tunnelTarget (boolean secure, HttpParams params) throws IOException
 Indicates that a tunnel to the target has been established. More...
 
void tunnelProxy (HttpHost next, boolean secure, HttpParams params) throws IOException
 Indicates that a tunnel to an intermediate proxy has been established. More...
 
void layerProtocol (HttpContext context, HttpParams params) throws IOException
 Layers a new protocol on top of a tunnelled connection. More...
 
void setState (Object state)
 Assigns a state object to this connection. More...
 
Object getState ()
 Returns the state object associated with this connection. More...
 
- Public Member Functions inherited from HttpConnection
void close () throws IOException
 Closes this connection gracefully. More...
 
void shutdown () throws IOException
 Force-closes this connection. More...
 

Protected Member Functions

 AbstractClientConnAdapter (ClientConnectionManager mgr, OperatedClientConnection conn)
 Creates a new connection adapter. More...
 
void detach ()
 Detaches this adapter from the wrapped connection. More...
 
final void assertNotAborted () throws InterruptedIOException
 Asserts that the connection has not been aborted. More...
 
final void assertValid (final OperatedClientConnection wrappedConn)
 Asserts that there is a wrapped connection to delegate to. More...
 

Constructor & Destructor Documentation

◆ AbstractClientConnAdapter()

The adapter is initially not marked as reusable.

Parameters
mgrthe connection manager, or null
connthe connection to wrap, or null

Member Function Documentation

◆ detach()

void detach ( )
protected

This adapter becomes useless.

Reimplemented in AbstractPooledConnAdapter, and BasicPooledConnAdapter.

◆ assertNotAborted()

final void assertNotAborted ( ) throws InterruptedIOException
protected
Exceptions
InterruptedIOExceptionif the connection has been aborted

◆ assertValid()

final void assertValid ( final OperatedClientConnection  wrappedConn)
protected
Exceptions
IllegalStateExceptionif there is no wrapped connection or connection has been aborted

◆ isOpen()

boolean isOpen ( )
Returns
true if it is open, false if it is closed.

Implements HttpConnection.

◆ isStale()

boolean isStale ( )

Network connections may get closed during some time of inactivity for several reasons. The next time a read is attempted on such a connection it will throw an IOException. This method tries to alleviate this inconvenience by trying to find out if a connection is still usable. Implementations may do that by attempting a read with a very small timeout. Thus this method may block for a small amount of time before returning a result. It is therefore an expensive operation.

Returns
true if attempts to use this connection are likely to succeed, or false if they are likely to fail and this connection should be closed

Implements HttpConnection.

◆ setSocketTimeout()

void setSocketTimeout ( int  timeout)
Parameters
timeouttimeout value in milliseconds

Implements HttpConnection.

◆ getSocketTimeout()

int getSocketTimeout ( )
Returns
positive value in milliseconds if a timeout is set, 0 if timeout is disabled or -1 if timeout is undefined.

Implements HttpConnection.

◆ getMetrics()

HttpConnectionMetrics getMetrics ( )

◆ flush()

void flush ( ) throws IOException
Exceptions
IOException

Implements HttpClientConnection.

◆ isResponseAvailable()

boolean isResponseAvailable ( int  timeout) throws IOException

May wait for the specified time until some data becomes available. Note that some implementations may completely ignore the timeout parameter.

Parameters
timeoutthe maximum time in milliseconds to wait for data
Returns
true if data is available; false if there was no data available even after waiting for timeout milliseconds.
Exceptions
IOExceptionif an error happens on the connection

Implements HttpClientConnection.

◆ receiveResponseEntity()

void receiveResponseEntity ( HttpResponse  response) throws HttpException, IOException
Parameters
responsethe response to attach the entity to
Exceptions
HttpException
IOException

Implements HttpClientConnection.

◆ receiveResponseHeader()

HttpResponse receiveResponseHeader ( ) throws HttpException, IOException

The caller should examine the HttpResponse object to find out if it should try to receive a response entity as well.

Returns
a new HttpResponse object with status line and headers initialized.
Exceptions
HttpException
IOException

Implements HttpClientConnection.

◆ sendRequestEntity()

void sendRequestEntity ( HttpEntityEnclosingRequest  request) throws HttpException, IOException
Parameters
requestthe request whose entity to send.
Exceptions
HttpException
IOException

Implements HttpClientConnection.

◆ sendRequestHeader()

void sendRequestHeader ( HttpRequest  request) throws HttpException, IOException
Parameters
requestthe request whose headers to send.
Exceptions
HttpException
IOException

Implements HttpClientConnection.

◆ isSecure()

boolean isSecure ( )

The return value is well-defined only while the connection is open. It may change even while the connection is open.

Returns
true if this connection is secure, false otherwise

Implements ManagedClientConnection.

◆ getSSLSession()

SSLSession getSSLSession ( )

If this connection is open, and the underlying socket is an javax.net.ssl.SSLSocket, the SSL session of that socket is obtained. This is a potentially blocking operation.
Note: Whether the underlying socket is an SSL socket can not necessarily be determined via isSecure. Plain sockets may be considered secure, for example if they are connected to a known host in the same network segment. On the other hand, SSL sockets may be considered insecure, for example depending on the chosen cipher suite.

Returns
the underlying SSL session if available, null otherwise

Implements ManagedClientConnection.

◆ markReusable()

void markReusable ( )

The checkpoints for reuseable communication states (in the absence of pipelining) are before sending a request and after receiving the response in it's entirety. The connection will automatically clear the checkpoint when used for communication. A call to this method indicates that the next checkpoint has been reached.
A reusable communication state is necessary but not sufficient for the connection to be reused. A route mismatch, the connection being closed, or other circumstances might prevent reuse.

Implements ManagedClientConnection.

◆ unmarkReusable()

void unmarkReusable ( )

This can be used immediately before releasing this connection to prevent it's reuse. Reasons for preventing reuse include error conditions and the evaluation of a reuse strategy .
Note: It is not necessary to call here before writing to or reading from this connection. Communication attempts will automatically unmark the state as non-reusable. It can then be switched back using markReusable .

Implements ManagedClientConnection.

◆ isMarkedReusable()

boolean isMarkedReusable ( )

See markReusable and unmarkReusable for details.

Returns
true if this connection is marked as being in a reusable communication state, false otherwise

Implements ManagedClientConnection.

◆ setIdleDuration()

void setIdleDuration ( long  duration,
TimeUnit  unit 
)

The connection should not be used again if this time elapses. The idle duration must be reset after each request sent over this connection. The elapsed time starts counting when the connection is released, which is typically after the headers (and any response body, if present) is fully consumed.

Implements ManagedClientConnection.

◆ releaseConnection()

void releaseConnection ( )

This is a "graceful" release and may cause IO operations for consuming the remainder of a response entity. Use abortConnection for a hard release. The connection may be reused as specified by the duration.

Exceptions
IOExceptionin case of an IO problem. The connection will be released anyway.

Implements ConnectionReleaseTrigger.

◆ abortConnection()

void abortConnection ( )

This is a "hard" release that implies a shutdown of the connection. Use releaseConnection for a graceful release.

Exceptions
IOExceptionin case of an IO problem. The connection will be released anyway.

Implements ConnectionReleaseTrigger.