Package com.tenio.api

Class MessageApi


  • public final class MessageApi
    extends AbstractLogger
    This class provides you a necessary interface for sending messages from the server to clients. It uses a pooling mechanism to increase performance. For creating a message, it's better that decrease this content as less as possible (for fast transferring, save bandwidth, reduce risk, ...). For example, a message should only hold an array, and the client will reference the defined APIs to retrieve his desired values by the array's indexes.
    Author:
    kong
    • Constructor Detail

    • Method Detail

      • sendToConnection

        public void sendToConnection​(Connection connection,
                                     java.lang.String key,
                                     java.lang.Object value)
        Send a message for a connection
        Parameters:
        connection - See Connection
        key - the key of message
        value - the value of message
      • sendToConnection

        public void sendToConnection​(Connection connection,
                                     java.lang.String key,
                                     java.lang.Object value,
                                     java.lang.String keyData,
                                     TArray data)
        Send a message to a connection Must use getArrayPack() to create data array package for avoiding memory leak.
        Parameters:
        connection - See Connection
        key - the key of message
        value - the value of message
        keyData - the key of message's data
        data - the main data of message, see: TArray
      • sendToPlayer

        public void sendToPlayer​(AbstractPlayer player,
                                 int index,
                                 java.lang.String key,
                                 java.lang.Object value)
        Send a message to player via his connection
        Parameters:
        player - See AbstractPlayer
        index - the index of connection in current player
        key - the key of message
        value - the value of message
      • sendToPlayer

        public void sendToPlayer​(AbstractPlayer player,
                                 int index,
                                 java.lang.String key,
                                 java.lang.Object value,
                                 java.lang.String keyData,
                                 TArray data)
        Send a message to a player Must use getArrayPack() to create data array package for avoiding memory leak.
        Parameters:
        player - the desired player
        index - the index of connection in current player
        key - the key of message
        value - the value of message
        keyData - the key of message's data
        data - the message data, see: TArray
      • sendToRoom

        public void sendToRoom​(AbstractRoom room,
                               int index,
                               java.lang.String key,
                               java.lang.Object value)
        Send a message to all players of one room
        Parameters:
        room - the desired room
        index - the index of connection in current player
        key - the key of message
        value - the value of message
      • sendToRoom

        public void sendToRoom​(AbstractRoom room,
                               int index,
                               java.lang.String key,
                               java.lang.Object value,
                               java.lang.String keyData,
                               TArray data)
        Send a message to all players on one room Must use getArrayPack() to create data array package for avoiding memory leak.
        Parameters:
        room - the desired room
        index - the index of connection in current player
        key - the key of message
        value - the value of message
        keyData - the key of message's data
        data - the message's data, see: TArray
      • sendToRoomIgnorePlayer

        public void sendToRoomIgnorePlayer​(AbstractPlayer player,
                                           int index,
                                           java.lang.String key,
                                           java.lang.Object value)
        Send a message to all players in one room except the desired player
        Parameters:
        player - the desired player
        index - the index of connection in current player
        key - the key of message
        value - the value of message
      • sendToRoomIgnorePlayer

        public void sendToRoomIgnorePlayer​(AbstractPlayer player,
                                           int index,
                                           java.lang.String key,
                                           java.lang.Object value,
                                           java.lang.String keyData,
                                           TArray data)
        Send a message to all players in one room except the desired player Must use getArrayPack() to create data array package for avoiding memory leak.
        Parameters:
        player - the desired player
        index - the index of connection in current player
        key - the key of message
        value - the value of message
        keyData - the key of message's data
        data - the message's data, see: TArray
      • getArrayPack

        public TArray getArrayPack()
        Returns:
        a TArray object from the pooling mechanism