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 if the handling of I/O operations fail 38 */ 39 Connection handle() throws IOException; 40 41 /** 42 * @return the timestamp at which the connection was created 43 */ 44 long getTimeStamp(); 45 46 /** 47 * @return whether this connection is idle, that is not parsing and not generating 48 * @see #onIdleExpired(long) 49 */ 50 boolean isIdle(); 51 52 /** 53 * <p>The semantic of this method is to return true to indicate interest in further reads, 54 * or false otherwise, but it is misnamed and should be really called <code>isReadInterested()</code>.</p> 55 * 56 * @return true to indicate interest in further reads, false otherwise 57 */ 58 // TODO: rename to isReadInterested() in the next release 59 boolean isSuspended(); 60 61 /** 62 * Called after the connection is closed 63 */ 64 void onClose(); 65 66 /** 67 * Called when the connection idle timeout expires 68 * @param idleForMs how long the connection has been idle 69 * @see #isIdle() 70 */ 71 void onIdleExpired(long idleForMs); 72 }