Class AbstractCommunicationMessage

java.lang.Object
com.iohao.net.framework.protocol.AbstractCommunicationMessage
All Implemented Interfaces:
CommonResponse, CommunicationMessage, FutureMessage, RemoteMessage, Request, UserIdentity
Direct Known Subclasses:
ExternalMessage

public abstract class AbstractCommunicationMessage extends Object implements CommunicationMessage
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 Details

    • AbstractCommunicationMessage

      public AbstractCommunicationMessage()
  • Method Details

    • setOutputError

      public void setOutputError(ErrorInformation outputError)
      Set the error information to be included in the response.
      Specified by:
      setOutputError in interface RemoteMessage
      Parameters:
      outputError - the error information
    • setCmdInfo

      public void setCmdInfo(CmdInfo cmdInfo)
      Set the command route from a CmdInfo descriptor.
      Specified by:
      setCmdInfo in interface RemoteMessage
      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: CommunicationMessage
      Get the command code identifying the protocol-level message type.
      Specified by:
      getCmdCode in interface CommunicationMessage
      Returns:
      the command code
    • setCmdCode

      public void setCmdCode(int cmdCode)
      Description copied from interface: CommunicationMessage
      Set the command code identifying the protocol-level message type.
      Specified by:
      setCmdCode in interface CommunicationMessage
      Parameters:
      cmdCode - the command code
    • getProtocolSwitch

      public int getProtocolSwitch()
      Description copied from interface: CommunicationMessage
      Get the protocol switch flags controlling codec behavior.
      Specified by:
      getProtocolSwitch in interface CommunicationMessage
      Returns:
      the protocol switch bitmask
    • setProtocolSwitch

      public void setProtocolSwitch(int protocolSwitch)
      Description copied from interface: CommunicationMessage
      Set the protocol switch flags controlling codec behavior.
      Specified by:
      setProtocolSwitch in interface CommunicationMessage
      Parameters:
      protocolSwitch - the protocol switch bitmask
    • getMsgId

      public int getMsgId()
      Description copied from interface: CommunicationMessage
      Get the client-assigned message ID for request-response correlation.
      Specified by:
      getMsgId in interface CommunicationMessage
      Returns:
      the message ID
    • setMsgId

      public void setMsgId(int msgId)
      Description copied from interface: CommunicationMessage
      Set the client-assigned message ID.
      Specified by:
      setMsgId in interface CommunicationMessage
      Parameters:
      msgId - the message ID
    • getErrorCode

      public int getErrorCode()
      Description copied from interface: CommonResponse
      Get the error code. 0 indicates success; any other value indicates an error.
      Specified by:
      getErrorCode in interface CommonResponse
      Returns:
      the error code
    • setErrorCode

      public void setErrorCode(int errorCode)
      Description copied from interface: CommonResponse
      Set the error code. 0 indicates success; any other value indicates an error.
      Specified by:
      setErrorCode in interface CommonResponse
      Parameters:
      errorCode - the error code
    • getErrorMessage

      public String getErrorMessage()
      Description copied from interface: CommonResponse
      Get the human-readable error message.
      Specified by:
      getErrorMessage in interface CommonResponse
      Returns:
      the error message, or null on success
    • setErrorMessage

      public void setErrorMessage(String errorMessage)
      Description copied from interface: CommonResponse
      Set the human-readable error message.
      Specified by:
      setErrorMessage in interface CommonResponse
      Parameters:
      errorMessage - the error message
    • getInetSocketAddress

      public Object getInetSocketAddress()
    • getCacheCondition

      public int getCacheCondition()
      Description copied from interface: CommunicationMessage
      Get the cache condition flag indicating whether this message is cacheable.
      Specified by:
      getCacheCondition in interface CommunicationMessage
      Returns:
      the cache condition value
    • getUserId

      public long getUserId()
      Description copied from interface: UserIdentity
      Get the user id.
      Specified by:
      getUserId in interface UserIdentity
      Returns:
      the user id
    • isVerifyIdentity

      public boolean isVerifyIdentity()
      Description copied from interface: UserIdentity
      Check whether the user's identity has been verified (authenticated).
      Specified by:
      isVerifyIdentity in interface UserIdentity
      Returns:
      true if the identity is verified
    • getStick

      public int getStick()
      Description copied from interface: Request
      Get the sticky-routing hint for this request.
      Specified by:
      getStick in interface Request
      Returns:
      the sticky-routing value, or 0 if not set
    • getHopCount

      public int getHopCount()
      Description copied from interface: Request
      Get the number of hops this request has traversed across logic servers.
      Specified by:
      getHopCount in interface Request
      Returns:
      the current hop count
    • getBindingLogicServerIds

      public int[] getBindingLogicServerIds()
      Description copied from interface: Request
      The IDs of multiple game logic servers bound to the player
          All 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:
      getBindingLogicServerIds in interface Request
      Returns:
      bindingLogicServerIds
    • getAttachment

      public byte[] getAttachment()
      Description copied from interface: Request
      Extended 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:
      getAttachment in interface Request
      Returns:
      AttachmentData
    • getTraceId

      public String getTraceId()
      Description copied from interface: RemoteMessage
      Get the distributed trace ID for this message.
      Specified by:
      getTraceId in interface RemoteMessage
      Returns:
      the trace ID, or null if not set
    • getExternalServerId

      public int getExternalServerId()
      Description copied from interface: RemoteMessage
      Get the ID of the external server that originated or will receive this message.
      Specified by:
      getExternalServerId in interface RemoteMessage
      Returns:
      the external server ID
    • getLogicServerId

      public int getLogicServerId()
      Description copied from interface: RemoteMessage
      Get the ID of the logic server handling this message.
      Specified by:
      getLogicServerId in interface RemoteMessage
      Returns:
      the logic server ID
    • getSourceServerId

      public int getSourceServerId()
      Description copied from interface: RemoteMessage
      Get the ID of the server that originally created this message.
      Specified by:
      getSourceServerId in interface RemoteMessage
      Returns:
      the source server ID
    • getNetId

      public int getNetId()
      Description copied from interface: RemoteMessage
      Get the network-level identifier.
      Specified by:
      getNetId in interface RemoteMessage
      Returns:
      the net ID
    • getFutureId

      public long getFutureId()
      Description copied from interface: FutureMessage
      Get the future correlation id.
      Specified by:
      getFutureId in interface FutureMessage
      Returns:
      the future id
    • getNanoTime

      public long getNanoTime()
      Description copied from interface: RemoteMessage
      Get the nanosecond timestamp recorded when this message was created or received.
      Specified by:
      getNanoTime in interface RemoteMessage
      Returns:
      the nano time
    • setOther

      public void setOther(Object other)
    • setInetSocketAddress

      public void setInetSocketAddress(Object inetSocketAddress)
    • setCacheCondition

      public void setCacheCondition(int cacheCondition)
      Description copied from interface: CommunicationMessage
      Set the cache condition flag.
      Specified by:
      setCacheCondition in interface CommunicationMessage
      Parameters:
      cacheCondition - the cache condition value
    • setUserId

      public void setUserId(long userId)
      Description copied from interface: UserIdentity
      Set the user id.
      Specified by:
      setUserId in interface UserIdentity
      Parameters:
      userId - the user id
    • setVerifyIdentity

      public void setVerifyIdentity(boolean verifyIdentity)
      Description copied from interface: UserIdentity
      Set the identity verification flag.
      Specified by:
      setVerifyIdentity in interface UserIdentity
      Parameters:
      verifyIdentity - true if the identity is verified
    • setStick

      public void setStick(int stick)
      Description copied from interface: Request
      Set the sticky-routing hint used to pin this request to a specific server instance.
      Specified by:
      setStick in interface Request
      Parameters:
      stick - the sticky-routing value
    • setHopCount

      public void setHopCount(int hopCount)
      Description copied from interface: Request
      Set the number of hops this request has traversed.
      Specified by:
      setHopCount in interface Request
      Parameters:
      hopCount - the hop count to set
    • setBindingLogicServerIds

      public void setBindingLogicServerIds(int[] bindingLogicServerIds)
      Description copied from interface: Request
      Set the IDs of logic servers that this player is bound to.
      Specified by:
      setBindingLogicServerIds in interface Request
      Parameters:
      bindingLogicServerIds - array of bound logic server IDs
    • setAttachment

      public void setAttachment(byte[] attachment)
      Description copied from interface: Request
      Set the per-request attachment data.
      Specified by:
      setAttachment in interface Request
      Parameters:
      attachment - the attachment byte array
    • setTraceId

      public void setTraceId(String traceId)
      Description copied from interface: RemoteMessage
      Set the distributed trace ID for this message.
      Specified by:
      setTraceId in interface RemoteMessage
      Parameters:
      traceId - the trace ID
    • setExternalServerId

      public void setExternalServerId(int externalServerId)
      Description copied from interface: RemoteMessage
      Set the ID of the external server.
      Specified by:
      setExternalServerId in interface RemoteMessage
      Parameters:
      externalServerId - the external server ID
    • setLogicServerId

      public void setLogicServerId(int logicServerId)
      Description copied from interface: RemoteMessage
      Set the ID of the logic server handling this message.
      Specified by:
      setLogicServerId in interface RemoteMessage
      Parameters:
      logicServerId - the logic server ID
    • setSourceServerId

      public void setSourceServerId(int sourceServerId)
      Description copied from interface: RemoteMessage
      Set the ID of the server that originally created this message.
      Specified by:
      setSourceServerId in interface RemoteMessage
      Parameters:
      sourceServerId - the source server ID
    • setNetId

      public void setNetId(int netId)
      Description copied from interface: RemoteMessage
      Set the network-level identifier.
      Specified by:
      setNetId in interface RemoteMessage
      Parameters:
      netId - the net ID
    • setFutureId

      public void setFutureId(long futureId)
      Description copied from interface: FutureMessage
      Set the future correlation id.
      Specified by:
      setFutureId in interface FutureMessage
      Parameters:
      futureId - the future id
    • setNanoTime

      public void setNanoTime(long nanoTime)
      Description copied from interface: RemoteMessage
      Set the nanosecond timestamp for this message.
      Specified by:
      setNanoTime in interface RemoteMessage
      Parameters:
      nanoTime - the nano time