2 // ========================================================================
3 // Copyright (c) 1995-2014 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.
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
19 package org.eclipse.jetty.io;
21 import java.io.Closeable;
23 import org.eclipse.jetty.util.Callback;
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>
33 public interface Connection extends Closeable
35 public void addListener(Listener listener);
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>
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>
47 public void onClose();
50 * @return the {@link EndPoint} associated with this {@link Connection}
52 public EndPoint getEndPoint();
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>
63 public int getMessagesIn();
64 public int getMessagesOut();
65 public long getBytesIn();
66 public long getBytesOut();
67 public long getCreatedTimeStamp();
70 public interface Listener
72 public void onOpened(Connection connection);
74 public void onClosed(Connection connection);
76 public static class Adapter implements Listener
79 public void onOpened(Connection connection)
84 public void onClosed(Connection connection)