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 */
027
028package org.apache.http.nio;
029
030import java.io.IOException;
031
032import org.apache.http.HttpException;
033
034/**
035 * Abstract client-side HTTP protocol handler.
036 *
037 * @since 4.0
038 *
039 * @deprecated (4.2) use {@link NHttpClientEventHandler}
040 */
041@Deprecated
042public interface NHttpClientHandler {
043
044    /**
045     * Triggered when a new outgoing connection is created.
046     *
047     * @param conn new outgoing HTTP connection.
048     * @param attachment an object that was attached to the session request
049     */
050    void connected(NHttpClientConnection conn, Object attachment);
051
052    /**
053     * Triggered when the connection is ready to accept a new HTTP request.
054     * The protocol handler does not have to submit a request if it is not
055     * ready.
056     *
057     * @see NHttpClientConnection
058     *
059     * @param conn HTTP connection that is ready to accept a new HTTP request.
060     */
061    void requestReady(NHttpClientConnection conn);
062
063    /**
064     * Triggered when an HTTP response is received. The connection
065     * passed as a parameter to this method is guaranteed to return
066     * a valid HTTP response object.
067     * <p>
068     * If the response received encloses a response entity this method will
069     * be followed by a series of
070     * {@link #inputReady(NHttpClientConnection, ContentDecoder)} calls
071     * to transfer the response content.
072     *
073     * @see NHttpClientConnection
074     *
075     * @param conn HTTP connection that contains an HTTP response
076     */
077    void responseReceived(NHttpClientConnection conn);
078
079    /**
080     * Triggered when the underlying channel is ready for reading a
081     * new portion of the response entity through the corresponding
082     * content decoder.
083     * <p>
084     * If the content consumer is unable to process the incoming content,
085     * input event notifications can be temporarily suspended using
086     * {@link IOControl} interface.
087     *
088     * @see NHttpClientConnection
089     * @see ContentDecoder
090     * @see IOControl
091     *
092     * @param conn HTTP connection that can produce a new portion of the
093     * incoming response content.
094     * @param decoder The content decoder to use to read content.
095     */
096    void inputReady(NHttpClientConnection conn, ContentDecoder decoder);
097
098    /**
099     * Triggered when the underlying channel is ready for writing a next portion
100     * of the request entity through the corresponding content encoder.
101     * <p>
102     * If the content producer is unable to generate the outgoing content,
103     * output event notifications can be temporarily suspended using
104     * {@link IOControl} interface.
105     *
106     * @see NHttpClientConnection
107     * @see ContentEncoder
108     * @see IOControl
109     *
110     * @param conn HTTP connection that can accommodate a new portion
111     * of the outgoing request content.
112     * @param encoder The content encoder to use to write content.
113     */
114    void outputReady(NHttpClientConnection conn, ContentEncoder encoder);
115
116    /**
117     * Triggered when an I/O error occurs while reading from or writing
118     * to the underlying channel.
119     *
120     * @param conn HTTP connection that caused an I/O error
121     * @param ex I/O exception
122     */
123    void exception(NHttpClientConnection conn, IOException ex);
124
125    /**
126     * Triggered when an HTTP protocol violation occurs while receiving
127     * an HTTP response.
128     *
129     * @param conn HTTP connection that caused an HTTP protocol violation
130     * @param ex HTTP protocol violation exception
131     */
132    void exception(NHttpClientConnection conn, HttpException ex);
133
134    /**
135     * Triggered when no input is detected on this connection over the
136     * maximum period of inactivity.
137     *
138     * @param conn HTTP connection that caused timeout condition.
139     */
140    void timeout(NHttpClientConnection conn);
141
142    /**
143     * Triggered when the connection is closed.
144     *
145     * @param conn closed HTTP connection.
146     */
147    void closed(NHttpClientConnection conn);
148
149}