michael@0: /* michael@0: * ==================================================================== michael@0: * Licensed to the Apache Software Foundation (ASF) under one michael@0: * or more contributor license agreements. See the NOTICE file michael@0: * distributed with this work for additional information michael@0: * regarding copyright ownership. The ASF licenses this file michael@0: * to you under the Apache License, Version 2.0 (the michael@0: * "License"); you may not use this file except in compliance michael@0: * with the License. You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, michael@0: * software distributed under the License is distributed on an michael@0: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY michael@0: * KIND, either express or implied. See the License for the michael@0: * specific language governing permissions and limitations michael@0: * under the License. michael@0: * ==================================================================== michael@0: * michael@0: * This software consists of voluntary contributions made by many michael@0: * individuals on behalf of the Apache Software Foundation. For more michael@0: * information on the Apache Software Foundation, please see michael@0: * . michael@0: * michael@0: */ michael@0: michael@0: package ch.boye.httpclientandroidlib.conn; michael@0: michael@0: import java.util.concurrent.TimeUnit; michael@0: michael@0: import ch.boye.httpclientandroidlib.conn.routing.HttpRoute; michael@0: import ch.boye.httpclientandroidlib.conn.scheme.SchemeRegistry; michael@0: michael@0: /** michael@0: * Management interface for {@link ManagedClientConnection client connections}. michael@0: * The purpose of an HTTP connection manager is to serve as a factory for new michael@0: * HTTP connections, manage persistent connections and synchronize access to michael@0: * persistent connections making sure that only one thread of execution can michael@0: * have access to a connection at a time. michael@0: *

michael@0: * Implementations of this interface must be thread-safe. Access to shared michael@0: * data must be synchronized as methods of this interface may be executed michael@0: * from multiple threads. michael@0: * michael@0: * @since 4.0 michael@0: */ michael@0: public interface ClientConnectionManager { michael@0: michael@0: /** michael@0: * Obtains the scheme registry used by this manager. michael@0: * michael@0: * @return the scheme registry, never null michael@0: */ michael@0: SchemeRegistry getSchemeRegistry(); michael@0: michael@0: /** michael@0: * Returns a new {@link ClientConnectionRequest}, from which a michael@0: * {@link ManagedClientConnection} can be obtained or the request can be michael@0: * aborted. michael@0: */ michael@0: ClientConnectionRequest requestConnection(HttpRoute route, Object state); michael@0: michael@0: /** michael@0: * Releases a connection for use by others. michael@0: * You may optionally specify how long the connection is valid michael@0: * to be reused. Values <= 0 are considered to be valid forever. michael@0: * If the connection is not marked as reusable, the connection will michael@0: * not be reused regardless of the valid duration. michael@0: * michael@0: * If the connection has been released before, michael@0: * the call will be ignored. michael@0: * michael@0: * @param conn the connection to release michael@0: * @param validDuration the duration of time this connection is valid for reuse michael@0: * @param timeUnit the unit of time validDuration is measured in michael@0: * michael@0: * @see #closeExpiredConnections() michael@0: */ michael@0: void releaseConnection(ManagedClientConnection conn, long validDuration, TimeUnit timeUnit); michael@0: michael@0: /** michael@0: * Closes idle connections in the pool. michael@0: * Open connections in the pool that have not been used for the michael@0: * timespan given by the argument will be closed. michael@0: * Currently allocated connections are not subject to this method. michael@0: * Times will be checked with milliseconds precision michael@0: * michael@0: * All expired connections will also be closed. michael@0: * michael@0: * @param idletime the idle time of connections to be closed michael@0: * @param tunit the unit for the idletime michael@0: * michael@0: * @see #closeExpiredConnections() michael@0: */ michael@0: void closeIdleConnections(long idletime, TimeUnit tunit); michael@0: michael@0: /** michael@0: * Closes all expired connections in the pool. michael@0: * Open connections in the pool that have not been used for michael@0: * the timespan defined when the connection was released will be closed. michael@0: * Currently allocated connections are not subject to this method. michael@0: * Times will be checked with milliseconds precision. michael@0: */ michael@0: void closeExpiredConnections(); michael@0: michael@0: /** michael@0: * Shuts down this connection manager and releases allocated resources. michael@0: * This includes closing all connections, whether they are currently michael@0: * used or not. michael@0: */ michael@0: void shutdown(); michael@0: michael@0: }