Package net.sf.eBus.messages
Class EMessage
- java.lang.Object
-
- net.sf.eBus.messages.EMessageObject
-
- net.sf.eBus.messages.EMessage
-
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
ENotificationMessage
,EReplyMessage
,ERequestMessage
,ESystemMessage
public abstract class EMessage extends EMessageObject implements java.io.Serializable
EMessage
is the base class for all eBus messages and contains the message subject and timestamp. Application messages do not extend this class directly but one of the subclasses:ENotificationMessage
,ERequestMessage
, orEReplyMessage
.Note: messages are limited to 31 fields. This is due to eBus binary serialization format. This number is decreased to 29 fields for sub-classes because
EMessage
used two fields:subject
andtimestamp
. The work-around to this limitation is to group fields into anEField
subclass, which is allowed to have 31 fields of its own. So if a message class uses twoEField
subclasses, it may contain up to 62 fields with 31 in each field subclass.Note: a
EMessage
subclass may be used as a message field itself. That means that a message may contain another message as a field.This class is immutable.
See
EMessageObject
for detailed explanation of the required builder inner class.- Author:
- Charles Rapp
- See Also:
EMessageHeader
,EMessageObject
,ENotificationMessage
,ERequestMessage
,EReplyMessage
,EField
, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
EMessage.Builder<M extends EMessage,B extends EMessage.Builder<M,?>>
Base class for allEMessage
builders.static class
EMessage.MessageType
Messages are divided into four types: notification, request, reply and system.
-
Field Summary
Fields Modifier and Type Field Description static int
MAX_SUBJECT_LENGTH
eBus subjects are restricted to 512 characters.java.lang.String
subject
The required message subject.long
timestamp
The message timestamp in Java millisecond epoch time.
-
Constructor Summary
Constructors Modifier Constructor Description protected
EMessage(EMessage.Builder<?,?> builder)
Creates a new eBus message based on the given message builder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object o)
Returnstrue
ifo
is a non-null EMessage
instance with a subject and timestamp equal tothis EMessage
instance andfalse
otherwise.int
hashCode()
Returns the message header hash code.boolean
isApplicationMessage()
Returnstrue
if this is an application message andfalse
otherwise.boolean
isSystemMessage()
Returnstrue
if this is a system message andfalse
otherwise.EMessageKey
key()
Returns the unique message key based on the message class and subject.EMessage.MessageType
messageType()
Returns themessage type
.java.time.Instant
timestampAsInstant()
Returns message timestamp as anInstant
rather than as an epoch millisecondlong
.java.lang.String
toString()
Returns message subject and timestamp as a string.
-
-
-
Field Detail
-
MAX_SUBJECT_LENGTH
public static final int MAX_SUBJECT_LENGTH
eBus subjects are restricted to 512 characters. eBus messages with subjects exceeding this limit cannot be created or de-serialized.- See Also:
- Constant Field Values
-
subject
public final java.lang.String subject
The required message subject. The subject and the message class are used to route this message to the intended eBus clients.
-
timestamp
public final long timestamp
The message timestamp in Java millisecond epoch time.
-
-
Constructor Detail
-
EMessage
protected EMessage(EMessage.Builder<?,?> builder)
Creates a new eBus message based on the given message builder.builder
is guaranteed to contain a valid message configuration at this point.- Parameters:
builder
- contains the eBus message configuration.
-
-
Method Detail
-
equals
public boolean equals(java.lang.Object o)
Returnstrue
ifo
is a non-null EMessage
instance with a subject and timestamp equal tothis EMessage
instance andfalse
otherwise.- Overrides:
equals
in classjava.lang.Object
- Parameters:
o
- comparison object.- Returns:
true
if the message fields are equal andfalse
otherwise.
-
hashCode
public int hashCode()
Returns the message header hash code.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- the message header hash code.
-
toString
public java.lang.String toString()
Returns message subject and timestamp as a string.- Overrides:
toString
in classjava.lang.Object
- Returns:
- the message as text.
-
key
public EMessageKey key()
Returns the unique message key based on the message class and subject.- Returns:
- the unique message key based on the message class and subject.
-
messageType
public EMessage.MessageType messageType()
Returns themessage type
.- Returns:
- the message type.
-
isSystemMessage
public boolean isSystemMessage()
Returnstrue
if this is a system message andfalse
otherwise. Only eBus is allowed to transmit a system message.- Returns:
true
if this is a system message andfalse
otherwise.
-
isApplicationMessage
public boolean isApplicationMessage()
Returnstrue
if this is an application message andfalse
otherwise.- Returns:
true
if this is an application message andfalse
otherwise.
-
timestampAsInstant
public java.time.Instant timestampAsInstant()
Returns message timestamp as anInstant
rather than as an epoch millisecondlong
.- Returns:
- message timestamp as
Instant
.
-
-