// Path: src/android/org/eclipse/jetty/io/ConnectedEndPoint.java
// public interface ConnectedEndPoint extends EndPoint
// {
//     Connection getConnection();
//     void setConnection(Connection connection);
// }
// 
// Path: src/android/org/eclipse/jetty/io/Connection.java
// public interface Connection
// {
//     /* ------------------------------------------------------------ */
//     /**
//      * Handle the connection.
//      * @return The Connection to use for the next handling of the connection.
//      * This allows protocol upgrades and support for CONNECT.
//      * @throws IOException if the handling of I/O operations fail
//      */
//     Connection handle() throws IOException;
// 
//     /**
//      * <p>The semantic of this method is to return true to indicate interest in further reads,
//      * or false otherwise, but it is misnamed and should be really called <code>isReadInterested()</code>.</p>
//      *
//      * @return true to indicate interest in further reads, false otherwise
//      */
//     // TODO: rename to isReadInterested() in the next release
//     boolean isSuspended();
// 
//     /**
//      * Called after the connection is closed
//      */
//     void onClose();
// 
//     /**
//      * Called when the connection idle timeout expires
//      * @param idleForMs how long the connection has been idle
//      * @see #isIdle()
//      */
//     void onIdleExpired(long idleForMs);
// }
// 
// Path: src/android/org/eclipse/jetty/util/log/Logger.java
// public interface Logger
// {
//     /**
//      * @return the name of this logger
//      */
//     public String getName();
// 
//     /**
//      * Formats and logs at warn level.
//      * @param msg the formatting string
//      * @param args the optional arguments
//      */
//     public void warn(String msg, Object... args);
// 
//     /**
//      * Logs the given Throwable information at warn level
//      * @param thrown the Throwable to log
//      */
//     public void warn(Throwable thrown);
// 
//     /**
//      * Logs the given message at warn level, with Throwable information.
//      * @param msg the message to log
//      * @param thrown the Throwable to log
//      */
//     public void warn(String msg, Throwable thrown);
// 
//     /**
//      * Formats and logs at info level.
//      * @param msg the formatting string
//      * @param args the optional arguments
//      */
//     public void info(String msg, Object... args);
// 
//     /**
//      * Logs the given Throwable information at info level
//      * @param thrown the Throwable to log
//      */
//     public void info(Throwable thrown);
// 
//     /**
//      * Logs the given message at info level, with Throwable information.
//      * @param msg the message to log
//      * @param thrown the Throwable to log
//      */
//     public void info(String msg, Throwable thrown);
// 
//     /**
//      * @return whether the debug level is enabled
//      */
//     public boolean isDebugEnabled();
// 
//     /**
//      * Mutator used to turn debug on programmatically.
//      * @param enabled whether to enable the debug level
//      */
//     public void setDebugEnabled(boolean enabled);
// 
//     /**
//      * Formats and logs at debug level.
//      * @param msg the formatting string
//      * @param args the optional arguments
//      */
//     public void debug(String msg, Object... args);
// 
//     /**
//      * Logs the given Throwable information at debug level
//      * @param thrown the Throwable to log
//      */
//     public void debug(Throwable thrown);
// 
//     /**
//      * Logs the given message at debug level, with Throwable information.
//      * @param msg the message to log
//      * @param thrown the Throwable to log
//      */
//     public void debug(String msg, Throwable thrown);
// 
//     /**
//      * @param name the name of the logger
//      * @return a logger with the given name
//      */
//     public Logger getLogger(String name);
//     
//     /**
//      * Ignore an exception.
//      * <p>This should be used rather than an empty catch block.
//      */
//     public void ignore(Throwable ignored); 
// }


import java.io.IOException;
import java.nio.channels.CancelledKeyException;
import java.nio.channels.Channel;
import java.nio.channels.ClosedSelectorException;
import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.io.AsyncEndPoint;
import org.eclipse.jetty.io.ConnectedEndPoint;
import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.component.AggregateLifeCycle;
import org.eclipse.jetty.util.component.Dumpable;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.thread.Timeout;
import org.eclipse.jetty.util.thread.Timeout.Task;
    /* ------------------------------------------------------------------------------- */
    @Override
    protected void doStop() throws Exception
    {
        SelectSet[] sets= _selectSet;
        _selectSet=null;
        if (sets!=null)
        {
            for (SelectSet set : sets)
            {
                if (set!=null)
                    set.stop();
            }
        }
        super.doStop();
    }

    /* ------------------------------------------------------------ */
    /**
     * @param endpoint
     */
    protected abstract void endPointClosed(SelectChannelEndPoint endpoint);

    /* ------------------------------------------------------------ */
    /**
     * @param endpoint
     */
    protected abstract void endPointOpened(SelectChannelEndPoint endpoint);

    /* ------------------------------------------------------------ */
