001: /*
002: * $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0-beta1/module-nio/src/main/java/org/apache/http/nio/NHttpClientHandler.java $
003: * $Revision: 613298 $
004: * $Date: 2008-01-18 23:09:22 +0100 (Fri, 18 Jan 2008) $
005: *
006: * ====================================================================
007: * Licensed to the Apache Software Foundation (ASF) under one
008: * or more contributor license agreements. See the NOTICE file
009: * distributed with this work for additional information
010: * regarding copyright ownership. The ASF licenses this file
011: * to you under the Apache License, Version 2.0 (the
012: * "License"); you may not use this file except in compliance
013: * with the License. You may obtain a copy of the License at
014: *
015: * http://www.apache.org/licenses/LICENSE-2.0
016: *
017: * Unless required by applicable law or agreed to in writing,
018: * software distributed under the License is distributed on an
019: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
020: * KIND, either express or implied. See the License for the
021: * specific language governing permissions and limitations
022: * under the License.
023: * ====================================================================
024: *
025: * This software consists of voluntary contributions made by many
026: * individuals on behalf of the Apache Software Foundation. For more
027: * information on the Apache Software Foundation, please see
028: * <http://www.apache.org/>.
029: *
030: */
031:
032: package org.apache.http.nio;
033:
034: import java.io.IOException;
035:
036: import org.apache.http.HttpException;
037:
038: /**
039: * Abstract client-side HTTP event handler.
040: *
041: * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
042: */
043: public interface NHttpClientHandler {
044:
045: /**
046: * Triggered when a new outgoing connection is created.
047: *
048: * @param conn closed HTTP connection.
049: * @param attachment an arbitrary object that was attached to the
050: * session request
051: */
052: void connected(NHttpClientConnection conn, Object attachment);
053:
054: /**
055: * Triggered when the connection is ready to send an HTTP request.
056: *
057: * @see NHttpClientConnection
058: *
059: * @param conn HTTP connection that is ready to send an 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 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 temorarily suspended using
086: * {@link NHttpConnection#suspendInput()}.
087: *
088: * @see NHttpConnection
089: * @see ContentDecoder
090: *
091: * @param conn HTTP connection that can produce a new portion of the
092: * incoming response content.
093: * @param decoder The content decoder to use to read content.
094: */
095: void inputReady(NHttpClientConnection conn, ContentDecoder decoder);
096:
097: /**
098: * Triggered when the underlying channel is ready for writing a
099: * next portion of the request entity through the corresponding
100: * content encoder.
101: * <p/>
102: * If the content producer is unable to generate the outgoing content,
103: * output event notifications can be temorarily suspended using
104: * {@link NHttpConnection#suspendOutput()}.
105: *
106: * @see NHttpConnection
107: * @see ContentEncoder
108: *
109: * @param conn HTTP connection that can accommodate a new portion
110: * of the outgoing request content.
111: * @param encoder The content encoder to use to write content.
112: */
113: void outputReady(NHttpClientConnection conn, ContentEncoder encoder);
114:
115: /**
116: * Triggered when an I/O error occurrs while reading from or writing
117: * to the underlying channel.
118: *
119: * @param conn HTTP connection that caused an I/O error
120: * @param ex I/O exception
121: */
122: void exception(NHttpClientConnection conn, IOException ex);
123:
124: /**
125: * Triggered when an HTTP protocol violation occurs while receiving
126: * an HTTP response.
127: *
128: * @param conn HTTP connection that caused an HTTP protocol violation
129: * @param ex HTTP protocol violation exception
130: */
131: void exception(NHttpClientConnection conn, HttpException ex);
132:
133: /**
134: * Triggered when no input is detected on this connection over the
135: * maximum period of inactivity.
136: *
137: * @param conn HTTP connection that caused timeout condition.
138: */
139: void timeout(NHttpClientConnection conn);
140:
141: /**
142: * Triggered when the connection is closed.
143: *
144: * @param conn closed HTTP connection.
145: */
146: void closed(NHttpClientConnection conn);
147:
148: }
|