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.net.Socket;
22 import java.nio.ByteBuffer;
25 * <p>A listener for raw network traffic within Jetty.</p>
26 * <p>{@link NetworkTrafficListener}s can be installed in a
27 * <code>org.eclipse.jetty.server.nio.NetworkTrafficSelectChannelConnector</code>,
28 * and are notified of the following network traffic events:</p>
30 * <li>Connection opened, when the server has accepted the connection from a remote client</li>
31 * <li>Incoming bytes, when the server receives bytes sent from a remote client</li>
32 * <li>Outgoing bytes, when the server sends bytes to a remote client</li>
33 * <li>Connection closed, when the server has closed the connection to a remote client</li>
35 * <p>{@link NetworkTrafficListener}s can be used to log the network traffic viewed by
36 * a Jetty server (for example logging to filesystem) for activities such as debugging
37 * or request/response cycles or for replaying request/response cycles to other servers.</p>
39 public interface NetworkTrafficListener
42 * <p>Callback method invoked when a connection from a remote client has been accepted.</p>
43 * <p>The {@code socket} parameter can be used to extract socket address information of
44 * the remote client.</p>
46 * @param socket the socket associated with the remote client
48 public void opened(Socket socket);
51 * <p>Callback method invoked when bytes sent by a remote client arrived on the server.</p>
53 * @param socket the socket associated with the remote client
54 * @param bytes the read-only buffer containing the incoming bytes
56 public void incoming(Socket socket, ByteBuffer bytes);
59 * <p>Callback method invoked when bytes are sent to a remote client from the server.</p>
60 * <p>This method is invoked after the bytes have been actually written to the remote client.</p>
62 * @param socket the socket associated with the remote client
63 * @param bytes the read-only buffer containing the outgoing bytes
65 public void outgoing(Socket socket, ByteBuffer bytes);
68 * <p>Callback method invoked when a connection to a remote client has been closed.</p>
69 * <p>The {@code socket} parameter is already closed when this method is called, so it
70 * cannot be queried for socket address information of the remote client.<br />
71 * However, the {@code socket} parameter is the same object passed to {@link #opened(Socket)},
72 * so it is possible to map socket information in {@link #opened(Socket)} and retrieve it
75 * @param socket the (closed) socket associated with the remote client
77 public void closed(Socket socket);
80 * <p>A commodity class that implements {@link NetworkTrafficListener} with empty methods.</p>
82 public static class Adapter implements NetworkTrafficListener
84 public void opened(Socket socket)
88 public void incoming(Socket socket, ByteBuffer bytes)
92 public void outgoing(Socket socket, ByteBuffer bytes)
96 public void closed(Socket socket)