1 // 2 // ======================================================================== 3 // Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd. 4 // ------------------------------------------------------------------------ 5 // All rights reserved. This program and the accompanying materials 6 // are made available under the terms of the Eclipse Public License v1.0 7 // and Apache License v2.0 which accompanies this distribution. 8 // 9 // The Eclipse Public License is available at 10 // http://www.eclipse.org/legal/epl-v10.html 11 // 12 // The Apache License v2.0 is available at 13 // http://www.opensource.org/licenses/apache2.0.php 14 // 15 // You may elect to redistribute this code under either of these licenses. 16 // ======================================================================== 17 // 18 19 package org.eclipse.jetty.io; 20 21 import java.io.Closeable; 22 23 import org.eclipse.jetty.util.Callback; 24 25 /** 26 * <p>A {@link Connection} is associated to an {@link EndPoint} so that I/O events 27 * happening on the {@link EndPoint} can be processed by the {@link Connection}.</p> 28 * <p>A typical implementation of {@link Connection} overrides {@link #onOpen()} to 29 * {@link EndPoint#fillInterested(Callback) set read interest} on the {@link EndPoint}, 30 * and when the {@link EndPoint} signals read readyness, this {@link Connection} can 31 * read bytes from the network and interpret them.</p> 32 */ 33 public interface Connection extends Closeable 34 { 35 public void addListener(Listener listener); 36 37 /** 38 * <p>Callback method invoked when this {@link Connection} is opened.</p> 39 * <p>Creators of the connection implementation are responsible for calling this method.</p> 40 */ 41 public void onOpen(); 42 43 /** 44 * <p>Callback method invoked when this {@link Connection} is closed.</p> 45 * <p>Creators of the connection implementation are responsible for calling this method.</p> 46 */ 47 public void onClose(); 48 49 /** 50 * @return the {@link EndPoint} associated with this {@link Connection} 51 */ 52 public EndPoint getEndPoint(); 53 54 /** 55 * <p>Performs a logical close of this connection.</p> 56 * <p>For simple connections, this may just mean to delegate the close to the associated 57 * {@link EndPoint} but, for example, SSL connections should write the SSL close message 58 * before closing the associated {@link EndPoint}.</p> 59 */ 60 @Override 61 public void close(); 62 63 public int getMessagesIn(); 64 public int getMessagesOut(); 65 public long getBytesIn(); 66 public long getBytesOut(); 67 public long getCreatedTimeStamp(); 68 69 70 public interface Listener 71 { 72 public void onOpened(Connection connection); 73 74 public void onClosed(Connection connection); 75 76 public static class Empty implements Listener 77 { 78 @Override 79 public void onOpened(Connection connection) 80 { 81 } 82 83 @Override 84 public void onClosed(Connection connection) 85 { 86 } 87 } 88 } 89 }