// Path: src/android/org/eclipse/jetty/io/ConnectedEndPoint.java
// public interface ConnectedEndPoint extends EndPoint
// {
//     Connection getConnection();
//     void setConnection(Connection connection);
// }
// 
// Path: src/android/org/eclipse/jetty/io/Connection.java
// public interface Connection
// {
//     /* ------------------------------------------------------------ */
//     /**
//      * Handle the connection.
//      * @return The Connection to use for the next handling of the connection.
//      * This allows protocol upgrades and support for CONNECT.
//      * @throws IOException if the handling of I/O operations fail
//      */
//     Connection handle() throws IOException;
// 
//     /**
//      * <p>The semantic of this method is to return true to indicate interest in further reads,
//      * or false otherwise, but it is misnamed and should be really called <code>isReadInterested()</code>.</p>
//      *
//      * @return true to indicate interest in further reads, false otherwise
//      */
//     // TODO: rename to isReadInterested() in the next release
//     boolean isSuspended();
// 
//     /**
//      * Called after the connection is closed
//      */
//     void onClose();
// 
//     /**
//      * Called when the connection idle timeout expires
//      * @param idleForMs how long the connection has been idle
//      * @see #isIdle()
//      */
//     void onIdleExpired(long idleForMs);
// }
// 
// Path: src/android/org/eclipse/jetty/util/log/Logger.java
// public interface Logger
// {
//     /**
//      * @return the name of this logger
//      */
//     public String getName();
// 
//     /**
//      * Formats and logs at warn level.
//      * @param msg the formatting string
//      * @param args the optional arguments
//      */
//     public void warn(String msg, Object... args);
// 
//     /**
//      * Logs the given Throwable information at warn level
//      * @param thrown the Throwable to log
//      */
//     public void warn(Throwable thrown);
// 
//     /**
//      * Logs the given message at warn level, with Throwable information.
//      * @param msg the message to log
//      * @param thrown the Throwable to log
//      */
//     public void warn(String msg, Throwable thrown);
// 
//     /**
//      * Formats and logs at info level.
//      * @param msg the formatting string
//      * @param args the optional arguments
//      */
//     public void info(String msg, Object... args);
// 
//     /**
//      * Logs the given Throwable information at info level
//      * @param thrown the Throwable to log
//      */
//     public void info(Throwable thrown);
// 
//     /**
//      * Logs the given message at info level, with Throwable information.
//      * @param msg the message to log
//      * @param thrown the Throwable to log
//      */
//     public void info(String msg, Throwable thrown);
// 
//     /**
//      * @return whether the debug level is enabled
//      */
//     public boolean isDebugEnabled();
// 
//     /**
//      * Mutator used to turn debug on programmatically.
//      * @param enabled whether to enable the debug level
//      */
//     public void setDebugEnabled(boolean enabled);
// 
//     /**
//      * Formats and logs at debug level.
//      * @param msg the formatting string
//      * @param args the optional arguments
//      */
//     public void debug(String msg, Object... args);
// 
//     /**
//      * Logs the given Throwable information at debug level
//      * @param thrown the Throwable to log
//      */
//     public void debug(Throwable thrown);
// 
//     /**
//      * Logs the given message at debug level, with Throwable information.
//      * @param msg the message to log
//      * @param thrown the Throwable to log
//      */
//     public void debug(String msg, Throwable thrown);
// 
//     /**
//      * @param name the name of the logger
//      * @return a logger with the given name
//      */
//     public Logger getLogger(String name);
//     
//     /**
//      * Ignore an exception.
//      * <p>This should be used rather than an empty catch block.
//      */
//     public void ignore(Throwable ignored); 
// }


// Path: src/android/org/eclipse/jetty/io/nio/SelectorManager.java
import java.io.IOException;
import java.nio.channels.CancelledKeyException;
import java.nio.channels.Channel;
import java.nio.channels.ClosedSelectorException;
import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.io.AsyncEndPoint;
import org.eclipse.jetty.io.ConnectedEndPoint;
import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.component.AggregateLifeCycle;
import org.eclipse.jetty.util.component.Dumpable;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.thread.Timeout;
import org.eclipse.jetty.util.thread.Timeout.Task;

    /* ------------------------------------------------------------------------------- */
    @Override
    protected void doStop() throws Exception
    {
        SelectSet[] sets= _selectSet;
        _selectSet=null;
        if (sets!=null)
        {
            for (SelectSet set : sets)
            {
                if (set!=null)
                    set.stop();
            }
        }
        super.doStop();
    }

    /* ------------------------------------------------------------ */
    /**
     * @param endpoint
     */
    protected abstract void endPointClosed(SelectChannelEndPoint endpoint);

    /* ------------------------------------------------------------ */
    /**
     * @param endpoint
     */
    protected abstract void endPointOpened(SelectChannelEndPoint endpoint);

    /* ------------------------------------------------------------ */
    protected abstract void endPointUpgraded(ConnectedEndPoint endpoint,Connection oldConnection);