001/* 002 * ==================================================================== 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, 014 * software distributed under the License is distributed on an 015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 016 * KIND, either express or implied. See the License for the 017 * specific language governing permissions and limitations 018 * under the License. 019 * ==================================================================== 020 * 021 * This software consists of voluntary contributions made by many 022 * individuals on behalf of the Apache Software Foundation. For more 023 * information on the Apache Software Foundation, please see 024 * <http://www.apache.org/>. 025 * 026 */ 027package org.apache.http.pool; 028 029import java.util.concurrent.Future; 030 031import org.apache.http.concurrent.FutureCallback; 032 033/** 034 * {@code ConnPool} represents a shared pool connections can be leased from 035 * and released back to. 036 * 037 * @param <T> the route type that represents the opposite endpoint of a pooled 038 * connection. 039 * @param <E> the type of the pool entry containing a pooled connection. 040 * @since 4.2 041 */ 042public interface ConnPool<T, E> { 043 044 /** 045 * Attempts to lease a connection for the given route and with the given 046 * state from the pool. 047 * 048 * @param route route of the connection. 049 * @param state arbitrary object that represents a particular state 050 * (usually a security principal or a unique token identifying 051 * the user whose credentials have been used while establishing the connection). 052 * May be {@code null}. 053 * @param callback operation completion callback. 054 * 055 * @return future for a leased pool entry. 056 */ 057 Future<E> lease(final T route, final Object state, final FutureCallback<E> callback); 058 059 /** 060 * Releases the pool entry back to the pool. 061 * 062 * @param entry pool entry leased from the pool 063 * @param reusable flag indicating whether or not the released connection 064 * is in a consistent state and is safe for further use. 065 */ 066 void release(E entry, boolean reusable); 067 068}