Class AbstractIoService

    • Field Detail

      • LOGGER

        protected static final org.slf4j.Logger LOGGER
      • disposalLock

        protected final java.lang.Object disposalLock
        A lock object which must be acquired when related resources are destroyed.
    • Constructor Detail

      • AbstractIoService

        protected AbstractIoService​(IoSessionConfig sessionConfig,
                                    java.util.concurrent.Executor executor)
        Constructor for AbstractIoService. You need to provide a default session configuration and an Executor for handling I/O events. If a null Executor is provided, a default one will be created using Executors.newCachedThreadPool().
        Parameters:
        sessionConfig - the default configuration for the managed IoSession
        executor - the Executor used for handling execution of I/O events. Can be null.
    • Method Detail

      • 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 java.lang.Exception
        Implement this method to release any acquired resources. This method is invoked only once by dispose().
        Throws:
        java.lang.Exception - If the dispose failed
      • getManagedSessions

        public final java.util.Map<java.lang.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
      • 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 java.util.Set<WriteFuture> broadcast​(java.lang.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
      • executeWorker

        protected final void executeWorker​(java.lang.Runnable worker)
      • executeWorker

        protected final void executeWorker​(java.lang.Runnable worker,
                                           java.lang.String suffix)
      • 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