Package net.sf.eBus.messages
Class EMessageHeader
- java.lang.Object
-
- net.sf.eBus.messages.EMessageHeader
-
public final class EMessageHeader extends java.lang.ObjectContains theEMessageheader information. This includes the "from" proxy identifier, the "to" proxy identifier, and the eBusEMessage. 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
MessageTypeabout eBus message and field serialization.
Both the "to" and "from" feeds are encapsulated in an
ERemoteAppinstance.- Author:
- Charles Rapp
- See Also:
EMessage
-
-
Field Summary
Fields Modifier and Type Field Description static intNO_IDProxy 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.SocketAddressaddress()Returns the message source or destination address.intclassId()Returns the unique class identifier.DataTypedataType()Returns encapsulated message's data type.intfromFeedId()Returns the from proxy identifier.booleanisSystemMessage()Returnstrueif the contained message is a system message.EMessagemessage()Returns the encapsulated eBus message.java.lang.Class<? extends EMessage>messageClass()Returns the message class.EMessageKeymessageKey()Returns the encapsulated message key.EMessage.MessageTypemessageType()Returns the encapsulated message type.intsequenceNumber()Returns message sequence number.voidsequenceNumber(int n)Sets message sequence number to the given value if not previously set.inttoFeedId()Returns the to proxy identifier.java.lang.StringtoString()Returns this header as human-readable text.
-
-
-
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 tonulland sequence number toNO_ID.- Parameters:
classId- the message class identifier.fromFeedId- the message is from this eBus proxy. Will beNO_IDforsystem messagesonly; all other messages must set this to a value ≥ zero.toFeedId- the message is destined for this eBus proxy. Will beNO_IDif the destination proxy is unknown.msg- the eBus message.- Throws:
java.lang.IllegalArgumentException- ifmsgisnullor ifmsgis an application message andclassId,fromFeedId, orsequenceNumberis < 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 toNO_ID.- Parameters:
classId- the message class identifier.fromFeedId- the message is from this eBus proxy. Will beNO_IDforsystem messagesonly; all other messages must set this to a value ≥ zero.toFeedId- the message is destined for this eBus proxy. Will beNO_IDif the destination proxy is unknown.address- message source or destination address. May benull.msg- the eBus message.- Throws:
java.lang.IllegalArgumentException- ifmsgisnullor ifmsgis an application message andclassId,fromFeedId, orsequenceNumberis < 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 beNO_IDforsystem messagesonly; all other messages must set this to a value ≥ zero.toFeedId- the message is destined for this eBus proxy. Will beNO_IDif the destination proxy is unknown.sequenceNumber- message sequence number.address- message source or destination address. May benull.msg- the eBus message.- Throws:
java.lang.IllegalArgumentException- ifmsgisnullor ifmsgis an application message andclassId,fromFeedId, orsequenceNumberis < zero.
-
-
Method Detail
-
toString
public java.lang.String toString()
Returns this header as human-readable text.- Overrides:
toStringin classjava.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()
Returnstrueif the contained message is a system message.- Returns:
trueif 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 aESystemMessage, then returnsNO_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 returnsNO_ID.- Returns:
- the destination proxy identifier.
-
sequenceNumber
public int sequenceNumber()
Returns message sequence number. If the sequence number is not set, then returnsNO_ID.- Returns:
- message sequence number.
-
address
public java.net.SocketAddress address()
Returns the message source or destination address. May returnnull.- 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- ifn< zero.java.lang.IllegalStateException- ifsequenceNumber(int)previously called for this message header.
-
-