Class NetService


  • public final class NetService
    extends Service<NetServiceConsumer>
    This class implements a service that provide an up-level interface to open tcp and udp connections like a server side or client side.
    Author:
    javaito
    • Method Detail

      • getInstance

        public static final NetService getInstance()
        Return the unique instance of the service.
        Returns:
        Instance of the service.
      • init

        protected void init()
        This method will be called immediately after of the execution of the service's constructor method
        Overrides:
        init in class Service<NetServiceConsumer>
      • registerConsumer

        public final void registerConsumer​(NetServiceConsumer consumer)
        This method register the consumer in the service.
        Specified by:
        registerConsumer in class Service<NetServiceConsumer>
        Parameters:
        consumer - Consumer.
        Throws:
        java.lang.NullPointerException - If the consumer is null.
        java.lang.IllegalArgumentException - If the consumer is not a NetClient instance of a NetServer instance.
        java.lang.RuntimeException - With a IOException like a cause.
      • isShuttingDown

        public final boolean isShuttingDown()
        Return a boolean to knows if the instance of the java vm is into the shutdown process or not.
        Returns:
        True if the vm is into the shutdown porcess and false in the otherwise.
      • checkSession

        public final boolean checkSession​(NetSession session)
        Check if the specific session is active into the sercie.
        Parameters:
        session - Specific session.
        Returns:
        Return true if the session is active into the
      • writeData

        public final NetPackage writeData​(NetSession session,
                                          byte[] data)
                                   throws java.io.IOException
        This method put a net package on the output queue of the session.
        Parameters:
        session - Net session.
        data - Data to create the package.
        Returns:
        Return the id of the created package.
        Throws:
        java.io.IOException - Exception of the write operation.
      • disconnect

        public final void disconnect​(NetSession session,
                                     java.lang.String message)
        Disconnect a specific session.
        Parameters:
        session - Session to disconnect.
        message - Disconnection message.
      • isConnected

        public final boolean isConnected​(NetSession session)
        Indicates if the session is connected or not
        Parameters:
        session - Session
        Returns:
        Return true if the session is connected and false in the other case.