Class NIOTransport

    • Field Detail

      • DEFAULT_SERVER_SOCKET_SO_TIMEOUT

        public static final int DEFAULT_SERVER_SOCKET_SO_TIMEOUT
        See Also:
        Constant Field Values
      • DEFAULT_REUSE_ADDRESS

        public static final boolean DEFAULT_REUSE_ADDRESS
        See Also:
        Constant Field Values
      • DEFAULT_CLIENT_SOCKET_SO_TIMEOUT

        public static final int DEFAULT_CLIENT_SOCKET_SO_TIMEOUT
        See Also:
        Constant Field Values
      • DEFAULT_CONNECTION_TIMEOUT

        public static final int DEFAULT_CONNECTION_TIMEOUT
        See Also:
        Constant Field Values
      • DEFAULT_SELECTOR_RUNNER_COUNT

        public static final int DEFAULT_SELECTOR_RUNNER_COUNT
        See Also:
        Constant Field Values
      • DEFAULT_OPTIMIZED_FOR_MULTIPLEXING

        public static final boolean DEFAULT_OPTIMIZED_FOR_MULTIPLEXING
        See Also:
        Constant Field Values
      • selectorProvider

        protected java.nio.channels.spi.SelectorProvider selectorProvider
      • shutdownFuture

        protected FutureImpl<Transport> shutdownFuture
        Future to control graceful shutdown status
      • shutdownService

        protected java.util.concurrent.ExecutorService shutdownService
        ExecutorService hosting shutdown listener threads.
    • Constructor Detail

      • NIOTransport

        public NIOTransport​(java.lang.String name)
    • Method Detail

      • addShutdownListener

        public boolean addShutdownListener​(GracefulShutdownListener shutdownListener)
        Description copied from interface: Transport
        Adds a GracefulShutdownListener which will be called when Transport.shutdown() is called to enable graceful shutdown of transports. This allows the owner of the listener to signal that all shutdown tasks are complete and that it's safe to finalize the termination of the transport
        Specified by:
        addShutdownListener in interface Transport
        Parameters:
        shutdownListener - the GracefulShutdownListener
        Returns:
        true if the listener was successfully registered, otherwise false. When this method returns false it means one of two things: the transport is stopping or is stopped, or the listener has already been registered.
      • setSelectionKeyHandler

        public void setSelectionKeyHandler​(SelectionKeyHandler selectionKeyHandler)
      • setSelectorHandler

        public void setSelectorHandler​(SelectorHandler selectorHandler)
      • getChannelConfigurator

        public ChannelConfigurator getChannelConfigurator()
        Returns:
        the configurator responsible for initial SelectableChannel configuration
      • setChannelConfigurator

        public void setChannelConfigurator​(ChannelConfigurator channelConfigurator)
        Sets the configurator responsible for initial SelectableChannel configuration.
        Parameters:
        channelConfigurator - ChannelConfigurator
      • getSelectorRunnersCount

        public int getSelectorRunnersCount()
        Returns:
        the number of SelectorRunners used for handling NIO events
      • setSelectorRunnersCount

        public void setSelectorRunnersCount​(int selectorRunnersCount)
        Sets the number of SelectorRunners used for handling NIO events.
        Parameters:
        selectorRunnersCount -
      • getSelectorProvider

        public java.nio.channels.spi.SelectorProvider getSelectorProvider()
        Get the SelectorProvider to be used by this transport.
        Returns:
        the SelectorProvider to be used by this transport.
      • setSelectorProvider

        public void setSelectorProvider​(java.nio.channels.spi.SelectorProvider selectorProvider)
        Set the SelectorProvider to be used by this transport.
        Parameters:
        selectorProvider - the SelectorProvider.
      • isOptimizedForMultiplexing

        public boolean isOptimizedForMultiplexing()
        Returns true, if NIOTransport is configured to use AsyncQueueWriter, optimized to be used in connection multiplexing mode, or false otherwise.
        Returns:
        true, if NIOTransport is configured to use AsyncQueueWriter, optimized to be used in connection multiplexing mode, or false otherwise.
      • setOptimizedForMultiplexing

        public void setOptimizedForMultiplexing​(boolean optimizedForMultiplexing)
        Configures NIOTransport to be optimized for specific for the connection multiplexing usecase, when different threads will try to write data simultaneously.
      • startSelectorRunners

        protected void startSelectorRunners()
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • stopSelectorRunners

        protected void stopSelectorRunners()
      • setNIOChannelDistributor

        public void setNIOChannelDistributor​(NIOChannelDistributor nioChannelDistributor)
      • notifyTransportError

        public void notifyTransportError​(java.lang.Throwable error)
        Method gets invoked, when error occur during the Transport lifecycle.
        Specified by:
        notifyTransportError in interface Transport
        Parameters:
        error - Throwable.
      • getSelectorRunners

        protected SelectorRunner[] getSelectorRunners()
      • notifyProbesError

        protected static void notifyProbesError​(NIOTransport transport,
                                                java.lang.Throwable error)
        Notify registered TransportProbes about the error.
        Parameters:
        transport - the Transport event occurred on.
      • notifyProbesStart

        protected static void notifyProbesStart​(NIOTransport transport)
        Notify registered TransportProbes about the start event.
        Parameters:
        transport - the Transport event occurred on.
      • notifyProbesStop

        protected static void notifyProbesStop​(NIOTransport transport)
        Notify registered TransportProbes about the stop event.
        Parameters:
        transport - the Transport event occurred on.
      • notifyProbesPause

        protected static void notifyProbesPause​(NIOTransport transport)
        Notify registered TransportProbes about the pause event.
        Parameters:
        transport - the Transport event occurred on.
      • notifyProbesResume

        protected static void notifyProbesResume​(NIOTransport transport)
        Notify registered TransportProbes about the resume event.
        Parameters:
        transport - the Transport event occurred on.
      • start

        public void start()
                   throws java.io.IOException
        Start TCPNIOTransport.

        The transport will be started only if its current state is Transport.State.STOPPED, otherwise the call will be ignored without exception thrown and the transport state will remain the same as it was before the method call.

        Specified by:
        start in interface Transport
        Throws:
        java.io.IOException - if an attempt was made to actually start which failed
      • shutdown

        public GrizzlyFuture<Transport> shutdown()
        Description copied from interface: Transport
        Gracefully stops the transport accepting new connections and allows existing work to complete before finalizing the shutdown. This method will wait indefinitely for all interested parties to signal it is safe to terminate the transport. Invoke Transport.shutdownNow() to terminate the transport if the graceful shutdown is taking too long.
        Specified by:
        shutdown in interface Transport
        Returns:
        a GrizzlyFuture which will return the stopped transport.
        See Also:
        GracefulShutdownListener
      • shutdown

        public GrizzlyFuture<Transport> shutdown​(long gracePeriod,
                                                 java.util.concurrent.TimeUnit timeUnit)
        Gracefully stops the transport accepting new connections and allows existing work to complete before finalizing the shutdown. This method will wait for the specified time for all interested parties to signal it is safe to terminate the transport. If the timeout is exceeded, the transport will be terminated forcefully.
        Specified by:
        shutdown in interface Transport
        Parameters:
        gracePeriod - the grace period for a graceful shutdown before the transport is forcibly terminated. If gracePeriod is zero or less, then there is no time limit for the shutdown.
        timeUnit - the TimeUnit of the specified grace period.
        Returns:
        a GrizzlyFuture which will return the stopped transport.
      • shutdownNow

        public void shutdownNow()
                         throws java.io.IOException
        Forcibly stops the transport and closes all connections.
        Specified by:
        shutdownNow in interface Transport
        Throws:
        java.io.IOException - if there was an error shutting down
        See Also:
        to complete gracefully
      • createTemporarySelectorIO

        protected abstract TemporarySelectorIO createTemporarySelectorIO()
      • listen

        protected abstract void listen()
      • getDefaultSelectorRunnersCount

        protected int getDefaultSelectorRunnersCount()
      • finalizeShutdown

        protected void finalizeShutdown()
      • pause

        public void pause()
        Pause UDPNIOTransport, so I/O events coming on its UDPNIOConnections will not be processed. Use resume() in order to resume UDPNIOTransport processing. The transport will be paused only if its current state is Transport.State.STARTED, otherwise the call will be ignored without exception thrown and the transport state will remain the same as it was before the method call.
        Specified by:
        pause in interface Transport
      • resume

        public void resume()
        Resume UDPNIOTransport, which has been paused before using pause(). The transport will be resumed only if its current state is Transport.State.PAUSED, otherwise the call will be ignored without exception thrown and the transport state will remain the same as it was before the method call.
        Specified by:
        resume in interface Transport
      • configureNIOConnection

        protected void configureNIOConnection​(NIOConnection connection)
      • isReuseAddress

        public boolean isReuseAddress()
      • setReuseAddress

        public void setReuseAddress​(boolean reuseAddress)
      • getClientSocketSoTimeout

        public int getClientSocketSoTimeout()
      • setClientSocketSoTimeout

        public void setClientSocketSoTimeout​(int socketTimeout)
      • getConnectionTimeout

        public int getConnectionTimeout()
      • setConnectionTimeout

        public void setConnectionTimeout​(int connectionTimeout)
      • getServerSocketSoTimeout

        public int getServerSocketSoTimeout()
      • setServerSocketSoTimeout

        public void setServerSocketSoTimeout​(int serverSocketSoTimeout)
      • createShutdownExecutorService

        protected java.util.concurrent.ExecutorService createShutdownExecutorService()