001: /*
002: * $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0-beta1/module-nio/src/main/java/org/apache/http/nio/NHttpServiceHandler.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 server-side HTTP event handler.
040: *
041: * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
042: */
043: public interface NHttpServiceHandler {
044:
045: /**
046: * Triggered when a new incoming connection is created.
047: *
048: * @param conn closed HTTP connection.
049: */
050: void connected(NHttpServerConnection conn);
051:
052: /**
053: * Triggered when a new HTTP request is received. The connection
054: * passed as a parameter to this method is guaranteed to return
055: * a valid HTTP request object.
056: * <p/>
057: * If the request received encloses a request entity this method will
058: * be followed a series of
059: * {@link #inputReady(NHttpServerConnection, ContentDecoder)} calls
060: * to transfer the request content.
061: *
062: * @see NHttpServerConnection
063: *
064: * @param conn HTTP connection that contains a new HTTP request
065: */
066: void requestReceived(NHttpServerConnection conn);
067:
068: /**
069: * Triggered when the underlying channel is ready for reading a
070: * new portion of the request entity through the corresponding
071: * content decoder.
072: * <p/>
073: * If the content consumer is unable to process the incoming content,
074: * input event notifications can be temorarily suspended using
075: * {@link NHttpConnection#suspendInput()}.
076: *
077: * @see NHttpConnection
078: * @see ContentDecoder
079: *
080: * @param conn HTTP connection that can produce a new portion of the
081: * incoming request content.
082: * @param decoder The content decoder to use to read content.
083: */
084: void inputReady(NHttpServerConnection conn, ContentDecoder decoder);
085:
086: /**
087: * Triggered when the connection is ready to send an HTTP response.
088: *
089: * @see NHttpServerConnection
090: *
091: * @param conn HTTP connection that contains an HTTP response
092: */
093: void responseReady(NHttpServerConnection conn);
094:
095: /**
096: * Triggered when the underlying channel is ready for writing a
097: * next portion of the response entity through the corresponding
098: * content encoder.
099: * <p/>
100: * If the content producer is unable to generate the outgoing content,
101: * output event notifications can be temorarily suspended using
102: * {@link NHttpConnection#suspendOutput()}.
103: *
104: * @see NHttpConnection
105: * @see ContentEncoder
106: *
107: * @param conn HTTP connection that can accommodate a new portion
108: * of the outgoing response content.
109: * @param encoder The content encoder to use to write content.
110: */
111: void outputReady(NHttpServerConnection conn, ContentEncoder encoder);
112:
113: /**
114: * Triggered when an I/O error occurrs while reading from or writing
115: * to the underlying channel.
116: *
117: * @param conn HTTP connection that caused an I/O error
118: * @param ex I/O exception
119: */
120: void exception(NHttpServerConnection conn, IOException ex);
121:
122: /**
123: * Triggered when an HTTP protocol violation occurs while receiving
124: * an HTTP request.
125: *
126: * @param conn HTTP connection that caused an HTTP protocol violation
127: * @param ex HTTP protocol violation exception
128: */
129: void exception(NHttpServerConnection conn, HttpException ex);
130:
131: /**
132: * Triggered when no input is detected on this connection over the
133: * maximum period of inactivity.
134: *
135: * @param conn HTTP connection that caused timeout condition.
136: */
137: void timeout(NHttpServerConnection conn);
138:
139: /**
140: * Triggered when the connection is closed.
141: *
142: * @param conn closed HTTP connection.
143: */
144: void closed(NHttpServerConnection conn);
145:
146: }
|