View Javadoc
1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package org.apache.http.nio;
29  
30  import java.io.IOException;
31  
32  import org.apache.http.HttpException;
33  
34  /**
35   * Abstract client-side HTTP protocol handler.
36   *
37   * @since 4.0
38   *
39   * @deprecated (4.2) use {@link NHttpClientEventHandler}
40   */
41  @Deprecated
42  public interface NHttpClientHandler {
43  
44      /**
45       * Triggered when a new outgoing connection is created.
46       *
47       * @param conn new outgoing HTTP connection.
48       * @param attachment an object that was attached to the session request
49       */
50      void connected(NHttpClientConnection conn, Object attachment);
51  
52      /**
53       * Triggered when the connection is ready to accept a new HTTP request.
54       * The protocol handler does not have to submit a request if it is not
55       * ready.
56       *
57       * @see NHttpClientConnection
58       *
59       * @param conn HTTP connection that is ready to accept a new HTTP request.
60       */
61      void requestReady(NHttpClientConnection conn);
62  
63      /**
64       * Triggered when an HTTP response is received. The connection
65       * passed as a parameter to this method is guaranteed to return
66       * a valid HTTP response object.
67       * <p>
68       * If the response received encloses a response entity this method will
69       * be followed by a series of
70       * {@link #inputReady(NHttpClientConnection, ContentDecoder)} calls
71       * to transfer the response content.
72       *
73       * @see NHttpClientConnection
74       *
75       * @param conn HTTP connection that contains an HTTP response
76       */
77      void responseReceived(NHttpClientConnection conn);
78  
79      /**
80       * Triggered when the underlying channel is ready for reading a
81       * new portion of the response entity through the corresponding
82       * content decoder.
83       * <p>
84       * If the content consumer is unable to process the incoming content,
85       * input event notifications can be temporarily suspended using
86       * {@link IOControl} interface.
87       *
88       * @see NHttpClientConnection
89       * @see ContentDecoder
90       * @see IOControl
91       *
92       * @param conn HTTP connection that can produce a new portion of the
93       * incoming response content.
94       * @param decoder The content decoder to use to read content.
95       */
96      void inputReady(NHttpClientConnection conn, ContentDecoder decoder);
97  
98      /**
99       * 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 }