001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.catalina;
019:
020: import java.io.IOException;
021:
022: import javax.servlet.ServletException;
023: import javax.servlet.http.HttpServletRequest;
024: import javax.servlet.http.HttpServletResponse;
025:
026: /**
027: * The CometEvent interface.
028: *
029: * @author Filip Hanik
030: * @author Remy Maucherat
031: */
032: public interface CometEvent {
033:
034: /**
035: * Enumeration describing the major events that the container can invoke
036: * the CometProcessors event() method with
037: * BEGIN - will be called at the beginning
038: * of the processing of the connection. It can be used to initialize any relevant
039: * fields using the request and response objects. Between the end of the processing
040: * of this event, and the beginning of the processing of the end or error events,
041: * it is possible to use the response object to write data on the open connection.
042: * Note that the response object and depedent OutputStream and Writer are still
043: * not synchronized, so when they are accessed by multiple threads,
044: * synchronization is mandatory. After processing the initial event, the request
045: * is considered to be committed.
046: * READ - This indicates that input data is available, and that one read can be made
047: * without blocking. The available and ready methods of the InputStream or
048: * Reader may be used to determine if there is a risk of blocking: the servlet
049: * should read while data is reported available. When encountering a read error,
050: * the servlet should report it by propagating the exception properly. Throwing
051: * an exception will cause the error event to be invoked, and the connection
052: * will be closed.
053: * Alternately, it is also possible to catch any exception, perform clean up
054: * on any data structure the servlet may be using, and using the close method
055: * of the event. It is not allowed to attempt reading data from the request
056: * object outside of the execution of this method.
057: * END - End may be called to end the processing of the request. Fields that have
058: * been initialized in the begin method should be reset. After this event has
059: * been processed, the request and response objects, as well as all their dependent
060: * objects will be recycled and used to process other requests. End will also be
061: * called when data is available and the end of file is reached on the request input
062: * (this usually indicates the client has pipelined a request).
063: * ERROR - Error will be called by the container in the case where an IO exception
064: * or a similar unrecoverable error occurs on the connection. Fields that have
065: * been initialized in the begin method should be reset. After this event has
066: * been processed, the request and response objects, as well as all their dependent
067: * objects will be recycled and used to process other requests.
068: */
069: public enum EventType {
070: BEGIN, READ, END, ERROR
071: }
072:
073: /**
074: * Event details
075: * TIMEOUT - the connection timed out (sub type of ERROR); note that this ERROR type is not fatal, and
076: * the connection will not be closed unless the servlet uses the close method of the event
077: * CLIENT_DISCONNECT - the client connection was closed (sub type of ERROR)
078: * IOEXCEPTION - an IO exception occurred, such as invalid content, for example, an invalid chunk block (sub type of ERROR)
079: * WEBAPP_RELOAD - the webapplication is being reloaded (sub type of END)
080: * SERVER_SHUTDOWN - the server is shutting down (sub type of END)
081: * SESSION_END - the servlet ended the session (sub type of END)
082: */
083: public enum EventSubType {
084: TIMEOUT, CLIENT_DISCONNECT, IOEXCEPTION, WEBAPP_RELOAD, SERVER_SHUTDOWN, SESSION_END
085: }
086:
087: /**
088: * Returns the HttpServletRequest.
089: *
090: * @return HttpServletRequest
091: */
092: public HttpServletRequest getHttpServletRequest();
093:
094: /**
095: * Returns the HttpServletResponse.
096: *
097: * @return HttpServletResponse
098: */
099: public HttpServletResponse getHttpServletResponse();
100:
101: /**
102: * Returns the event type.
103: *
104: * @return EventType
105: */
106: public EventType getEventType();
107:
108: /**
109: * Returns the sub type of this event.
110: *
111: * @return EventSubType
112: */
113: public EventSubType getEventSubType();
114:
115: /**
116: * Ends the Comet session. This signals to the container that
117: * the container wants to end the comet session. This will send back to the
118: * client a notice that the server has no more data to send as part of this
119: * request. The servlet should perform any needed cleanup as if it had recieved
120: * an END or ERROR event.
121: *
122: * @throws IOException if an IO exception occurs
123: */
124: public void close() throws IOException;
125:
126: /**
127: * Sets the timeout for this Comet connection. Please NOTE, that the implementation
128: * of a per connection timeout is OPTIONAL and MAY NOT be implemented.<br/>
129: * This method sets the timeout in milliseconds of idle time on the connection.
130: * The timeout is reset every time data is received from the connection or data is flushed
131: * using <code>response.flushBuffer()</code>. If a timeout occurs, the
132: * <code>error(HttpServletRequest, HttpServletResponse)</code> method is invoked. The
133: * web application SHOULD NOT attempt to reuse the request and response objects after a timeout
134: * as the <code>error(HttpServletRequest, HttpServletResponse)</code> method indicates.<br/>
135: * This method should not be called asynchronously, as that will have no effect.
136: *
137: * @param timeout The timeout in milliseconds for this connection, must be a positive value, larger than 0
138: * @throws IOException An IOException may be thrown to indicate an IO error,
139: * or that the EOF has been reached on the connection
140: * @throws ServletException An exception has occurred, as specified by the root
141: * cause
142: * @throws UnsupportedOperationException if per connection timeout is not supported, either at all or at this phase
143: * of the invocation.
144: */
145: public void setTimeout(int timeout) throws IOException,
146: ServletException, UnsupportedOperationException;
147:
148: }
|