Class MessagesServer<S extends NetSession>

  • All Implemented Interfaces:
    ServiceConsumer
    Direct Known Subclasses:
    CloudServer, ConsoleServer

    public abstract class MessagesServer<S extends NetSession>
    extends NetServer<S,​MessageBuffer>
    This implementation provides the base to work with messages into the network. The messages are objects that are serialized in bson format to be transfer.
    Author:
    javaito
    • Method Detail

      • isEncrypted

        public final boolean isEncrypted()
        Returns true if the server use a encrypted protocol and false in the otherwise
        Returns:
        Is encrypted or no.
      • encode

        protected final byte[] encode​(MessageBuffer payLoad)
        Returns the byte array in order to transfer the message.
        Specified by:
        encode in class NetServiceConsumer<S extends NetSession,​MessageBuffer>
        Parameters:
        payLoad - Implementation data.
        Returns:
        Byte array that represents the message.
      • send

        public final void send​(S session,
                               Message message)
                        throws java.io.IOException
        Send message to the net using the buffer.
        Parameters:
        session - Session that indicate the remote host.
        message - Message to transfer.
        Throws:
        java.io.IOException - Io Exception
      • encrypt

        protected EncryptedMessage encrypt​(Message message)
        This method must encrypt the message and create an instance of EncryptedMessage wrapping the original message.
        Parameters:
        message - Original message.
        Returns:
        Encrypted message.
      • decrypt

        protected Message decrypt​(EncryptedMessage encryptedMessage)
        This method must decrypt the encrypted message and returns the original message decrypted.
        Parameters:
        encryptedMessage - Incoming encrypted message.
        Returns:
        Original message decrypted.
      • onRead

        protected abstract void onRead​(S session,
                                       Message message)
        This method depends of each implementation.
        Parameters:
        session - Net session.
        message - Incoming message.