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.server;
21 import java.io.IOException;
22 import java.nio.channels.SelectionKey;
23 import java.nio.channels.SocketChannel;
24 import java.util.List;
25 import java.util.concurrent.CopyOnWriteArrayList;
26 import java.util.concurrent.Executor;
28 import org.eclipse.jetty.io.ByteBufferPool;
29 import org.eclipse.jetty.io.NetworkTrafficListener;
30 import org.eclipse.jetty.io.NetworkTrafficSelectChannelEndPoint;
31 import org.eclipse.jetty.io.SelectChannelEndPoint;
32 import org.eclipse.jetty.io.SelectorManager;
33 import org.eclipse.jetty.util.ssl.SslContextFactory;
34 import org.eclipse.jetty.util.thread.Scheduler;
37 * <p>A specialized version of {@link ServerConnector} that supports {@link NetworkTrafficListener}s.</p>
38 * <p>{@link NetworkTrafficListener}s can be added and removed dynamically before and after this connector has
39 * been started without causing {@link java.util.ConcurrentModificationException}s.</p>
41 public class NetworkTrafficServerConnector extends ServerConnector
43 private final List<NetworkTrafficListener> listeners = new CopyOnWriteArrayList<>();
45 public NetworkTrafficServerConnector(Server server)
47 this(server, null, null, null, 0, 0, new HttpConnectionFactory());
50 public NetworkTrafficServerConnector(Server server, ConnectionFactory connectionFactory, SslContextFactory sslContextFactory)
52 super(server, sslContextFactory, connectionFactory);
55 public NetworkTrafficServerConnector(Server server, ConnectionFactory connectionFactory)
57 super(server, connectionFactory);
60 public NetworkTrafficServerConnector(Server server, Executor executor, Scheduler scheduler, ByteBufferPool pool, int acceptors, int selectors, ConnectionFactory... factories)
62 super(server, executor, scheduler, pool, acceptors, selectors, factories);
65 public NetworkTrafficServerConnector(Server server, SslContextFactory sslContextFactory)
67 super(server, sslContextFactory);
71 * @param listener the listener to add
73 public void addNetworkTrafficListener(NetworkTrafficListener listener)
75 listeners.add(listener);
79 * @param listener the listener to remove
81 public void removeNetworkTrafficListener(NetworkTrafficListener listener)
83 listeners.remove(listener);
87 protected SelectChannelEndPoint newEndPoint(SocketChannel channel, SelectorManager.ManagedSelector selectSet, SelectionKey key) throws IOException
89 NetworkTrafficSelectChannelEndPoint endPoint = new NetworkTrafficSelectChannelEndPoint(channel, selectSet, key, getScheduler(), getIdleTimeout(), listeners);