michael@0: /* michael@0: * ==================================================================== michael@0: * Licensed to the Apache Software Foundation (ASF) under one michael@0: * or more contributor license agreements. See the NOTICE file michael@0: * distributed with this work for additional information michael@0: * regarding copyright ownership. The ASF licenses this file michael@0: * to you under the Apache License, Version 2.0 (the michael@0: * "License"); you may not use this file except in compliance michael@0: * with the License. You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, michael@0: * software distributed under the License is distributed on an michael@0: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY michael@0: * KIND, either express or implied. See the License for the michael@0: * specific language governing permissions and limitations michael@0: * under the License. michael@0: * ==================================================================== michael@0: * michael@0: * This software consists of voluntary contributions made by many michael@0: * individuals on behalf of the Apache Software Foundation. For more michael@0: * information on the Apache Software Foundation, please see michael@0: * . michael@0: * michael@0: */ michael@0: michael@0: package ch.boye.httpclientandroidlib.conn; michael@0: michael@0: import java.io.IOException; michael@0: import java.net.Socket; michael@0: michael@0: import ch.boye.httpclientandroidlib.HttpClientConnection; michael@0: import ch.boye.httpclientandroidlib.HttpHost; michael@0: import ch.boye.httpclientandroidlib.HttpInetConnection; michael@0: import ch.boye.httpclientandroidlib.params.HttpParams; michael@0: michael@0: /** michael@0: * A client-side connection that relies on outside logic to connect sockets to the michael@0: * appropriate hosts. It can be operated directly by an application, or through an michael@0: * {@link ClientConnectionOperator operator}. michael@0: * michael@0: * @since 4.0 michael@0: */ michael@0: public interface OperatedClientConnection extends HttpClientConnection, HttpInetConnection { michael@0: michael@0: /** michael@0: * Obtains the target host for this connection. michael@0: * If the connection is to a proxy but not tunnelled, this is michael@0: * the proxy. If the connection is tunnelled through a proxy, michael@0: * this is the target of the tunnel. michael@0: *
michael@0: * The return value is well-defined only while the connection is open. michael@0: * It may change even while the connection is open, michael@0: * because of an {@link #update update}. michael@0: * michael@0: * @return the host to which this connection is opened michael@0: */ michael@0: HttpHost getTargetHost(); michael@0: michael@0: /** michael@0: * Indicates whether this connection is secure. michael@0: * The return value is well-defined only while the connection is open. michael@0: * It may change even while the connection is open, michael@0: * because of an {@link #update update}. michael@0: * michael@0: * @return true if this connection is secure, michael@0: * false otherwise michael@0: */ michael@0: boolean isSecure(); michael@0: michael@0: /** michael@0: * Obtains the socket for this connection. michael@0: * The return value is well-defined only while the connection is open. michael@0: * It may change even while the connection is open, michael@0: * because of an {@link #update update}. michael@0: * michael@0: * @return the socket for communicating with the michael@0: * {@link #getTargetHost target host} michael@0: */ michael@0: Socket getSocket(); michael@0: michael@0: /** michael@0: * Signals that this connection is in the process of being open. michael@0: *

michael@0: * By calling this method, the connection can be re-initialized michael@0: * with a new Socket instance before {@link #openCompleted} is called. michael@0: * This enabled the connection to close that socket if michael@0: * {@link ch.boye.httpclientandroidlib.HttpConnection#shutdown shutdown} michael@0: * is called before it is fully open. Closing an unconnected socket michael@0: * will interrupt a thread that is blocked on the connect. michael@0: * Otherwise, that thread will either time out on the connect, michael@0: * or it returns successfully and then opens this connection michael@0: * which was just shut down. michael@0: *

michael@0: * This method can be called multiple times if the connection michael@0: * is layered over another protocol. Note: This method michael@0: * will not close the previously used socket. It is michael@0: * the caller's responsibility to close that socket if it is michael@0: * no longer required. michael@0: *

michael@0: * The caller must invoke {@link #openCompleted} in order to complete michael@0: * the process. michael@0: * michael@0: * @param sock the unconnected socket which is about to michael@0: * be connected. michael@0: * @param target the target host of this connection michael@0: */ michael@0: void opening(Socket sock, HttpHost target) michael@0: throws IOException; michael@0: michael@0: /** michael@0: * Signals that the connection has been successfully open. michael@0: * An attempt to call this method on an open connection will cause michael@0: * an exception. michael@0: * michael@0: * @param secure true if this connection is secure, for michael@0: * example if an SSLSocket is used, or michael@0: * false if it is not secure michael@0: * @param params parameters for this connection. The parameters will michael@0: * be used when creating dependent objects, for example michael@0: * to determine buffer sizes. michael@0: */ michael@0: void openCompleted(boolean secure, HttpParams params) michael@0: throws IOException; michael@0: michael@0: /** michael@0: * Updates this connection. michael@0: * A connection can be updated only while it is open. michael@0: * Updates are used for example when a tunnel has been established, michael@0: * or when a TLS/SSL connection has been layered on top of a plain michael@0: * socket connection. michael@0: *
michael@0: * Note: Updating the connection will not close the michael@0: * previously used socket. It is the caller's responsibility to close michael@0: * that socket if it is no longer required. michael@0: * michael@0: * @param sock the new socket for communicating with the target host, michael@0: * or null to continue using the old socket. michael@0: * If null is passed, helper objects that michael@0: * depend on the socket should be re-used. In that case, michael@0: * some changes in the parameters will not take effect. michael@0: * @param target the new target host of this connection michael@0: * @param secure true if this connection is now secure, michael@0: * false if it is not secure michael@0: * @param params new parameters for this connection michael@0: */ michael@0: void update(Socket sock, HttpHost target, michael@0: boolean secure, HttpParams params) michael@0: throws IOException; michael@0: michael@0: }