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  package org.apache.http.impl.pool;
28  
29  import java.util.concurrent.atomic.AtomicLong;
30  
31  import org.apache.http.HttpClientConnection;
32  import org.apache.http.HttpHost;
33  import org.apache.http.annotation.ThreadSafe;
34  import org.apache.http.config.ConnectionConfig;
35  import org.apache.http.config.SocketConfig;
36  import org.apache.http.params.HttpParams;
37  import org.apache.http.pool.AbstractConnPool;
38  import org.apache.http.pool.ConnFactory;
39  
40  /**
41   * A very basic {@link org.apache.http.pool.ConnPool} implementation that
42   * represents a pool of blocking {@link HttpClientConnection} connections
43   * identified by an {@link HttpHost} instance. Please note this pool
44   * implementation does not support complex routes via a proxy cannot
45   * differentiate between direct and proxied connections.
46   *
47   * @see HttpHost
48   * @since 4.2
49   */
50  @SuppressWarnings("deprecation")
51  @ThreadSafe
52  public class BasicConnPool extends AbstractConnPool<HttpHost, HttpClientConnection, BasicPoolEntry> {
53  
54      private static final AtomicLong COUNTER = new AtomicLong();
55  
56      public BasicConnPool(final ConnFactory<HttpHost, HttpClientConnection> connFactory) {
57          super(connFactory, 2, 20);
58      }
59  
60      /**
61       * @deprecated (4.3) use {@link BasicConnPool#BasicConnPool(SocketConfig, ConnectionConfig)}
62       */
63      @Deprecated
64      public BasicConnPool(final HttpParams params) {
65          super(new BasicConnFactory(params), 2, 20);
66      }
67  
68      /**
69       * @since 4.3
70       */
71      public BasicConnPool(final SocketConfig sconfig, final ConnectionConfig cconfig) {
72          super(new BasicConnFactory(sconfig, cconfig), 2, 20);
73      }
74  
75      /**
76       * @since 4.3
77       */
78      public BasicConnPool() {
79          super(new BasicConnFactory(SocketConfig.DEFAULT, ConnectionConfig.DEFAULT), 2, 20);
80      }
81  
82      @Override
83      protected BasicPoolEntry createEntry(
84              final HttpHost host,
85              final HttpClientConnection conn) {
86          return new BasicPoolEntry(Long.toString(COUNTER.getAndIncrement()), host, conn);
87      }
88  
89  }