Class SelectorManager

  • All Implemented Interfaces:
    org.eclipse.jetty.util.component.Container, org.eclipse.jetty.util.component.Destroyable, org.eclipse.jetty.util.component.Dumpable, org.eclipse.jetty.util.component.LifeCycle

    @ManagedObject("Manager of the NIO Selectors")
    public abstract class SelectorManager
    extends org.eclipse.jetty.util.component.ContainerLifeCycle
    implements org.eclipse.jetty.util.component.Dumpable

    SelectorManager manages a number of ManagedSelectors that simplify the non-blocking primitives provided by the JVM via the java.nio package.

    SelectorManager subclasses implement methods to return protocol-specific EndPoints and Connections.

    • Field Detail

      • DEFAULT_CONNECT_TIMEOUT

        public static final int DEFAULT_CONNECT_TIMEOUT
        See Also:
        Constant Field Values
      • LOG

        protected static final org.eclipse.jetty.util.log.Logger LOG
    • Constructor Detail

      • SelectorManager

        protected SelectorManager​(Executor executor,
                                  org.eclipse.jetty.util.thread.Scheduler scheduler)
      • SelectorManager

        protected SelectorManager​(Executor executor,
                                  org.eclipse.jetty.util.thread.Scheduler scheduler,
                                  int selectors)
        Parameters:
        executor - The executor to use for handling selected EndPoints
        scheduler - The scheduler to use for timing events
        selectors - The number of selectors to use, or -1 for a default derived from a heuristic over available CPUs and thread pool size.
    • Method Detail

      • getExecutor

        @ManagedAttribute("The Executor")
        public Executor getExecutor()
      • getScheduler

        @ManagedAttribute("The Scheduler")
        public org.eclipse.jetty.util.thread.Scheduler getScheduler()
      • getConnectTimeout

        @ManagedAttribute("The Connection timeout (ms)")
        public long getConnectTimeout()
        Get the connect timeout
        Returns:
        the connect timeout (in milliseconds)
      • setConnectTimeout

        public void setConnectTimeout​(long milliseconds)
        Set the connect timeout (in milliseconds)
        Parameters:
        milliseconds - the number of milliseconds for the timeout
      • getReservedThreads

        @Deprecated
        public int getReservedThreads()
        Deprecated.
        Returns:
        -1
      • setReservedThreads

        @Deprecated
        public void setReservedThreads​(int threads)
        Deprecated.
        Parameters:
        threads - ignored
      • execute

        protected void execute​(Runnable task)
        Executes the given task in a different thread.
        Parameters:
        task - the task to execute
      • getSelectorCount

        @ManagedAttribute("The number of NIO Selectors")
        public int getSelectorCount()
        Returns:
        the number of selectors in use
      • acceptor

        public Closeable acceptor​(SelectableChannel server)

        Registers a server channel for accept operations. When a SocketChannel is accepted from the given ServerSocketChannel then the accepted(SelectableChannel) method is called, which must be overridden by a derivation of this class to handle the accepted channel

        Parameters:
        server - the server channel to register
        Returns:
        A Closable that allows the acceptor to be cancelled
      • doStart

        protected void doStart()
                        throws Exception
        Overrides:
        doStart in class org.eclipse.jetty.util.component.ContainerLifeCycle
        Throws:
        Exception
      • doStop

        protected void doStop()
                       throws Exception
        Overrides:
        doStop in class org.eclipse.jetty.util.component.ContainerLifeCycle
        Throws:
        Exception
      • endPointOpened

        protected void endPointOpened​(EndPoint endpoint)

        Callback method invoked when an endpoint is opened.

        Parameters:
        endpoint - the endpoint being opened
      • endPointClosed

        protected void endPointClosed​(EndPoint endpoint)

        Callback method invoked when an endpoint is closed.

        Parameters:
        endpoint - the endpoint being closed
      • connectionOpened

        public void connectionOpened​(Connection connection)

        Callback method invoked when a connection is opened.

        Parameters:
        connection - the connection just opened
      • connectionClosed

        public void connectionClosed​(Connection connection)

        Callback method invoked when a connection is closed.

        Parameters:
        connection - the connection just closed
      • isConnectionPending

        protected boolean isConnectionPending​(SelectableChannel channel)
      • connectionFailed

        protected void connectionFailed​(SelectableChannel channel,
                                        Throwable ex,
                                        Object attachment)

        Callback method invoked when a non-blocking connect cannot be completed.

        By default it just logs with level warning.

        Parameters:
        channel - the channel that attempted the connect
        ex - the exception that caused the connect to fail
        attachment - the attachment object associated at registration
      • newConnection

        public abstract Connection newConnection​(SelectableChannel channel,
                                                 EndPoint endpoint,
                                                 Object attachment)
                                          throws IOException

        Factory method to create Connection.

        Parameters:
        channel - the channel associated to the connection
        endpoint - the endpoint
        attachment - the attachment
        Returns:
        a new connection
        Throws:
        IOException - if unable to create new connection
      • addEventListener

        public void addEventListener​(EventListener listener)
      • removeEventListener

        public void removeEventListener​(EventListener listener)