Class AbstractCommunicationMessage
java.lang.Object
com.iohao.net.framework.protocol.AbstractCommunicationMessage
- All Implemented Interfaces:
CommonResponse, CommunicationMessage, FutureMessage, RemoteMessage, Request, UserIdentity
- Direct Known Subclasses:
ExternalMessage
Abstract base implementation of
CommunicationMessage for external protocol codecs.
Stores all routing, identity, and metadata fields as transient members annotated
with @Ignore so they are excluded from protobuf serialization. Subclasses (e.g.,
WebSocket and TCP codec messages) only serialize their protocol-specific wire fields while
inheriting the full CommunicationMessage contract. Provides no-op defaults for
fields not used in every codec variant (cmdCode, protocolSwitch, msgId, error fields).
- Since:
- 25.1
- Author:
- 渔民小镇
- date:
- 2025-09-24
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]Extended field.int[]The IDs of multiple game logic servers bound to the playerintGet the cache condition flag indicating whether this message is cacheable.intGet the command code identifying the protocol-level message type.intGet the error code. 0 indicates success; any other value indicates an error.Get the human-readable error message.intGet the ID of the external server that originated or will receive this message.longGet the future correlation id.intGet the number of hops this request has traversed across logic servers.intGet the ID of the logic server handling this message.intgetMsgId()Get the client-assigned message ID for request-response correlation.longGet the nanosecond timestamp recorded when this message was created or received.intgetNetId()Get the network-level identifier.<T> TgetOther()Get the transient auxiliary object attached to this message.intGet the protocol switch flags controlling codec behavior.intGet the ID of the server that originally created this message.intgetStick()Get the sticky-routing hint for this request.Get the distributed trace ID for this message.longGet the user id.booleanCheck whether the user's identity has been verified (authenticated).voidsetAttachment(byte[] attachment) Set the per-request attachment data.voidsetBindingLogicServerIds(int[] bindingLogicServerIds) Set the IDs of logic servers that this player is bound to.voidsetCacheCondition(int cacheCondition) Set the cache condition flag.voidsetCmdCode(int cmdCode) Set the command code identifying the protocol-level message type.voidsetCmdInfo(CmdInfo cmdInfo) Set the command route from aCmdInfodescriptor.voidsetErrorCode(int errorCode) Set the error code. 0 indicates success; any other value indicates an error.voidsetErrorMessage(String errorMessage) Set the human-readable error message.voidsetExternalServerId(int externalServerId) Set the ID of the external server.voidsetFutureId(long futureId) Set the future correlation id.voidsetHopCount(int hopCount) Set the number of hops this request has traversed.voidsetInetSocketAddress(Object inetSocketAddress) voidsetLogicServerId(int logicServerId) Set the ID of the logic server handling this message.voidsetMsgId(int msgId) Set the client-assigned message ID.voidsetNanoTime(long nanoTime) Set the nanosecond timestamp for this message.voidsetNetId(int netId) Set the network-level identifier.voidvoidsetOutputError(ErrorInformation outputError) Set the error information to be included in the response.voidsetProtocolSwitch(int protocolSwitch) Set the protocol switch flags controlling codec behavior.voidsetSourceServerId(int sourceServerId) Set the ID of the server that originally created this message.voidsetStick(int stick) Set the sticky-routing hint used to pin this request to a specific server instance.voidsetTraceId(String traceId) Set the distributed trace ID for this message.voidsetUserId(long userId) Set the user id.voidsetVerifyIdentity(boolean verifyIdentity) Set the identity verification flag.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface CommonResponse
hasError, isSuccess, setErrorMethods inherited from interface CommunicationMessage
getCmdInfo, getCmdMerge, getData, setCmdMerge, setDataMethods inherited from interface UserIdentity
bindingUserId, setUserIdentity, verifyIdentity
-
Constructor Details
-
AbstractCommunicationMessage
public AbstractCommunicationMessage()
-
-
Method Details
-
setOutputError
Set the error information to be included in the response.- Specified by:
setOutputErrorin interfaceRemoteMessage- Parameters:
outputError- the error information
-
setCmdInfo
Set the command route from aCmdInfodescriptor.- Specified by:
setCmdInfoin interfaceRemoteMessage- Parameters:
cmdInfo- the command info containing the merged route key
-
getOther
public <T> T getOther()Get the transient auxiliary object attached to this message.- Type Parameters:
T- the expected type- Returns:
- the auxiliary object, cast to
T
-
getCmdCode
public int getCmdCode()Description copied from interface:CommunicationMessageGet the command code identifying the protocol-level message type.- Specified by:
getCmdCodein interfaceCommunicationMessage- Returns:
- the command code
-
setCmdCode
public void setCmdCode(int cmdCode) Description copied from interface:CommunicationMessageSet the command code identifying the protocol-level message type.- Specified by:
setCmdCodein interfaceCommunicationMessage- Parameters:
cmdCode- the command code
-
getProtocolSwitch
public int getProtocolSwitch()Description copied from interface:CommunicationMessageGet the protocol switch flags controlling codec behavior.- Specified by:
getProtocolSwitchin interfaceCommunicationMessage- Returns:
- the protocol switch bitmask
-
setProtocolSwitch
public void setProtocolSwitch(int protocolSwitch) Description copied from interface:CommunicationMessageSet the protocol switch flags controlling codec behavior.- Specified by:
setProtocolSwitchin interfaceCommunicationMessage- Parameters:
protocolSwitch- the protocol switch bitmask
-
getMsgId
public int getMsgId()Description copied from interface:CommunicationMessageGet the client-assigned message ID for request-response correlation.- Specified by:
getMsgIdin interfaceCommunicationMessage- Returns:
- the message ID
-
setMsgId
public void setMsgId(int msgId) Description copied from interface:CommunicationMessageSet the client-assigned message ID.- Specified by:
setMsgIdin interfaceCommunicationMessage- Parameters:
msgId- the message ID
-
getErrorCode
public int getErrorCode()Description copied from interface:CommonResponseGet the error code. 0 indicates success; any other value indicates an error.- Specified by:
getErrorCodein interfaceCommonResponse- Returns:
- the error code
-
setErrorCode
public void setErrorCode(int errorCode) Description copied from interface:CommonResponseSet the error code. 0 indicates success; any other value indicates an error.- Specified by:
setErrorCodein interfaceCommonResponse- Parameters:
errorCode- the error code
-
getErrorMessage
Description copied from interface:CommonResponseGet the human-readable error message.- Specified by:
getErrorMessagein interfaceCommonResponse- Returns:
- the error message, or
nullon success
-
setErrorMessage
Description copied from interface:CommonResponseSet the human-readable error message.- Specified by:
setErrorMessagein interfaceCommonResponse- Parameters:
errorMessage- the error message
-
getInetSocketAddress
-
getCacheCondition
public int getCacheCondition()Description copied from interface:CommunicationMessageGet the cache condition flag indicating whether this message is cacheable.- Specified by:
getCacheConditionin interfaceCommunicationMessage- Returns:
- the cache condition value
-
getUserId
public long getUserId()Description copied from interface:UserIdentityGet the user id.- Specified by:
getUserIdin interfaceUserIdentity- Returns:
- the user id
-
isVerifyIdentity
public boolean isVerifyIdentity()Description copied from interface:UserIdentityCheck whether the user's identity has been verified (authenticated).- Specified by:
isVerifyIdentityin interfaceUserIdentity- Returns:
trueif the identity is verified
-
getStick
-
getHopCount
public int getHopCount()Description copied from interface:RequestGet the number of hops this request has traversed across logic servers.- Specified by:
getHopCountin interfaceRequest- Returns:
- the current hop count
-
getBindingLogicServerIds
public int[] getBindingLogicServerIds()Description copied from interface:RequestThe IDs of multiple game logic servers bound to the playerAll requests related to this game logic server will be routed to the bound game logic server for processing. Even if multiple game logic servers of the same type are running, requests will still be directed to the originally bound server.- Specified by:
getBindingLogicServerIdsin interfaceRequest- Returns:
- bindingLogicServerIds
-
getAttachment
public byte[] getAttachment()Description copied from interface:RequestExtended field. Developers can use this field to extend meta-information for special business needs. The data in this field will be included with every request.- Specified by:
getAttachmentin interfaceRequest- Returns:
- AttachmentData
-
getTraceId
Description copied from interface:RemoteMessageGet the distributed trace ID for this message.- Specified by:
getTraceIdin interfaceRemoteMessage- Returns:
- the trace ID, or
nullif not set
-
getExternalServerId
public int getExternalServerId()Description copied from interface:RemoteMessageGet the ID of the external server that originated or will receive this message.- Specified by:
getExternalServerIdin interfaceRemoteMessage- Returns:
- the external server ID
-
getLogicServerId
public int getLogicServerId()Description copied from interface:RemoteMessageGet the ID of the logic server handling this message.- Specified by:
getLogicServerIdin interfaceRemoteMessage- Returns:
- the logic server ID
-
getSourceServerId
public int getSourceServerId()Description copied from interface:RemoteMessageGet the ID of the server that originally created this message.- Specified by:
getSourceServerIdin interfaceRemoteMessage- Returns:
- the source server ID
-
getNetId
public int getNetId()Description copied from interface:RemoteMessageGet the network-level identifier.- Specified by:
getNetIdin interfaceRemoteMessage- Returns:
- the net ID
-
getFutureId
public long getFutureId()Description copied from interface:FutureMessageGet the future correlation id.- Specified by:
getFutureIdin interfaceFutureMessage- Returns:
- the future id
-
getNanoTime
public long getNanoTime()Description copied from interface:RemoteMessageGet the nanosecond timestamp recorded when this message was created or received.- Specified by:
getNanoTimein interfaceRemoteMessage- Returns:
- the nano time
-
setOther
-
setInetSocketAddress
-
setCacheCondition
public void setCacheCondition(int cacheCondition) Description copied from interface:CommunicationMessageSet the cache condition flag.- Specified by:
setCacheConditionin interfaceCommunicationMessage- Parameters:
cacheCondition- the cache condition value
-
setUserId
public void setUserId(long userId) Description copied from interface:UserIdentitySet the user id.- Specified by:
setUserIdin interfaceUserIdentity- Parameters:
userId- the user id
-
setVerifyIdentity
public void setVerifyIdentity(boolean verifyIdentity) Description copied from interface:UserIdentitySet the identity verification flag.- Specified by:
setVerifyIdentityin interfaceUserIdentity- Parameters:
verifyIdentity-trueif the identity is verified
-
setStick
-
setHopCount
public void setHopCount(int hopCount) Description copied from interface:RequestSet the number of hops this request has traversed.- Specified by:
setHopCountin interfaceRequest- Parameters:
hopCount- the hop count to set
-
setBindingLogicServerIds
public void setBindingLogicServerIds(int[] bindingLogicServerIds) Description copied from interface:RequestSet the IDs of logic servers that this player is bound to.- Specified by:
setBindingLogicServerIdsin interfaceRequest- Parameters:
bindingLogicServerIds- array of bound logic server IDs
-
setAttachment
public void setAttachment(byte[] attachment) Description copied from interface:RequestSet the per-request attachment data.- Specified by:
setAttachmentin interfaceRequest- Parameters:
attachment- the attachment byte array
-
setTraceId
Description copied from interface:RemoteMessageSet the distributed trace ID for this message.- Specified by:
setTraceIdin interfaceRemoteMessage- Parameters:
traceId- the trace ID
-
setExternalServerId
public void setExternalServerId(int externalServerId) Description copied from interface:RemoteMessageSet the ID of the external server.- Specified by:
setExternalServerIdin interfaceRemoteMessage- Parameters:
externalServerId- the external server ID
-
setLogicServerId
public void setLogicServerId(int logicServerId) Description copied from interface:RemoteMessageSet the ID of the logic server handling this message.- Specified by:
setLogicServerIdin interfaceRemoteMessage- Parameters:
logicServerId- the logic server ID
-
setSourceServerId
public void setSourceServerId(int sourceServerId) Description copied from interface:RemoteMessageSet the ID of the server that originally created this message.- Specified by:
setSourceServerIdin interfaceRemoteMessage- Parameters:
sourceServerId- the source server ID
-
setNetId
public void setNetId(int netId) Description copied from interface:RemoteMessageSet the network-level identifier.- Specified by:
setNetIdin interfaceRemoteMessage- Parameters:
netId- the net ID
-
setFutureId
public void setFutureId(long futureId) Description copied from interface:FutureMessageSet the future correlation id.- Specified by:
setFutureIdin interfaceFutureMessage- Parameters:
futureId- the future id
-
setNanoTime
public void setNanoTime(long nanoTime) Description copied from interface:RemoteMessageSet the nanosecond timestamp for this message.- Specified by:
setNanoTimein interfaceRemoteMessage- Parameters:
nanoTime- the nano time
-