Class NioDatagramAcceptor

    • Constructor Detail

      • NioDatagramAcceptor

        public NioDatagramAcceptor()
        Creates a new instance.
      • NioDatagramAcceptor

        public NioDatagramAcceptor​(java.util.concurrent.Executor executor)
        Creates a new instance.
        Parameters:
        executor - The executor to use
    • Method Detail

      • init

        protected void init()
                     throws java.lang.Exception
        Throws:
        java.lang.Exception
      • add

        public void add​(NioSession session)
        Adds the specified session to the I/O processor so that the I/O processor starts to perform any I/O operations related with the session.
        Specified by:
        add in interface IoProcessor<NioSession>
        Parameters:
        session - The added session
      • bindInternal

        protected final java.util.Set<java.net.SocketAddress> bindInternal​(java.util.List<? extends java.net.SocketAddress> localAddresses)
                                                                    throws java.lang.Exception
        Starts the acceptor, and register the given addresses
        Specified by:
        bindInternal in class AbstractIoAcceptor
        Parameters:
        localAddresses - The address to bind to
        Returns:
        the Set of the local addresses which is bound actually
        Throws:
        java.lang.Exception - If the bind failed
      • close

        protected void close​(java.nio.channels.DatagramChannel handle)
                      throws java.lang.Exception
        Throws:
        java.lang.Exception
      • destroy

        protected void destroy()
                        throws java.lang.Exception
        Throws:
        java.lang.Exception
      • dispose0

        protected void dispose0()
                         throws java.lang.Exception
        Implement this method to release any acquired resources. This method is invoked only once by AbstractIoService.dispose().
        Specified by:
        dispose0 in class AbstractIoService
        Throws:
        java.lang.Exception - If the dispose failed
      • flush

        public void flush​(NioSession session)
        Flushes the internal write request queue of the specified session.
        Specified by:
        flush in interface IoProcessor<NioSession>
        Parameters:
        session - The session we want the message to be written
      • isReadable

        protected boolean isReadable​(java.nio.channels.DatagramChannel handle)
      • isWritable

        protected boolean isWritable​(java.nio.channels.DatagramChannel handle)
      • localAddress

        protected java.net.SocketAddress localAddress​(java.nio.channels.DatagramChannel handle)
                                               throws java.lang.Exception
        Throws:
        java.lang.Exception
      • newSession

        protected NioSession newSession​(IoProcessor<NioSession> processor,
                                        java.nio.channels.DatagramChannel handle,
                                        java.net.SocketAddress remoteAddress)
      • newSession

        public final IoSession newSession​(java.net.SocketAddress remoteAddress,
                                          java.net.SocketAddress localAddress)
        (Optional) Returns an IoSession that is bound to the specified localAddress and the specified remoteAddress which reuses the local address that is already bound by this service.

        This operation is optional. Please throw UnsupportedOperationException if the transport type doesn't support this operation. This operation is usually implemented for connectionless transport types.

        Specified by:
        newSession in interface IoAcceptor
        Parameters:
        remoteAddress - The remote address bound to the service
        localAddress - The local address the session will be bound to
        Returns:
        The session bound to the the given localAddress and remote address
      • open

        protected java.nio.channels.DatagramChannel open​(java.net.SocketAddress localAddress)
                                                  throws java.lang.Exception
        Throws:
        java.lang.Exception
      • receive

        protected java.net.SocketAddress receive​(java.nio.channels.DatagramChannel handle,
                                                 IoBuffer buffer)
                                          throws java.lang.Exception
        Throws:
        java.lang.Exception
      • remove

        public void remove​(NioSession session)
        Removes and closes the specified session from the I/O processor so that the I/O processor closes the connection associated with the session and releases any other related resources.
        Specified by:
        remove in interface IoProcessor<NioSession>
        Parameters:
        session - The session to be removed
      • select

        protected int select()
                      throws java.lang.Exception
        Throws:
        java.lang.Exception
      • select

        protected int select​(long timeout)
                      throws java.lang.Exception
        Throws:
        java.lang.Exception
      • selectedHandles

        protected java.util.Set<java.nio.channels.SelectionKey> selectedHandles()
      • send

        protected int send​(NioSession session,
                           IoBuffer buffer,
                           java.net.SocketAddress remoteAddress)
                    throws java.lang.Exception
        Throws:
        java.lang.Exception
      • setInterestedInWrite

        protected void setInterestedInWrite​(NioSession session,
                                            boolean isInterested)
                                     throws java.lang.Exception
        Throws:
        java.lang.Exception
      • unbind0

        protected final void unbind0​(java.util.List<? extends java.net.SocketAddress> localAddresses)
                              throws java.lang.Exception
        Implement this method to perform the actual unbind operation.
        Specified by:
        unbind0 in class AbstractIoAcceptor
        Parameters:
        localAddresses - The address to unbind from
        Throws:
        java.lang.Exception - If the unbind failed
      • wakeup

        protected void wakeup()
      • write

        public void write​(NioSession session,
                          WriteRequest writeRequest)
        Writes the WriteRequest for the specified session.
        Specified by:
        write in interface IoProcessor<NioSession>
        Parameters:
        session - The session we want the message to be written
        writeRequest - the WriteRequest to write