Package com.tenio.api
Class MessageApi
- java.lang.Object
-
- com.tenio.logger.AbstractLogger
-
- com.tenio.api.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 Summary
Constructors Constructor Description MessageApi(IEventManager eventManager)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TArray
getArrayPack()
void
sendToConnection(Connection connection, java.lang.String key, java.lang.Object value)
Send a message for a connectionvoid
sendToConnection(Connection connection, java.lang.String key, java.lang.Object value, java.lang.String keyData, TArray data)
Send a message to a connection Must usegetArrayPack()
to create data array package for avoiding memory leak.void
sendToPlayer(AbstractPlayer player, int index, java.lang.String key, java.lang.Object value)
Send a message to player via his connectionvoid
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 usegetArrayPack()
to create data array package for avoiding memory leak.void
sendToRoom(AbstractRoom room, int index, java.lang.String key, java.lang.Object value)
Send a message to all players of one roomvoid
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 usegetArrayPack()
to create data array package for avoiding memory leak.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 playervoid
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 usegetArrayPack()
to create data array package for avoiding memory leak.
-
-
-
Constructor Detail
-
MessageApi
public MessageApi(IEventManager eventManager)
-
-
Method Detail
-
sendToConnection
public void sendToConnection(Connection connection, java.lang.String key, java.lang.Object value)
Send a message for a connection- Parameters:
connection
- SeeConnection
key
- the key of messagevalue
- 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 usegetArrayPack()
to create data array package for avoiding memory leak.- Parameters:
connection
- SeeConnection
key
- the key of messagevalue
- the value of messagekeyData
- the key of message's datadata
- 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
- SeeAbstractPlayer
index
- the index of connection in current playerkey
- the key of messagevalue
- 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 usegetArrayPack()
to create data array package for avoiding memory leak.- Parameters:
player
- the desired playerindex
- the index of connection in current playerkey
- the key of messagevalue
- the value of messagekeyData
- the key of message's datadata
- 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 roomindex
- the index of connection in current playerkey
- the key of messagevalue
- 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 usegetArrayPack()
to create data array package for avoiding memory leak.- Parameters:
room
- the desired roomindex
- the index of connection in current playerkey
- the key of messagevalue
- the value of messagekeyData
- the key of message's datadata
- 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 playerindex
- the index of connection in current playerkey
- the key of messagevalue
- 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 usegetArrayPack()
to create data array package for avoiding memory leak.- Parameters:
player
- the desired playerindex
- the index of connection in current playerkey
- the key of messagevalue
- the value of messagekeyData
- the key of message's datadata
- the message's data, see:TArray
-
-