public abstract class MessageType extends DataType
EMessageObject sub-class. The serialized
binary format is:
EMessageObject class name (serialized as a
String).
EMessage and
EField classes to 31 fields.
EMessageObject class or its sub-class. This allows a
EMessage and EField to use an abstract class
extending EField as a field and initializing that
field with a concrete sub-class. This allows the message/field
to support new information without changing the message/field
class.
Note: as of eBus 4.4.0, messages are
automatically compiled when first used for serialization
or de-serialization. This increases the time it takes to
send or receive a message the first time. When a message
is frequently transmitted, it is recommended that the
message class is "compiled" by calling
DataType.findType(java.lang.Class) for that
message class. So when a message is sent or received the
first time, the message compilation is already done.
| Modifier and Type | Class and Description |
|---|---|
static class |
MessageType.MessageField
Stores a field index, field name, class field, eBus data
type.
|
| Modifier and Type | Field and Description |
|---|---|
static String |
BUILD_INNER_CLASS
EMessageObject subclasses must have an inner
class names "Builder" if the subclass has any
fields. |
static String |
BUILDER_METHOD
EMessageObject concrete subclass must have a
public static method named "builder" which takes
no arguments and returns an object which extends
EMessageObject.Builder. |
protected List<MessageType.MessageField> |
mFields
The message field names and types.
|
protected List<Class<? extends EReplyMessage>> |
mReplyClasses
If this a request message type, then this array specifies
the reply messages which may be sent in reply to the
request class.
|
protected String |
mSubject
EMessage has a public subject field but
this field is not serialized because it is
include in the message key identifier. |
static int |
PUBLIC_FINAL
Message fields must be public and final.
|
static int |
PUBLIC_STATIC
The "builder" method must be public and static.
|
static String |
SUBJECT_FIELD
Ignore the "subject" message field.
|
ADDRESS_TYPE, ARRAY_SUFFIX, CHARSET, CLASS_TYPE, EMPTY_STRING, FIELD_MASK_SIZE, INDENT, INDENT1, KEY_TYPE, MAX_ARRAY_SIZE, MAX_FIELDS, MAX_FILE_NAME_LENGTH, MAX_STRING_LENGTH, mBuiltinFlag, mClass, mDefaultValue, mSize, sClasses, sCompiledClasses, STRING_TYPE, VARIABLE_SIZE| Modifier | Constructor and Description |
|---|---|
protected |
MessageType(Class<?> clazz,
List<MessageType.MessageField> fields,
List<Class<? extends EReplyMessage>> replies)
Creates a new message type instance for the given class,
message fields, and constructor method handle.
|
| Modifier and Type | Method and Description |
|---|---|
protected Object |
deserializeFields(int fieldMask,
ByteBuffer buffer)
Returns an
EMessageObject de-serialized from the
given buffer. |
List<MessageType.MessageField> |
fields()
Returns the message object public fields.
|
protected static List<MessageType.MessageField> |
findFields(Class<? extends EMessageObject> mc)
|
boolean |
isValidReply(Class<?> clazz)
Returns
true if clazz is listed in the
allowed reply message class list and false if not. |
int |
numberFields()
Returns the number of fields in this
EMessage
type. |
List<Class<? extends EReplyMessage>> |
replyTypes()
Returns the reply classes associated with a request
message class.
|
protected int |
serializeFields(Object o,
ByteBuffer buffer)
Writes the message object fields to the given buffer and
returns the resulting field mask.
|
void |
subject(String subject)
Sets the message subject to the given value.
|
List<Object> |
values(EMessageObject message)
Returns the message object's field values as an
Object list. |
compareTo, createDeserializer, createSerializer, dataClass, dataClassName, defaultValue, deserialize, equals, fields, findCharset, findType, hashCode, isArray, isBuiltin, isEnum, isInstance, isLocalOnly, isMessage, isPrimitive, replyClasses, serialize, size, toStringpublic static final String BUILDER_METHOD
EMessageObject concrete subclass must have a
public static method named "builder" which takes
no arguments and returns an object which extends
EMessageObject.Builder.public static final String BUILD_INNER_CLASS
EMessageObject subclasses must have an inner
class names "Builder" if the subclass has any
fields.public static final int PUBLIC_STATIC
public static final int PUBLIC_FINAL
public static final String SUBJECT_FIELD
protected final List<MessageType.MessageField> mFields
map cannot be used to
match field names to field instances.protected final List<Class<? extends EReplyMessage>> mReplyClasses
protected String mSubject
EMessage has a public subject field but
this field is not serialized because it is
include in the message key identifier. But it must be
included in
EMessage.EMessage(java.lang.String, long)
constructor. This problem is resolved setting the
subject via subject(String) before de-serializing
the message.protected MessageType(Class<?> clazz, List<MessageType.MessageField> fields, List<Class<? extends EReplyMessage>> replies)
clazz - the message class instance.fields - the message fields.replies - reply classes associated with a request
message class. Will be an empty array for non-request
message types.public boolean isValidReply(Class<?> clazz)
true if clazz is listed in the
allowed reply message class list and false if not.
In short, returns true if clazz message
may be sent in reply to this request message type.clazz - the reply message class.true if clazz message
may be sent in reply to this request message type.public List<Class<? extends EReplyMessage>> replyTypes()
public List<Object> values(EMessageObject message) throws Throwable
Object list. The returned list values are in
the same order as fields().message - extract the field values from this message
object.Throwable - if any sort of error occurs when extracting the values
from message.public int numberFields()
EMessage
type.public List<MessageType.MessageField> fields()
public void subject(String subject) throws IllegalArgumentException
subject - de-serialized message subject.IllegalArgumentException - if subject is null or empty.protected int serializeFields(Object o, ByteBuffer buffer) throws BufferOverflowException
As of eBus v. 4.4.0, all EMessageObject classes
are automatically "compiled" - meaning that an
MessageType-subclass is generated for any given
EMessageObject subclass. The MessageType
subclass overrides this serializeFields method,
meaning this method implementation is never called.
Therefore, this method implementation has an empty body
and always returns zero.
o - write this EMessageObject's fields to
buffer. Note: o is not null.buffer - serialize fields to this buffer.BufferOverflowException - if buffer does not contain sufficient space to
store the message.protected Object deserializeFields(int fieldMask, ByteBuffer buffer) throws BufferUnderflowException, UnknownMessageException, ValidationException
EMessageObject de-serialized from the
given buffer.
As of eBus v. 4.4.0, all EMessageObject classes
are automatically "compiled" - meaning that an
MessageType-subclass is generated for any given
EMessageObject subclass. The MessageType
subclass overrides this deserializeFields method,
meaning this method implementation is never called.
Therefore, this method implementation has an empty body
and always returns null.
fieldMask - the message field mask specifying which
fields are serialized and which are null.buffer - read in the message from this buffer.BufferUnderflowException - if buffer contains an incomplete message.UnknownMessageException - if the serialized message is unknown to this eBus.ValidationException - if the message is incorrectly serialized.protected static List<MessageType.MessageField> findFields(Class<? extends EMessageObject> mc)
public final, non-static
fields (except EMessage.subject). The returned
fields are sorted by field name and field length with
longer fields preceding shorter fields. Two fields of the
same length are further sorted lexicographically by field
name.mc - message object subclass.Copyright © 2019. All rights reserved.