Class EMessageHeader


  • public final class EMessageHeader
    extends java.lang.Object
    Contains the EMessage header information. This includes the "from" proxy identifier, the "to" proxy identifier, and the eBus EMessage. The proxy identifiers are used to route messages between remote eBus applications. The proxies are used to represent the remote eBus' capability within the local JVM.

    This class is immutable.

    The binary serialization format for an eBus message header is:

    • 2-byte, signed integer serialized header length. These two bytes are also used for the heartbeat (-15,000) and heartbeat reply (-8,000) indicators.
    • 4-byte, signed integer message class identifier. This is the same identifier received from the remote application's KeyMessage.
    • 4-byte, signed integer from feed identifier. The local eBus feed responsible for sending this message.
    • 4-byte, signed integer to feed identifier. The remote eBus feed responsible for handling this message. If the remote feed is not known when the message is sent, it is set to NO_ID.
    • The de-serialized eBus message. See MessageType about eBus message and field serialization.

    Both the "to" and "from" feeds are encapsulated in an ERemoteApp instance.

    Author:
    Charles Rapp
    See Also:
    EMessage
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int NO_ID
      Proxy identifiers are set to -1 to signify that they are unknown at the time the message was sent.
    • Constructor Summary

      Constructors 
      Constructor Description
      EMessageHeader​(int classId, int fromFeedId, int toFeedId, int sequenceNumber, java.net.SocketAddress address, EMessage msg)
      Creates a message header with the given key, from and to feed identifiers and eBus message.
      EMessageHeader​(int classId, int fromFeedId, int toFeedId, java.net.SocketAddress address, EMessage msg)
      Creates a message header with the given key, from and to feed identifiers, message source/destination address, and eBus message.
      EMessageHeader​(int classId, int fromFeedId, int toFeedId, EMessage msg)
      Creates a message header with the given key, from and to feed identifiers and eBus message.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.net.SocketAddress address()
      Returns the message source or destination address.
      int classId()
      Returns the unique class identifier.
      DataType dataType()
      Returns encapsulated message's data type.
      int fromFeedId()
      Returns the from proxy identifier.
      boolean isSystemMessage()
      Returns true if the contained message is a system message.
      EMessage message()
      Returns the encapsulated eBus message.
      java.lang.Class<? extends EMessage> messageClass()
      Returns the message class.
      EMessageKey messageKey()
      Returns the encapsulated message key.
      EMessage.MessageType messageType()
      Returns the encapsulated message type.
      int sequenceNumber()
      Returns message sequence number.
      void sequenceNumber​(int n)
      Sets message sequence number to the given value if not previously set.
      int toFeedId()
      Returns the to proxy identifier.
      java.lang.String toString()
      Returns this header as human-readable text.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • NO_ID

        public static final int NO_ID
        Proxy identifiers are set to -1 to signify that they are unknown at the time the message was sent.
        See Also:
        Constant Field Values
    • Constructor Detail

      • EMessageHeader

        public EMessageHeader​(int classId,
                              int fromFeedId,
                              int toFeedId,
                              EMessage msg)
        Creates a message header with the given key, from and to feed identifiers and eBus message. Sets the message's associated address to null and sequence number to NO_ID.
        Parameters:
        classId - the message class identifier.
        fromFeedId - the message is from this eBus proxy. Will be NO_ID for system messages only; all other messages must set this to a value ≥ zero.
        toFeedId - the message is destined for this eBus proxy. Will be NO_ID if the destination proxy is unknown.
        msg - the eBus message.
        Throws:
        java.lang.IllegalArgumentException - if msg is null or if msg is an application message and classId, fromFeedId, or sequenceNumber is < zero.
      • EMessageHeader

        public EMessageHeader​(int classId,
                              int fromFeedId,
                              int toFeedId,
                              java.net.SocketAddress address,
                              EMessage msg)
        Creates a message header with the given key, from and to feed identifiers, message source/destination address, and eBus message. Sequence number set to NO_ID.
        Parameters:
        classId - the message class identifier.
        fromFeedId - the message is from this eBus proxy. Will be NO_ID for system messages only; all other messages must set this to a value ≥ zero.
        toFeedId - the message is destined for this eBus proxy. Will be NO_ID if the destination proxy is unknown.
        address - message source or destination address. May be null.
        msg - the eBus message.
        Throws:
        java.lang.IllegalArgumentException - if msg is null or if msg is an application message and classId, fromFeedId, or sequenceNumber is < zero.
      • EMessageHeader

        public EMessageHeader​(int classId,
                              int fromFeedId,
                              int toFeedId,
                              int sequenceNumber,
                              java.net.SocketAddress address,
                              EMessage msg)
        Creates a message header with the given key, from and to feed identifiers and eBus message.
        Parameters:
        classId - the message class identifier.
        fromFeedId - the message is from this eBus proxy. Will be NO_ID for system messages only; all other messages must set this to a value ≥ zero.
        toFeedId - the message is destined for this eBus proxy. Will be NO_ID if the destination proxy is unknown.
        sequenceNumber - message sequence number.
        address - message source or destination address. May be null.
        msg - the eBus message.
        Throws:
        java.lang.IllegalArgumentException - if msg is null or if msg is an application message and classId, fromFeedId, or sequenceNumber is < zero.
    • Method Detail

      • toString

        public java.lang.String toString()
        Returns this header as human-readable text.
        Overrides:
        toString in class java.lang.Object
        Returns:
        the header as text.
      • messageClass

        public java.lang.Class<? extends EMessage> messageClass()
        Returns the message class.
        Returns:
        message class.
      • isSystemMessage

        public boolean isSystemMessage()
        Returns true if the contained message is a system message.
        Returns:
        true if a system message.
      • messageType

        public EMessage.MessageType messageType()
        Returns the encapsulated message type.
        Returns:
        message type.
      • messageKey

        public EMessageKey messageKey()
        Returns the encapsulated message key.
        Returns:
        message key.
      • classId

        public int classId()
        Returns the unique class identifier.
        Returns:
        class identifier.
      • fromFeedId

        public int fromFeedId()
        Returns the from proxy identifier. If this is a ESystemMessage, then returns NO_ID.
        Returns:
        the from proxy identifier.
      • toFeedId

        public int toFeedId()
        Returns the to proxy identifier. If the destination proxy is not known at the time the message was sent, then returns NO_ID.
        Returns:
        the destination proxy identifier.
      • sequenceNumber

        public int sequenceNumber()
        Returns message sequence number. If the sequence number is not set, then returns NO_ID.
        Returns:
        message sequence number.
      • address

        public java.net.SocketAddress address()
        Returns the message source or destination address. May return null.
        Returns:
        socket address.
      • message

        public EMessage message()
        Returns the encapsulated eBus message.
        Returns:
        the encapsulated eBus message.
      • dataType

        public DataType dataType()
        Returns encapsulated message's data type.
        Returns:
        message data type.
      • sequenceNumber

        public void sequenceNumber​(int n)
        Sets message sequence number to the given value if not previously set.
        Parameters:
        n - message sequence number.
        Throws:
        java.lang.IllegalArgumentException - if n < zero.
        java.lang.IllegalStateException - if sequenceNumber(int) previously called for this message header.