2 // ========================================================================
3 // Copyright (c) 1995-2016 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;
22 import java.nio.ByteBuffer;
25 * <p>A {@link Connection} is associated to an {@link EndPoint} so that I/O events
26 * happening on the {@link EndPoint} can be processed by the {@link Connection}.</p>
27 * <p>A typical implementation of {@link Connection} overrides {@link #onOpen(ByteBuffer)} to
28 * {@link EndPoint#fillInterested(Callback) set read interest} on the {@link EndPoint},
29 * and when the {@link EndPoint} signals read readyness, this {@link Connection} can
30 * read bytes from the network and interpret them.</p>
32 public interface Connection extends Closeable
34 public void addListener(Listener listener);
39 * <p>Callback method invoked when this {@link Connection} is closed.</p>
40 * <p>Creators of the connection implementation are responsible for calling this method.</p>
42 public void onClose();
45 * @return the {@link EndPoint} associated with this {@link Connection}
47 public EndPoint getEndPoint();
50 * <p>Performs a logical close of this connection.</p>
51 * <p>For simple connections, this may just mean to delegate the close to the associated
52 * {@link EndPoint} but, for example, SSL connections should write the SSL close message
53 * before closing the associated {@link EndPoint}.</p>
58 public int getMessagesIn();
59 public int getMessagesOut();
60 public long getBytesIn();
61 public long getBytesOut();
62 public long getCreatedTimeStamp();
64 public interface UpgradeFrom extends Connection
66 /* ------------------------------------------------------------ */
67 /** Take the input buffer from the connection on upgrade.
68 * <p>This method is used to take any unconsumed input from
69 * a connection during an upgrade.
70 * @return A buffer of unconsumed input. The caller must return the buffer
71 * to the bufferpool when consumed and this connection must not.
73 ByteBuffer onUpgradeFrom();
76 public interface UpgradeTo extends Connection
79 * <p>Callback method invoked when this {@link Connection} is upgraded.</p>
80 * <p>This must be called before {@link #onOpen()}.</p>
81 * @param prefilledBuffer An optional buffer that can contain prefilled data. Typically this
82 * results from an upgrade of one protocol to the other where the old connection has buffered
83 * data destined for the new connection. The new connection must take ownership of the buffer
84 * and is responsible for returning it to the buffer pool
86 void onUpgradeTo(ByteBuffer prefilled);
89 public interface Listener
91 public void onOpened(Connection connection);
93 public void onClosed(Connection connection);
95 public static class Adapter implements Listener
98 public void onOpened(Connection connection)
103 public void onClosed(Connection connection)