// // ======================================================================== // Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd. // ------------------------------------------------------------------------ // All rights reserved. This program and the accompanying materials // are made available under the terms of the Eclipse Public License v1.0 // and Apache License v2.0 which accompanies this distribution. // // The Eclipse Public License is available at // http://www.eclipse.org/legal/epl-v10.html // // The Apache License v2.0 is available at // http://www.opensource.org/licenses/apache2.0.php // // You may elect to redistribute this code under either of these licenses. // ======================================================================== // package org.eclipse.jetty.io; import java.net.Socket; /** *
A listener for raw network traffic within Jetty.
*{@link NetworkTrafficListener}s can be installed in a
* org.eclipse.jetty.server.nio.NetworkTrafficSelectChannelConnector
,
* and are notified of the following network traffic events:
{@link NetworkTrafficListener}s can be used to log the network traffic viewed by * a Jetty server (for example logging to filesystem) for activities such as debugging * or request/response cycles or for replaying request/response cycles to other servers.
*/ public interface NetworkTrafficListener { /** *Callback method invoked when a connection from a remote client has been accepted.
*The {@code socket} parameter can be used to extract socket address information of * the remote client.
* * @param socket the socket associated with the remote client */ public void opened(Socket socket); /** *Callback method invoked when bytes sent by a remote client arrived on the server.
* * @param socket the socket associated with the remote client * @param bytes the read-only buffer containing the incoming bytes */ public void incoming(Socket socket, Buffer bytes); /** *Callback method invoked when bytes are sent to a remote client from the server.
*This method is invoked after the bytes have been actually written to the remote client.
* * @param socket the socket associated with the remote client * @param bytes the read-only buffer containing the outgoing bytes */ public void outgoing(Socket socket, Buffer bytes); /** *Callback method invoked when a connection to a remote client has been closed.
*The {@code socket} parameter is already closed when this method is called, so it
* cannot be queried for socket address information of the remote client.
* However, the {@code socket} parameter is the same object passed to {@link #opened(Socket)},
* so it is possible to map socket information in {@link #opened(Socket)} and retrieve it
* in this method.
*
* @param socket the (closed) socket associated with the remote client
*/
public void closed(Socket socket);
/**
*
A commodity class that implements {@link NetworkTrafficListener} with empty methods.
*/ public static class Empty implements NetworkTrafficListener { public void opened(Socket socket) { } public void incoming(Socket socket, Buffer bytes) { } public void outgoing(Socket socket, Buffer bytes) { } public void closed(Socket socket) { } } }