1 /* 2 * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/AbstractPooledConnAdapter.java $ 3 * $Revision: 658775 $ 4 * $Date: 2008-05-21 10:30:45 -0700 (Wed, 21 May 2008) $ 5 * 6 * ==================================================================== 7 * 8 * Licensed to the Apache Software Foundation (ASF) under one or more 9 * contributor license agreements. See the NOTICE file distributed with 10 * this work for additional information regarding copyright ownership. 11 * The ASF licenses this file to You under the Apache License, Version 2.0 12 * (the "License"); you may not use this file except in compliance with 13 * the License. You may obtain a copy of the License at 14 * 15 * http://www.apache.org/licenses/LICENSE-2.0 16 * 17 * Unless required by applicable law or agreed to in writing, software 18 * distributed under the License is distributed on an "AS IS" BASIS, 19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 * See the License for the specific language governing permissions and 21 * limitations under the License. 22 * ==================================================================== 23 * 24 * This software consists of voluntary contributions made by many 25 * individuals on behalf of the Apache Software Foundation. For more 26 * information on the Apache Software Foundation, please see 27 * <http://www.apache.org/>. 28 * 29 */ 30 31 package org.apache.http.impl.conn; 32 33 34 import java.io.IOException; 35 36 import org.apache.http.HttpHost; 37 import org.apache.http.params.HttpParams; 38 import org.apache.http.protocol.HttpContext; 39 import org.apache.http.conn.routing.HttpRoute; 40 import org.apache.http.conn.ClientConnectionManager; 41 import org.apache.http.conn.OperatedClientConnection; 42 43 44 45 /** 46 * Abstract adapter from pool {@link AbstractPoolEntry entries} to 47 * {@link org.apache.http.conn.ManagedClientConnection managed} 48 * client connections. 49 * The connection in the pool entry is used to initialize the base class. 50 * In addition, methods to establish a route are delegated to the 51 * pool entry. {@link #shutdown shutdown} and {@link #close close} 52 * will clear the tracked route in the pool entry and call the 53 * respective method of the wrapped connection. 54 * 55 * @author <a href="mailto:rolandw at apache.org">Roland Weber</a> 56 * 57 * 58 * <!-- empty lines to avoid svn diff problems --> 59 * @version $Revision: 658775 $ $Date: 2008-05-21 10:30:45 -0700 (Wed, 21 May 2008) $ 60 * 61 * @since 4.0 62 * 63 * @deprecated Please use {@link java.net.URL#openConnection} instead. 64 * Please visit <a href="http://android-developers.blogspot.com/2011/09/androids-http-clients.html">this webpage</a> 65 * for further details. 66 */ 67 @Deprecated 68 public abstract class AbstractPooledConnAdapter extends AbstractClientConnAdapter { 69 70 /** The wrapped pool entry. */ 71 protected volatile AbstractPoolEntry poolEntry; 72 73 74 /** 75 * Creates a new connection adapter. 76 * 77 * @param manager the connection manager 78 * @param entry the pool entry for the connection being wrapped 79 */ AbstractPooledConnAdapter(ClientConnectionManager manager, AbstractPoolEntry entry)80 protected AbstractPooledConnAdapter(ClientConnectionManager manager, 81 AbstractPoolEntry entry) { 82 super(manager, entry.connection); 83 this.poolEntry = entry; 84 } 85 86 87 /** 88 * Asserts that this adapter is still attached. 89 * 90 * @throws IllegalStateException 91 * if it is {@link #detach detach}ed 92 */ assertAttached()93 protected final void assertAttached() { 94 if (poolEntry == null) { 95 throw new IllegalStateException("Adapter is detached."); 96 } 97 } 98 99 /** 100 * Detaches this adapter from the wrapped connection. 101 * This adapter becomes useless. 102 */ 103 @Override detach()104 protected void detach() { 105 super.detach(); 106 poolEntry = null; 107 } 108 109 110 // non-javadoc, see interface ManagedHttpConnection getRoute()111 public HttpRoute getRoute() { 112 113 assertAttached(); 114 return (poolEntry.tracker == null) ? 115 null : poolEntry.tracker.toRoute(); 116 } 117 118 // non-javadoc, see interface ManagedHttpConnection open(HttpRoute route, HttpContext context, HttpParams params)119 public void open(HttpRoute route, 120 HttpContext context, HttpParams params) 121 throws IOException { 122 123 assertAttached(); 124 poolEntry.open(route, context, params); 125 } 126 127 128 // non-javadoc, see interface ManagedHttpConnection tunnelTarget(boolean secure, HttpParams params)129 public void tunnelTarget(boolean secure, HttpParams params) 130 throws IOException { 131 132 assertAttached(); 133 poolEntry.tunnelTarget(secure, params); 134 } 135 136 137 // non-javadoc, see interface ManagedHttpConnection tunnelProxy(HttpHost next, boolean secure, HttpParams params)138 public void tunnelProxy(HttpHost next, boolean secure, HttpParams params) 139 throws IOException { 140 141 assertAttached(); 142 poolEntry.tunnelProxy(next, secure, params); 143 } 144 145 146 // non-javadoc, see interface ManagedHttpConnection layerProtocol(HttpContext context, HttpParams params)147 public void layerProtocol(HttpContext context, HttpParams params) 148 throws IOException { 149 150 assertAttached(); 151 poolEntry.layerProtocol(context, params); 152 } 153 154 155 156 // non-javadoc, see interface HttpConnection close()157 public void close() throws IOException { 158 if (poolEntry != null) 159 poolEntry.shutdownEntry(); 160 161 OperatedClientConnection conn = getWrappedConnection(); 162 if (conn != null) { 163 conn.close(); 164 } 165 } 166 167 // non-javadoc, see interface HttpConnection shutdown()168 public void shutdown() throws IOException { 169 if (poolEntry != null) 170 poolEntry.shutdownEntry(); 171 172 OperatedClientConnection conn = getWrappedConnection(); 173 if (conn != null) { 174 conn.shutdown(); 175 } 176 } 177 178 179 // non-javadoc, see interface ManagedClientConnection getState()180 public Object getState() { 181 assertAttached(); 182 return poolEntry.getState(); 183 } 184 185 186 // non-javadoc, see interface ManagedClientConnection setState(final Object state)187 public void setState(final Object state) { 188 assertAttached(); 189 poolEntry.setState(state); 190 } 191 192 193 } // class AbstractPooledConnAdapter 194