All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.jetty.server.nio.NetworkTrafficSelectChannelConnector Maven / Gradle / Ivy

Go to download

Ehcache is an open source, standards-based cache used to boost performance, offload the database and simplify scalability. Ehcache is robust, proven and full-featured and this has made it the most widely-used Java-based cache.

There is a newer version: 2.10.9.2
Show newest version
//
//  ========================================================================
//  Copyright (c) 1995-2012 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;

/**
 * 

A specialized version of {@link SelectChannelConnector} that supports {@link NetworkTrafficListener}s.

*

{@link NetworkTrafficListener}s can be added and removed dynamically before and after this connector has * been started without causing {@link ConcurrentModificationException}s.

*/ public class NetworkTrafficSelectChannelConnector extends SelectChannelConnector { private final List listeners = new CopyOnWriteArrayList(); /** * @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(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy