Class NetServiceConsumer<S extends NetSession,​D>

    • Method Summary

      Modifier and Type Method Description
      protected void addDecoupledAction​(NetServiceConsumer.DecoupledAction decoupledAction)
      Add a new decoupled action into the queue.
      abstract S checkSession​(S session, D payLoad, NetPackage netPackage)
      Check the channel session.
      protected abstract D decode​(NetPackage netPackage)
      This method decode the net package to obtain the implementation data
      void decoupleIoAction​(java.lang.Integer actionQueueSize, java.lang.Integer workersNumber)
      This method activate the decoupled io actions.
      abstract void destroySession​(NetSession session)
      Destroy the session.
      protected void disconnect​(S session, java.lang.String message)
      Disconnect the specific session.
      protected abstract byte[] encode​(D payLoad)
      This method decode the implementation data.
      java.lang.String getName()
      This method return a name to identify the consumer.
      java.lang.Integer getPort()
      Return the port of the consumer.
      NetService.TransportLayerProtocol getProtocol()
      Return the transport layer protocol of the consumer.
      protected NetService getService()
      Returns the net service instance of the consumer.
      byte[] getShutdownFrame​(S session)
      Returns the shutdown frame to send before the net service shutdown.
      protected D getShutdownPackage​(S session)
      Returns the shutdown package to send before the net service shutdown.
      java.util.Map<java.net.SocketOption,​java.lang.Object> getSocketOptions()
      Return the socket options of the implementation.
      protected javax.net.ssl.SSLEngine getSSLEngine()
      This method should create the ssl engine for the consumer.
      long getWriteWaitForTimeout()
      Return the waiting time to write a package.
      java.lang.Boolean isDecoupledIoAction()  
      protected void onCheckSessionError​(S session, D payLoad, NetPackage netPackage, java.lang.Throwable cause)
      When an exception is occurred while checking session, this method is called to process the package according the exception information.
      void onConnect​(NetPackage netPackage)
      This method abstracts the connection event to use the entities of the domain's implementation.
      protected void onConnect​(S session, D payLoad, NetPackage netPackage)
      Method that must be implemented by the custom implementation to know when a session is connected
      void onDisconnect​(NetPackage netPackage)
      This method abstracts the disconnection event to use the entities of the domain's implementation.
      protected void onDisconnect​(S session, NetPackage netPackage)
      Method must be implemented by the custom implementation to known when a session is disconnected
      void onRead​(NetPackage netPackage)
      When the net service receive data call this method to process the package
      protected void onRead​(S session, D payLoad, NetPackage netPackage)
      When the net service receive data, this method is called to process the package.
      void onWrite​(NetPackage netPackage)
      When the net service write data then call this method to process the package.
      protected void onWrite​(S session, NetPackage netPackage)
      When the net service write data then call this method to process the package.
      void setService​(NetService service)
      This method ser the reference to net service, this method only can be called from the net service that will be associated
      void setWriteWaitForTimeout​(long writeWaitForTimeout)
      Set the waiting time to write a package.
      protected void write​(S session, D payLoad)
      This method writes some data over the session indicated, this operation generate a blocking until the net service confirm that the data was written over the communication channel
      protected void write​(S session, D payLoad, boolean waitFor)
      This method writes some data over the session indicated.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • isDecoupledIoAction

        public final java.lang.Boolean isDecoupledIoAction()
      • decoupleIoAction

        public final void decoupleIoAction​(java.lang.Integer actionQueueSize,
                                           java.lang.Integer workersNumber)
        This method activate the decoupled io actions.
        Parameters:
        actionQueueSize - Size of the actions queue.
        workersNumber - Number of workers to execute the actions.
      • addDecoupledAction

        protected final void addDecoupledAction​(NetServiceConsumer.DecoupledAction decoupledAction)
        Add a new decoupled action into the queue.
        Parameters:
        decoupledAction - Decoupled action instance.
      • getName

        public java.lang.String getName()
        This method return a name to identify the consumer.
        Returns:
        Consumer name.
      • getWriteWaitForTimeout

        public long getWriteWaitForTimeout()
        Return the waiting time to write a package.
        Returns:
        Waiting time to write a apackage.
      • setWriteWaitForTimeout

        public void setWriteWaitForTimeout​(long writeWaitForTimeout)
        Set the waiting time to write a package.
        Parameters:
        writeWaitForTimeout - Waiting time to write a package.
      • setService

        public final void setService​(NetService service)
        This method ser the reference to net service, this method only can be called from the net service that will be associated
        Parameters:
        service - Net service that will be associated.
        Throws:
        java.lang.SecurityException - If the method was called from other method that not is NetService.registerConsumer().
      • getService

        protected final NetService getService()
        Returns the net service instance of the consumer.
        Returns:
        Net service instance.
      • getPort

        public final java.lang.Integer getPort()
        Return the port of the consumer.
        Returns:
        Port.
      • getSSLEngine

        protected javax.net.ssl.SSLEngine getSSLEngine()
        This method should create the ssl engine for the consumer.
        Returns:
        SSL engine implementation.
      • disconnect

        protected final void disconnect​(S session,
                                        java.lang.String message)
        Disconnect the specific session.
        Parameters:
        session - Net session.
        message - Disconnection message.
      • getShutdownFrame

        public final byte[] getShutdownFrame​(S session)
        Returns the shutdown frame to send before the net service shutdown.
        Parameters:
        session - Session to create the shutdown frame.
        Returns:
        Shutdown frame
      • getShutdownPackage

        protected D getShutdownPackage​(S session)
        Returns the shutdown package to send before the net service shutdown.
        Parameters:
        session - Session to create the package.
        Returns:
        Shutdown package.
      • write

        protected final void write​(S session,
                                   D payLoad)
                            throws java.io.IOException
        This method writes some data over the session indicated, this operation generate a blocking until the net service confirm that the data was written over the communication channel
        Parameters:
        session - Net session.
        payLoad - Data to be written
        Throws:
        java.io.IOException - Exception for the io operations
      • write

        protected final void write​(S session,
                                   D payLoad,
                                   boolean waitFor)
                            throws java.io.IOException
        This method writes some data over the session indicated.
        Parameters:
        session - Net session.
        payLoad - Data to be written.
        waitFor - If this parameter is true then the operation generate a blocking over the communication channel.
        Throws:
        java.io.IOException - Exception for io operations
      • onConnect

        public final void onConnect​(NetPackage netPackage)
        This method abstracts the connection event to use the entities of the domain's implementation.
        Parameters:
        netPackage - Connection package.
      • onConnect

        protected void onConnect​(S session,
                                 D payLoad,
                                 NetPackage netPackage)
        Method that must be implemented by the custom implementation to know when a session is connected
        Parameters:
        session - Connected session.
        payLoad - Decoded package payload.
        netPackage - Original package.
      • onDisconnect

        public final void onDisconnect​(NetPackage netPackage)
        This method abstracts the disconnection event to use the entities of the domain's implementation.
        Parameters:
        netPackage - Disconnection package.
      • onDisconnect

        protected void onDisconnect​(S session,
                                    NetPackage netPackage)
        Method must be implemented by the custom implementation to known when a session is disconnected
        Parameters:
        session - Disconnected session.
        netPackage - Original package.
      • onRead

        public final void onRead​(NetPackage netPackage)
        When the net service receive data call this method to process the package
        Parameters:
        netPackage - Net package.
      • onRead

        protected void onRead​(S session,
                              D payLoad,
                              NetPackage netPackage)
        When the net service receive data, this method is called to process the package.
        Parameters:
        session - Net session.
        payLoad - Net package decoded
        netPackage - Net package.
      • onCheckSessionError

        protected void onCheckSessionError​(S session,
                                           D payLoad,
                                           NetPackage netPackage,
                                           java.lang.Throwable cause)
        When an exception is occurred while checking session, this method is called to process the package according the exception information.
        Parameters:
        session - Net session.
        payLoad - Net package decoded
        netPackage - Net package.
        cause - Error cause.
      • onWrite

        public final void onWrite​(NetPackage netPackage)
        When the net service write data then call this method to process the package.
        Parameters:
        netPackage - Net package.
      • onWrite

        protected void onWrite​(S session,
                               NetPackage netPackage)
        When the net service write data then call this method to process the package.
        Parameters:
        session - Net session.
        netPackage - Net package.
      • encode

        protected abstract byte[] encode​(D payLoad)
        This method decode the implementation data.
        Parameters:
        payLoad - Implementation data.
        Returns:
        Implementation data encoded.
      • decode

        protected abstract D decode​(NetPackage netPackage)
        This method decode the net package to obtain the implementation data
        Parameters:
        netPackage - Net package.
        Returns:
        Return the implementation data.
      • destroySession

        public abstract void destroySession​(NetSession session)
        Destroy the session.
        Parameters:
        session - Net session to be destroyed
      • checkSession

        public abstract S checkSession​(S session,
                                       D payLoad,
                                       NetPackage netPackage)
        Check the channel session.
        Parameters:
        session - Created session.
        payLoad - Decoded package.
        netPackage - Net package.
        Returns:
        Updated session.
      • getSocketOptions

        public java.util.Map<java.net.SocketOption,​java.lang.Object> getSocketOptions()
        Return the socket options of the implementation.
        Returns:
        Socket options.