1 /* 2 * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/OperatedClientConnection.java $ 3 * $Revision: 646087 $ 4 * $Date: 2008-04-08 14:36:46 -0700 (Tue, 08 Apr 2008) $ 5 * 6 * ==================================================================== 7 * Licensed to the Apache Software Foundation (ASF) under one 8 * or more contributor license agreements. See the NOTICE file 9 * distributed with this work for additional information 10 * regarding copyright ownership. The ASF licenses this file 11 * to you under the Apache License, Version 2.0 (the 12 * "License"); you may not use this file except in compliance 13 * with 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, 18 * software distributed under the License is distributed on an 19 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 * KIND, either express or implied. See the License for the 21 * specific language governing permissions and limitations 22 * under the License. 23 * ==================================================================== 24 * 25 * This software consists of voluntary contributions made by many 26 * individuals on behalf of the Apache Software Foundation. For more 27 * information on the Apache Software Foundation, please see 28 * <http://www.apache.org/>. 29 * 30 */ 31 32 package org.apache.http.conn; 33 34 import java.io.IOException; 35 import java.net.Socket; 36 37 import org.apache.http.HttpClientConnection; 38 import org.apache.http.HttpHost; 39 import org.apache.http.HttpInetConnection; 40 import org.apache.http.params.HttpParams; 41 42 43 /** 44 * A client-side connection that relies on outside logic to connect sockets to the 45 * appropriate hosts. It can be operated directly by an application, or through an 46 * {@link ClientConnectionOperator operator}. 47 * 48 * 49 * @author <a href="mailto:rolandw at apache.org">Roland Weber</a> 50 * 51 * 52 * <!-- empty lines to avoid svn diff problems --> 53 * @version $Revision: 646087 $ $Date: 2008-04-08 14:36:46 -0700 (Tue, 08 Apr 2008) $ 54 * 55 * @since 4.0 56 */ 57 public interface OperatedClientConnection 58 extends HttpClientConnection, HttpInetConnection { 59 60 /** 61 * Obtains the target host for this connection. 62 * If the connection is to a proxy but not tunnelled, this is 63 * the proxy. If the connection is tunnelled through a proxy, 64 * this is the target of the tunnel. 65 * <br/> 66 * The return value is well-defined only while the connection is open. 67 * It may change even while the connection is open, 68 * because of an {@link #update update}. 69 * 70 * @return the host to which this connection is opened 71 */ 72 HttpHost getTargetHost() 73 ; 74 75 /** 76 * Indicates whether this connection is secure. 77 * The return value is well-defined only while the connection is open. 78 * It may change even while the connection is open, 79 * because of an {@link #update update}. 80 * 81 * @return <code>true</code> if this connection is secure, 82 * <code>false</code> otherwise 83 */ 84 boolean isSecure() 85 ; 86 87 /** 88 * Obtains the socket for this connection. 89 * The return value is well-defined only while the connection is open. 90 * It may change even while the connection is open, 91 * because of an {@link #update update}. 92 * 93 * @return the socket for communicating with the 94 * {@link #getTargetHost target host} 95 */ 96 Socket getSocket() 97 ; 98 99 100 // There is no getParams(). For the moment, we 101 // do not require connections to store parameters. 102 103 104 /** 105 * Signals that this connection is in the process of being open. 106 * <br/> 107 * By calling this method, you can provide the connection with 108 * the unconnected socket that will be connected before 109 * {@link #openCompleted} is called. This allows 110 * the connection to close that socket if 111 * {@link org.apache.http.HttpConnection#shutdown shutdown} 112 * is called before it is open. Closing the unconnected socket 113 * will interrupt a thread that is blocked on the connect. 114 * Otherwise, that thread will either time out on the connect, 115 * or it returns successfully and then opens this connection 116 * which was just shut down. 117 * <br/> 118 * You also must call {@link #openCompleted} in order to complete 119 * the process 120 * 121 * @param sock the unconnected socket which is about to 122 * be connected. 123 * @param target the target host of this connection 124 */ 125 void opening(Socket sock, HttpHost target) 126 throws IOException 127 ; 128 129 130 /** 131 * Signals that the connection has been successfully open. 132 * An attempt to call this method on an open connection will cause 133 * an exception. 134 * 135 * @param secure <code>true</code> if this connection is secure, for 136 * example if an <code>SSLSocket</code> is used, or 137 * <code>false</code> if it is not secure 138 * @param params parameters for this connection. The parameters will 139 * be used when creating dependent objects, for example 140 * to determine buffer sizes. 141 */ 142 void openCompleted(boolean secure, HttpParams params) 143 throws IOException 144 ; 145 146 147 /** 148 * Updates this connection. 149 * A connection can be updated only while it is open. 150 * Updates are used for example when a tunnel has been established, 151 * or when a TLS/SSL connection has been layered on top of a plain 152 * socket connection. 153 * <br/> 154 * <b>Note:</b> Updating the connection will <i>not</i> close the 155 * previously used socket. It is the caller's responsibility to close 156 * that socket if it is no longer required. 157 * 158 * @param sock the new socket for communicating with the target host, 159 * or <code>null</code> to continue using the old socket. 160 * If <code>null</code> is passed, helper objects that 161 * depend on the socket should be re-used. In that case, 162 * some changes in the parameters will not take effect. 163 * @param target the new target host of this connection 164 * @param secure <code>true</code> if this connection is now secure, 165 * <code>false</code> if it is not secure 166 * @param params new parameters for this connection 167 */ 168 void update(Socket sock, HttpHost target, 169 boolean secure, HttpParams params) 170 throws IOException 171 ; 172 173 174 } // interface OperatedClientConnection 175