Class AbstractIoService

java.lang.Object
org.apache.mina.core.service.AbstractIoService
All Implemented Interfaces:
IoService
Direct Known Subclasses:
AbstractIoAcceptor, AbstractIoConnector

public abstract class AbstractIoService extends Object implements IoService
Base implementation of IoServices. An instance of IoService contains an Executor which will handle the incoming events.
  • Field Details

    • LOGGER

      protected static final org.slf4j.Logger LOGGER
    • id

      private static final AtomicInteger id
      The unique number identifying the Service. It's incremented for each new IoService created.
    • threadName

      private final String threadName
      The thread name built from the IoService inherited instance class name and the IoService Id
    • executor

      private final Executor executor
      The associated executor, responsible for handling execution of I/O events.
    • createdExecutor

      private final boolean createdExecutor
      A flag used to indicate that the local executor has been created inside this instance, and not passed by a caller. If the executor is locally created, then it will be an instance of the ThreadPoolExecutor class.
    • handler

      private IoHandler handler
      The IoHandler in charge of managing all the I/O Events. It is
    • sessionConfig

      protected final IoSessionConfig sessionConfig
      The default IoSessionConfig which will be used to configure new sessions.
    • serviceActivationListener

      private final IoServiceListener serviceActivationListener
    • filterChainBuilder

      private IoFilterChainBuilder filterChainBuilder
      Current filter chain builder.
    • sessionDataStructureFactory

      private IoSessionDataStructureFactory sessionDataStructureFactory
    • listeners

      private final IoServiceListenerSupport listeners
      Maintains the IoServiceListeners of this service.
    • disposalLock

      protected final Object disposalLock
      A lock object which must be acquired when related resources are destroyed.
    • disposing

      private volatile boolean disposing
    • disposed

      private volatile boolean disposed
    • stats

      private final IoServiceStatistics stats
  • Constructor Details

  • Method Details

    • getFilterChainBuilder

      public final IoFilterChainBuilder getFilterChainBuilder()
      Specified by:
      getFilterChainBuilder in interface IoService
      Returns:
      the IoFilterChainBuilder which will build the IoFilterChain of all IoSessions which is created by this service. The default value is an empty DefaultIoFilterChainBuilder.
    • setFilterChainBuilder

      public final void setFilterChainBuilder(IoFilterChainBuilder builder)
      Sets the IoFilterChainBuilder which will build the IoFilterChain of all IoSessions which is created by this service. If you specify null this property will be set to an empty DefaultIoFilterChainBuilder.
      Specified by:
      setFilterChainBuilder in interface IoService
      Parameters:
      builder - The filter chain builder to use
    • getFilterChain

      public final DefaultIoFilterChainBuilder getFilterChain()
      A shortcut for ( ( DefaultIoFilterChainBuilder ) IoService.getFilterChainBuilder() ). Please note that the returned object is not a real IoFilterChain but a DefaultIoFilterChainBuilder. Modifying the returned builder won't affect the existing IoSessions at all, because IoFilterChainBuilders affect only newly created IoSessions.
      Specified by:
      getFilterChain in interface IoService
      Returns:
      The filter chain in use
    • addListener

      public final void addListener(IoServiceListener listener)
      Adds an IoServiceListener that listens any events related with this service.
      Specified by:
      addListener in interface IoService
      Parameters:
      listener - The listener to add
    • removeListener

      public final void removeListener(IoServiceListener listener)
      Removed an existing IoServiceListener that listens any events related with this service.
      Specified by:
      removeListener in interface IoService
      Parameters:
      listener - The listener to use
    • isActive

      public final boolean isActive()
      Specified by:
      isActive in interface IoService
      Returns:
      a value of whether or not this service is active
    • isDisposing

      public final boolean isDisposing()
      Specified by:
      isDisposing in interface IoService
      Returns:
      true if and if only IoService.dispose() method has been called. Please note that this method will return true even after all the related resources are released.
    • isDisposed

      public final boolean isDisposed()
      Specified by:
      isDisposed in interface IoService
      Returns:
      true if and if only all resources of this processor have been disposed.
    • dispose

      public final void dispose()
      Releases any resources allocated by this service. Please note that this method might block as long as there are any sessions managed by this service.
      Specified by:
      dispose in interface IoService
    • dispose

      public final void dispose(boolean awaitTermination)
      Releases any resources allocated by this service. Please note that this method might block as long as there are any sessions managed by this service. Warning : calling this method from a IoFutureListener with awaitTermination = true will probably lead to a deadlock.
      Specified by:
      dispose in interface IoService
      Parameters:
      awaitTermination - When true this method will block until the underlying ExecutorService is terminated
    • dispose0

      protected abstract void dispose0() throws Exception
      Implement this method to release any acquired resources. This method is invoked only once by dispose().
      Throws:
      Exception - If the dispose failed
    • getManagedSessions

      public final Map<Long, IoSession> getManagedSessions()
      Specified by:
      getManagedSessions in interface IoService
      Returns:
      the map of all sessions which are currently managed by this service. The key of map is the ID of the session. An empty collection if there's no session.
    • getManagedSessionCount

      public final int getManagedSessionCount()
      Specified by:
      getManagedSessionCount in interface IoService
      Returns:
      the number of all sessions which are currently managed by this service.
    • getHandler

      public final IoHandler getHandler()
      Specified by:
      getHandler in interface IoService
      Returns:
      the handler which will handle all connections managed by this service.
    • setHandler

      public final void setHandler(IoHandler handler)
      Sets the handler which will handle all connections managed by this service.
      Specified by:
      setHandler in interface IoService
      Parameters:
      handler - The IoHandler to use
    • getSessionDataStructureFactory

      public final IoSessionDataStructureFactory getSessionDataStructureFactory()
      Specified by:
      getSessionDataStructureFactory in interface IoService
      Returns:
      the IoSessionDataStructureFactory that provides related data structures for a new session created by this service.
    • setSessionDataStructureFactory

      public final void setSessionDataStructureFactory(IoSessionDataStructureFactory sessionDataStructureFactory)
      Sets the IoSessionDataStructureFactory that provides related data structures for a new session created by this service.
      Specified by:
      setSessionDataStructureFactory in interface IoService
      Parameters:
      sessionDataStructureFactory - The factory to use
    • getStatistics

      public IoServiceStatistics getStatistics()
      Specified by:
      getStatistics in interface IoService
      Returns:
      The statistics object for this service.
    • getActivationTime

      public final long getActivationTime()
      Specified by:
      getActivationTime in interface IoService
      Returns:
      the time when this service was activated. It returns the last time when this service was activated if the service is not active now.
    • broadcast

      public final Set<WriteFuture> broadcast(Object message)
      Writes the specified message to all the IoSessions managed by this service. This method is a convenience shortcut for IoUtil.broadcast(Object, Collection).
      Specified by:
      broadcast in interface IoService
      Parameters:
      message - the message to broadcast
      Returns:
      The set of WriteFuture associated to the message being broadcasted
    • getListeners

      public final IoServiceListenerSupport getListeners()
      Returns:
      The IoServiceListenerSupport attached to this service
    • executeWorker

      protected final void executeWorker(Runnable worker)
    • executeWorker

      protected final void executeWorker(Runnable worker, String suffix)
    • initSession

      protected final void initSession(IoSession session, IoFuture future, IoSessionInitializer sessionInitializer)
    • finishSessionInitialization0

      protected void finishSessionInitialization0(IoSession session, IoFuture future)
      Implement this method to perform additional tasks required for session initialization. Do not call this method directly; initSession(IoSession, IoFuture, IoSessionInitializer) will call this method instead.
      Parameters:
      session - The session to initialize
      future - The Future to use
    • getScheduledWriteBytes

      public int getScheduledWriteBytes()
      Specified by:
      getScheduledWriteBytes in interface IoService
      Returns:
      The number of bytes scheduled to be written
    • getScheduledWriteMessages

      public int getScheduledWriteMessages()
      Specified by:
      getScheduledWriteMessages in interface IoService
      Returns:
      The number of messages scheduled to be written