1 // ========================================================================
2 // Copyright (c) 2006-2009 Mort Bay Consulting Pty. Ltd.
3 // ------------------------------------------------------------------------
4 // All rights reserved. This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v1.0
6 // and Apache License v2.0 which accompanies this distribution.
7 // The Eclipse Public License is available at
8 // http://www.eclipse.org/legal/epl-v10.html
9 // The Apache License v2.0 is available at
10 // http://www.opensource.org/licenses/apache2.0.php
11 // You may elect to redistribute this code under either of these licenses.
12 // ========================================================================
13
14 package org.eclipse.jetty.io;
15
16 import java.io.IOException;
17
18 /* ------------------------------------------------------------ */
19 /** Abstract Connection used by Jetty Connectors.
20 * <p>
21 * Jetty will call the handle method of a connection when there is work
22 * to be done on the connection. For blocking connections, this is soon
23 * as the connection is open and handle will keep being called until the
24 * connection is closed. For non-blocking connections, handle will only
25 * be called if there are bytes to be read or the connection becomes writable
26 * after being write blocked.
27 *
28 * @see org.eclipse.jetty.io.nio.SelectorManager
29 */
30 public interface Connection
31 {
32 /* ------------------------------------------------------------ */
33 /**
34 * Handle the connection.
35 * @return The Connection to use for the next handling of the connection.
36 * This allows protocol upgrades and support for CONNECT.
37 * @throws IOException
38 */
39 Connection handle() throws IOException;
40
41 /**
42 * @return the timestamp at which the connection was created
43 */
44 long getTimeStamp();
45
46 boolean isIdle();
47
48 boolean isSuspended();
49
50 /**
51 * Called when the connection is closed
52 */
53 void onClose();
54
55 /**
56 * Called when the connection idle timeout expires
57 * @param idleForMs TODO
58 */
59 void onIdleExpired(long idleForMs);
60 }