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 org.eclipse.jetty.util.Callback; 22 23 /** 24 * <p>A {@link Connection} is associated to an {@link EndPoint} so that I/O events 25 * happening on the {@link EndPoint} can be processed by the {@link Connection}.</p> 26 * <p>A typical implementation of {@link Connection} overrides {@link #onOpen()} to 27 * {@link EndPoint#fillInterested(Callback) set read interest} on the {@link EndPoint}, 28 * and when the {@link EndPoint} signals read readyness, this {@link Connection} can 29 * read bytes from the network and interpret them.</p> 30 */ 31 public interface Connection extends AutoCloseable 32 { 33 public void addListener(Listener listener); 34 35 /** 36 * <p>Callback method invoked when this {@link Connection} is opened.</p> 37 * <p>Creators of the connection implementation are responsible for calling this method.</p> 38 */ 39 public void onOpen(); 40 41 /** 42 * <p>Callback method invoked when this {@link Connection} is closed.</p> 43 * <p>Creators of the connection implementation are responsible for calling this method.</p> 44 */ 45 public void onClose(); 46 47 /** 48 * @return the {@link EndPoint} associated with this {@link Connection} 49 */ 50 public EndPoint getEndPoint(); 51 52 /** 53 * <p>Performs a logical close of this connection.</p> 54 * <p>For simple connections, this may just mean to delegate the close to the associated 55 * {@link EndPoint} but, for example, SSL connections should write the SSL close message 56 * before closing the associated {@link EndPoint}.</p> 57 */ 58 @Override 59 public void close(); 60 61 public int getMessagesIn(); 62 public int getMessagesOut(); 63 public long getBytesIn(); 64 public long getBytesOut(); 65 public long getCreatedTimeStamp(); 66 67 68 public interface Listener 69 { 70 public void onOpened(Connection connection); 71 72 public void onClosed(Connection connection); 73 74 public static class Empty implements Listener 75 { 76 @Override 77 public void onOpened(Connection connection) 78 { 79 } 80 81 @Override 82 public void onClosed(Connection connection) 83 { 84 } 85 } 86 } 87 }