View Javadoc

1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package org.apache.http.conn;
29  
30  import java.util.concurrent.TimeUnit;
31  
32  import org.apache.http.conn.routing.HttpRoute;
33  import org.apache.http.conn.scheme.SchemeRegistry;
34  
35  /**
36   * Management interface for {@link ManagedClientConnection client connections}.
37   * The purpose of an HTTP connection manager is to serve as a factory for new
38   * HTTP connections, manage persistent connections and synchronize access to
39   * persistent connections making sure that only one thread of execution can
40   * have access to a connection at a time.
41   * <p>
42   * Implementations of this interface must be thread-safe. Access to shared
43   * data must be synchronized as methods of this interface may be executed
44   * from multiple threads.
45   *
46   * @since 4.0
47   */
48  public interface ClientConnectionManager {
49  
50      /**
51       * Obtains the scheme registry used by this manager.
52       *
53       * @return  the scheme registry, never <code>null</code>
54       */
55      SchemeRegistry getSchemeRegistry();
56  
57      /**
58       * Returns a new {@link ClientConnectionRequest}, from which a
59       * {@link ManagedClientConnection} can be obtained or the request can be
60       * aborted.
61       */
62      ClientConnectionRequest requestConnection(HttpRoute route, Object state);
63  
64      /**
65       * Releases a connection for use by others.
66       * You may optionally specify how long the connection is valid
67       * to be reused.  Values <= 0 are considered to be valid forever.
68       * If the connection is not marked as reusable, the connection will
69       * not be reused regardless of the valid duration.
70       *
71       * If the connection has been released before,
72       * the call will be ignored.
73       *
74       * @param conn      the connection to release
75       * @param validDuration the duration of time this connection is valid for reuse
76       * @param timeUnit the unit of time validDuration is measured in
77       *
78       * @see #closeExpiredConnections()
79       */
80      void releaseConnection(ManagedClientConnection conn, long validDuration, TimeUnit timeUnit);
81  
82      /**
83       * Closes idle connections in the pool.
84       * Open connections in the pool that have not been used for the
85       * timespan given by the argument will be closed.
86       * Currently allocated connections are not subject to this method.
87       * Times will be checked with milliseconds precision
88       *
89       * All expired connections will also be closed.
90       *
91       * @param idletime  the idle time of connections to be closed
92       * @param tunit     the unit for the <code>idletime</code>
93       *
94       * @see #closeExpiredConnections()
95       */
96      void closeIdleConnections(long idletime, TimeUnit tunit);
97  
98      /**
99       * Closes all expired connections in the pool.
100      * Open connections in the pool that have not been used for
101      * the timespan defined when the connection was released will be closed.
102      * Currently allocated connections are not subject to this method.
103      * Times will be checked with milliseconds precision.
104      */
105     void closeExpiredConnections();
106 
107     /**
108      * Shuts down this connection manager and releases allocated resources.
109      * This includes closing all connections, whether they are currently
110      * used or not.
111      */
112     void shutdown();
113 
114 }