changeset 866:f8c7b718f513

remove NetworkTrafficListener
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 02 Oct 2016 20:47:02 -0600
parents 6b210bb66c63
children 4f5547d29192
files src/org/eclipse/jetty/io/NetworkTrafficListener.java src/org/eclipse/jetty/io/nio/NetworkTrafficSelectChannelEndPoint.java src/org/eclipse/jetty/server/nio/NetworkTrafficSelectChannelConnector.java
diffstat 3 files changed, 0 insertions(+), 320 deletions(-) [+]
line wrap: on
line diff
--- a/src/org/eclipse/jetty/io/NetworkTrafficListener.java	Sun Oct 02 20:38:06 2016 -0600
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,99 +0,0 @@
-//
-//  ========================================================================
-//  Copyright (c) 1995-2014 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;
-
-/**
- * <p>A listener for raw network traffic within Jetty.</p>
- * <p>{@link NetworkTrafficListener}s can be installed in a
- * <code>org.eclipse.jetty.server.nio.NetworkTrafficSelectChannelConnector</code>,
- * and are notified of the following network traffic events:</p>
- * <ul>
- * <li>Connection opened, when the server has accepted the connection from a remote client</li>
- * <li>Incoming bytes, when the server receives bytes sent from a remote client</li>
- * <li>Outgoing bytes, when the server sends bytes to a remote client</li>
- * <li>Connection closed, when the server has closed the connection to a remote client</li>
- * </ul>
- * <p>{@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.</p>
- */
-public interface NetworkTrafficListener
-{
-    /**
-     * <p>Callback method invoked when a connection from a remote client has been accepted.</p>
-     * <p>The {@code socket} parameter can be used to extract socket address information of
-     * the remote client.</p>
-     *
-     * @param socket the socket associated with the remote client
-     */
-    public void opened(Socket socket);
-
-    /**
-     * <p>Callback method invoked when bytes sent by a remote client arrived on the server.</p>
-     *
-     * @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);
-
-    /**
-     * <p>Callback method invoked when bytes are sent to a remote client from the server.</p>
-     * <p>This method is invoked after the bytes have been actually written to the remote client.</p>
-     *
-     * @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);
-
-    /**
-     * <p>Callback method invoked when a connection to a remote client has been closed.</p>
-     * <p>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.<br />
-     * 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);
-
-    /**
-     * <p>A commodity class that implements {@link NetworkTrafficListener} with empty methods.</p>
-     */
-    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)
-        {
-        }
-    }
-}
--- a/src/org/eclipse/jetty/io/nio/NetworkTrafficSelectChannelEndPoint.java	Sun Oct 02 20:38:06 2016 -0600
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,148 +0,0 @@
-//
-//  ========================================================================
-//  Copyright (c) 1995-2014 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.nio;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.channels.SelectionKey;
-import java.nio.channels.SocketChannel;
-import java.util.List;
-
-import org.eclipse.jetty.io.Buffer;
-import org.eclipse.jetty.io.NetworkTrafficListener;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class NetworkTrafficSelectChannelEndPoint extends SelectChannelEndPoint
-{
-    private static final Logger LOG = LoggerFactory.getLogger(NetworkTrafficSelectChannelEndPoint.class);
-
-    private final List<NetworkTrafficListener> listeners;
-
-    public NetworkTrafficSelectChannelEndPoint(SocketChannel channel, SelectorManager.SelectSet selectSet, SelectionKey key, int maxIdleTime, List<NetworkTrafficListener> listeners) throws IOException
-    {
-        super(channel, selectSet, key, maxIdleTime);
-        this.listeners = listeners;
-    }
-
-    @Override
-    public int fill(Buffer buffer) throws IOException
-    {
-        int read = super.fill(buffer);
-        notifyIncoming(buffer, read);
-        return read;
-    }
-
-    @Override
-    public int flush(Buffer buffer) throws IOException
-    {
-        int position = buffer.getIndex();
-        int written = super.flush(buffer);
-        notifyOutgoing(buffer, position, written);
-        return written;
-    }
-
-    @Override
-    protected int gatheringFlush(Buffer header, ByteBuffer bbuf0, Buffer buffer, ByteBuffer bbuf1) throws IOException
-    {
-        int headerPosition = header.getIndex();
-        int headerLength = header.length();
-        int bufferPosition = buffer.getIndex();
-        int written = super.gatheringFlush(header, bbuf0, buffer,bbuf1);
-        notifyOutgoing(header, headerPosition, written > headerLength ? headerLength : written);
-        notifyOutgoing(buffer, bufferPosition, written > headerLength ? written - headerLength : 0);
-        return written;
-    }
-
-    public void notifyOpened()
-    {
-        if (listeners != null && !listeners.isEmpty())
-        {
-            for (NetworkTrafficListener listener : listeners)
-            {
-                try
-                {
-                    listener.opened(_socket);
-                }
-                catch (Exception x)
-                {
-                    LOG.warn("",x);
-                }
-            }
-        }
-    }
-
-    public void notifyIncoming(Buffer buffer, int read)
-    {
-        if (listeners != null && !listeners.isEmpty() && read > 0)
-        {
-            for (NetworkTrafficListener listener : listeners)
-            {
-                try
-                {
-                    Buffer view = buffer.asReadOnlyBuffer();
-                    listener.incoming(_socket, view);
-                }
-                catch (Exception x)
-                {
-                    LOG.warn("",x);
-                }
-            }
-        }
-    }
-
-    public void notifyOutgoing(Buffer buffer, int position, int written)
-    {
-        if (listeners != null && !listeners.isEmpty() && written > 0)
-        {
-            for (NetworkTrafficListener listener : listeners)
-            {
-                try
-                {
-                    Buffer view = buffer.asReadOnlyBuffer();
-                    view.setGetIndex(position);
-                    view.setPutIndex(position + written);
-                    listener.outgoing(_socket, view);
-                }
-                catch (Exception x)
-                {
-                    LOG.warn("",x);
-                }
-            }
-        }
-    }
-
-    public void notifyClosed()
-    {
-        if (listeners != null && !listeners.isEmpty())
-        {
-            for (NetworkTrafficListener listener : listeners)
-            {
-                try
-                {
-                    listener.closed(_socket);
-                }
-                catch (Exception x)
-                {
-                    LOG.warn("",x);
-                }
-            }
-        }
-    }
-}
--- a/src/org/eclipse/jetty/server/nio/NetworkTrafficSelectChannelConnector.java	Sun Oct 02 20:38:06 2016 -0600
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,73 +0,0 @@
-//
-//  ========================================================================
-//  Copyright (c) 1995-2014 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.server.nio;
-
-import java.io.IOException;
-import java.nio.channels.SelectionKey;
-import java.nio.channels.SocketChannel;
-import java.util.ConcurrentModificationException;
-import java.util.List;
-import java.util.concurrent.CopyOnWriteArrayList;
-
-import org.eclipse.jetty.io.NetworkTrafficListener;
-import org.eclipse.jetty.io.nio.NetworkTrafficSelectChannelEndPoint;
-import org.eclipse.jetty.io.nio.SelectChannelEndPoint;
-import org.eclipse.jetty.io.nio.SelectorManager;
-
-/**
- * <p>A specialized version of {@link SelectChannelConnector} that supports {@link NetworkTrafficListener}s.</p>
- * <p>{@link NetworkTrafficListener}s can be added and removed dynamically before and after this connector has
- * been started without causing {@link ConcurrentModificationException}s.</p>
- */
-public class NetworkTrafficSelectChannelConnector extends SelectChannelConnector
-{
-    private final List<NetworkTrafficListener> listeners = new CopyOnWriteArrayList<NetworkTrafficListener>();
-
-    /**
-     * @param listener the listener to add
-     */
-    public void addNetworkTrafficListener(NetworkTrafficListener listener)
-    {
-        listeners.add(listener);
-    }
-
-    /**
-     * @param listener the listener to remove
-     */
-    public void removeNetworkTrafficListener(NetworkTrafficListener listener)
-    {
-        listeners.remove(listener);
-    }
-
-    @Override
-    protected SelectChannelEndPoint newEndPoint(SocketChannel channel, SelectorManager.SelectSet selectSet, SelectionKey key) throws IOException
-    {
-        NetworkTrafficSelectChannelEndPoint endPoint = new NetworkTrafficSelectChannelEndPoint(channel, selectSet, key, _maxIdleTime, listeners);
-        endPoint.setConnection(selectSet.getManager().newConnection(channel,endPoint, key.attachment()));
-        endPoint.notifyOpened();
-        return endPoint;
-    }
-
-    @Override
-    protected void endPointClosed(SelectChannelEndPoint endpoint)
-    {
-        super.endPointClosed(endpoint);
-        ((NetworkTrafficSelectChannelEndPoint)endpoint).notifyClosed();
-    }
-}