Class NIOTransport

java.lang.Object
org.glassfish.grizzly.AbstractTransport
org.glassfish.grizzly.nio.NIOTransport
All Implemented Interfaces:
AsyncQueueEnabledTransport, ConnectorHandler<SocketAddress>, MonitoringAware<TransportProbe>, TemporarySelectorsEnabledTransport, SocketBinder, SocketConnectorHandler, Transport
Direct Known Subclasses:
TCPNIOTransport, UDPNIOTransport

Author:
oleksiys
  • Field Details

  • Constructor Details

    • NIOTransport

      public NIOTransport(String name)
  • Method Details

    • unbindAll

      public abstract void unbindAll()
      Description copied from interface: SocketBinder
      Unbinds all bound Transport connections.
      Specified by:
      unbindAll in interface SocketBinder
    • 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.
    • getTemporarySelectorIO

      public TemporarySelectorIO getTemporarySelectorIO()
      Specified by:
      getTemporarySelectorIO in interface TemporarySelectorsEnabledTransport
    • getSelectionKeyHandler

      public SelectionKeyHandler getSelectionKeyHandler()
    • setSelectionKeyHandler

      public void setSelectionKeyHandler(SelectionKeyHandler selectionKeyHandler)
    • getSelectorHandler

      public SelectorHandler getSelectorHandler()
    • 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 SelectorProvider getSelectorProvider()
      Get the SelectorProvider to be used by this transport.
      Returns:
      the SelectorProvider to be used by this transport.
    • setSelectorProvider

      public void setSelectorProvider(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 IOException
      Throws:
      IOException
    • stopSelectorRunners

      protected void stopSelectorRunners()
    • getNIOChannelDistributor

      public NIOChannelDistributor getNIOChannelDistributor()
    • 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:
    • 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.
    • shutdownNow

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

      protected abstract void closeConnection(Connection connection) throws IOException
      Description copied from class: AbstractTransport
      Close the connection, managed by Transport
      Specified by:
      closeConnection in class AbstractTransport
      Parameters:
      connection - NIOConnection to close
      Throws:
      IOException - not used
    • 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()