Class NIOTransport

    • Constructor Detail

      • NIOTransport

        public NIOTransport​(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)
      • 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 -
      • 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.
      • stopSelectorRunners

        protected void stopSelectorRunners()
      • setNIOChannelDistributor

        public void setNIOChannelDistributor​(NIOChannelDistributor nioChannelDistributor)
      • notifyTransportError

        public void notifyTransportError​(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,
                                                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 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:
        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,
                                                 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.
      • 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 ExecutorService createShutdownExecutorService()