public class IMCMessage extends java.lang.Object implements IMessage, java.lang.Comparable<IMCMessage>
getMessageType()
and
header with getHeader()
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_ENTITY_ID |
static int |
DEFAULT_SYSTEM_ID |
Constructor and Description |
---|
IMCMessage()
Creates a new (dummy) message
|
IMCMessage(Header header)
Creates a new message based on an existing header and using default IMC
definitions
|
IMCMessage(IMCDefinition defs,
IMCMessageType type)
Creates a new message given its type.
|
IMCMessage(IMCMessageType type)
Creates a new IMCMessage given its type and using default IMC definitions
|
IMCMessage(java.lang.Integer type)
Uses the default IMC definitions and calls
IMCMessage(IMCDefinition, Integer) |
IMCMessage(java.lang.String abbreviatedName)
Resolves the type, given an abbreviated name and creates a corresponding
message using default IMC definitions
|
IMCMessage(java.lang.String abbreviatedName,
java.lang.Object... values)
Creates a new message given its abbreviated name and fills it with given
values
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
asJSON()
Retrieve this message as a JSON string
|
java.lang.String |
asJSON(boolean includeHeader) |
java.util.Map<java.lang.String,java.lang.Object> |
asMap(boolean inner) |
java.lang.String |
asXml(boolean isInline) |
java.lang.String |
asXmlStripped(int tabAmount,
boolean isInline) |
IMCMessage |
cloneMessage()
Creates a cloned message with copied values
|
IMCMessage |
cloneMessage(IMCDefinition defs)
Create a copy of this message using the given definitions.
|
int |
compareTo(IMCMessage arg0)
Natural order uses the timestamp of the message for comparison
|
IMCMessage |
copyFrom(IMCMessage otherMessage)
Set all values from another message of same type
|
static java.util.LinkedHashMap<java.lang.String,java.lang.String> |
decodeTupleList(java.lang.String tupleList)
Reverse from
encodeTupleList(LinkedHashMap) |
void |
dump(java.io.OutputStream err)
Write this message as text into the given OutputStream.
|
static java.lang.String |
encodeTupleList(java.util.LinkedHashMap<java.lang.String,?> map)
Given a map of Strings to Objects, encodes a tuplelist in the type:
name1=value1;name2=value2 ...
|
<T> T |
get(java.lang.String field,
java.lang.Class<T> type) |
java.lang.String |
getAbbrev() |
double |
getAgeInSeconds()
Calculates the difference between current time and the timestamp in this
message
|
java.lang.Number |
getAsNumber(java.lang.String fieldName)
Retrieve the value of the field as a Number
|
java.lang.String |
getAsString(java.lang.String fieldName)
Retrieve the value of a field as a String
|
java.util.LinkedHashMap<java.lang.String,java.lang.Boolean> |
getBitmask(java.lang.String field)
Retrieves the value of a Bitmask as map of booleans
|
java.util.Date |
getDate()
Retrieve the timestamp of this message as a Date
|
double |
getDouble(java.lang.String field)
Retrives the value of a field as a double value.
|
int |
getDst()
The numeric id of this message destination (header field "dst")
|
short |
getDstEnt()
Retrieve IMC id of this message destination entity (header field
"dst_ent")
|
java.lang.String |
getEntityName() |
java.lang.String[] |
getFieldNames() |
float |
getFloat(java.lang.String field)
Retrives the value of a field as a float value.
|
Header |
getHeader()
Retrieves the header of this message, stored as an inner IMC Message
(payload fields match header fields and header is NULL)
|
java.lang.Object |
getHeaderValue(java.lang.String field)
Retrieve a value from the header
|
int |
getInteger(java.lang.String field)
Retrives the value of a field as an integer value.
|
long |
getLong(java.lang.String field)
Retrives the value of a field as a long value.
|
java.lang.String |
getLongFieldName(java.lang.String fieldName)
Retrieve the long name (human readable) of a given field
|
java.lang.String |
getLongName() |
<T extends IMCMessage> |
getMessage(java.lang.Class<T> clazz,
java.lang.String field)
Retrieves an IMCMessage from a field and converts it to a chosen type.
Example: |
IMCMessage |
getMessage(java.lang.String field)
Retrieves an IMCMesssage from a field (used for inline messages)
|
pt.lsts.neptus.messages.listener.MessageInfo |
getMessageInfo() |
java.util.Vector<IMCMessage> |
getMessageList(java.lang.String field)
Retrieve all the messages in a MessageList as a Vector
|
<T extends IMCMessage> |
getMessageList(java.lang.String field,
java.lang.Class<T> clazz)
Retrieve a message list from this message using a given type
|
IMCMessageType |
getMessageType() |
int |
getMgid() |
int |
getPayloadSize() |
IMessageProtocol<? extends IMessage> |
getProtocolFactory() |
byte[] |
getRawData(java.lang.String field)
Returns a byte array from a rawdata field
|
int |
getSize()
Retrieve the size indicated on the header of this message (header field
"size")
|
java.lang.String |
getSourceName() |
int |
getSrc()
Retrieve IMC id of this message source (header field "src")
|
short |
getSrcEnt()
Retrieve IMC id of this message source entity (header field "src_ent")
|
java.lang.String |
getString(java.lang.String field)
Returns a String representation for the value in the given field
|
java.lang.String |
getString(java.lang.String field,
boolean addUnits) |
double |
getTimestamp() |
long |
getTimestampMillis() |
java.util.LinkedHashMap<java.lang.String,java.lang.String> |
getTupleList(java.lang.String field)
Returns the value of a field as an hash map
|
java.lang.String |
getTypeOf(java.lang.String fieldName)
Retrieve the field type of the given field
|
java.lang.String |
getUnitsOf(java.lang.String fieldName)
Retrieves the units of the given field
|
java.lang.Object |
getValue(java.lang.String field)
Retrieve a value in the message
|
java.util.Map<java.lang.String,java.lang.Object> |
getValues()
Returns all the values in this message.
|
boolean |
hasFlag(java.lang.String flagName)
Verify if the message has the given flag set
|
void |
hexdump(java.io.OutputStream err) |
boolean |
isNull()
Check in this is a null inline message
|
boolean |
isPeriodic() |
static void |
main(java.lang.String[] args) |
void |
makeImmutable()
This method enforces all values in this message as immutable.
|
static IMCMessage |
parseJson(java.lang.String json) |
static IMCMessage |
parseXml(java.lang.String xml)
Parse an IMC-XML file and retrieve the messages found on the file
|
byte[] |
payloadMD5()
Compute this message's payload MD5
|
int |
serialize(java.nio.ByteBuffer destination,
int offset) |
int |
serialize(IMCDefinition def,
IMCOutputStream out)
Writes this message to an OutputStream
|
int |
serialize(IMCOutputStream out)
Serialize this message to an IMCOutputStream
|
int |
serializePayload(java.nio.ByteBuffer destination,
int offset) |
void |
setBitMask(java.lang.String field,
java.util.LinkedHashMap<java.lang.String,java.lang.Boolean> bitmask)
Set the value of a bitmask field using a map from Strings to Booleans
|
void |
setDst(int dst)
Set the destination of this message (header field "dst")
|
void |
setDstEnt(int dst_ent)
Set the destination entity of this message (header field "dst_ent")
|
void |
setHeader(Header header)
Change the header of this message
|
void |
setMessageInfo(pt.lsts.neptus.messages.listener.MessageInfo messageInfo) |
void |
setMessageList(java.util.Vector<? extends IMCMessage> messages,
java.lang.String field)
This method receives a vector of messages and sets a field with a
MessageList of those messages
|
void |
setSrc(int src)
Set the source of this message (header field "src")
|
void |
setSrcEnt(int src_ent)
Set the source entity of this message (header field "src_ent")
|
void |
setTimestamp(double time)
Change the timestamp of this message (stored in the header field "time")
|
void |
setTimestampMillis(long timestampMillis) |
void |
setType(IMCMessageType type)
Change the type of the message.
|
IMCMessage |
setValue(java.lang.String field,
java.lang.Object value)
Sets a field value
|
void |
setValues(java.util.Map<java.lang.String,java.lang.Object> values)
All the values in the given hashtable will be copied to this message
without any conversions
|
java.lang.String |
toString()
Returns a String representation of this message (used for debugging)
|
void |
validate()
Verifies if the message is valid by generating exceptions when the message is not valid
|
public static final int DEFAULT_ENTITY_ID
public static final int DEFAULT_SYSTEM_ID
public IMCMessage()
public IMCMessage(IMCMessageType type)
type
- The IMCMessageType
of the message to be createdpublic IMCMessage(Header header)
header
- The header of the message, which will define its typepublic IMCMessage(java.lang.Integer type)
IMCMessage(IMCDefinition, Integer)
type
- The type (mgid) of the message to be createdpublic IMCMessage(java.lang.String abbreviatedName)
abbreviatedName
- The abbreviated name of the message to be createdpublic IMCMessage(java.lang.String abbreviatedName, java.lang.Object... values)
abbreviatedName
- The message's abbreviated namevalues
- A list of objects which will be parse in pairs. IMCMessage state = new IMCMessage("EstimatedState", "ref", "NED_ONLY", "x", 10.343, y, -100);
public IMCMessage(IMCDefinition defs, IMCMessageType type)
type
- The type for this message.public final IMCMessageType getMessageType()
public Header getHeader()
public void setHeader(Header header)
header
- The new header for this messagepublic IMCMessage copyFrom(IMCMessage otherMessage) throws java.lang.Exception
otherMessage
- Message where to read values fromjava.lang.Exception
- In case the types of the messages do not matchpublic void setValues(java.util.Map<java.lang.String,java.lang.Object> values)
values
- public java.util.Map<java.lang.String,java.lang.Object> getValues()
UnsupportedOperationException
will be
thrownpublic void setType(IMCMessageType type)
type
- The new type for this messagepublic IMCMessage cloneMessage(IMCDefinition defs)
defs
- The definitions to be used when cloning the messagepublic IMCMessage cloneMessage()
cloneMessage
in interface IMessage
public int getSrc()
public java.lang.String getSourceName()
public java.lang.String getEntityName()
public int getDst()
public short getSrcEnt()
public short getDstEnt()
public int getSize()
public void setSrc(int src)
src
- The new source of this messagepublic void setDst(int dst)
src
- The destination of this messagepublic void setSrcEnt(int src_ent)
src
- The source entity of this messagepublic void setDstEnt(int dst_ent)
src
- The destination entity of this messagepublic int getPayloadSize()
public IMCMessage setValue(java.lang.String field, java.lang.Object value)
setValue
in interface IMessage
field
- The field to be setvalue
- The new value for the field. public java.lang.Object getHeaderValue(java.lang.String field)
getHeaderValue
in interface IMessage
field
- The name of the field to retrievepublic java.lang.Object getValue(java.lang.String field)
public static java.lang.String encodeTupleList(java.util.LinkedHashMap<java.lang.String,?> map)
map
- A map from Strings (var names) to Objects (values)public static java.util.LinkedHashMap<java.lang.String,java.lang.String> decodeTupleList(java.lang.String tupleList)
encodeTupleList(LinkedHashMap)
tupleList
- An encoded tuplelistpublic java.util.LinkedHashMap<java.lang.String,java.lang.String> getTupleList(java.lang.String field)
field
- The name of the field (should be a tuplelist)public java.util.LinkedHashMap<java.lang.String,java.lang.Boolean> getBitmask(java.lang.String field)
field
- The name of the field (should be a Bitmask)public void setBitMask(java.lang.String field, java.util.LinkedHashMap<java.lang.String,java.lang.Boolean> bitmask)
public double getDouble(java.lang.String field)
field
- The name of the field (should be numeric)public float getFloat(java.lang.String field)
field
- The name of the field (should be numeric)public int getInteger(java.lang.String field)
field
- The name of the field (should be numeric)public long getLong(java.lang.String field)
field
- The name of the field (should be numeric)public java.lang.String getString(java.lang.String field, boolean addUnits)
public java.lang.String getString(java.lang.String field)
field
- The field to be returned as Stringpublic byte[] getRawData(java.lang.String field)
field
- The field whose value is to be returnedpublic IMCMessage getMessage(java.lang.String field)
field
- The field whose value is to be returnedpublic <T extends IMCMessage> T getMessage(java.lang.Class<T> clazz, java.lang.String field) throws java.lang.Exception
PlanSpecification plan = planControl.getMessage(PlanSpecification.class, "arg");
clazz
- The expected class of the inline messagefield
- The field corresponding to the inline messagejava.lang.Exception
public java.util.Vector<IMCMessage> getMessageList(java.lang.String field)
field
- The name of the field in this message which is of type
MessageListpublic void setMessageList(java.util.Vector<? extends IMCMessage> messages, java.lang.String field)
messages
- The messages in the MessageListfield
- The field to be set with a list of messagespublic <T extends IMCMessage> java.util.Vector<T> getMessageList(java.lang.String field, java.lang.Class<T> clazz) throws java.lang.Exception
field
- The field from where to retrieve the message listclazz
- The type of the messages in this listjava.lang.Exception
- If the messages found do not correspond to expected typepublic java.lang.String toString()
toString
in class java.lang.Object
public int serialize(IMCDefinition def, IMCOutputStream out) throws java.io.IOException
out
- The OutputStream to write tojava.io.IOException
public int serialize(IMCOutputStream out) throws java.io.IOException
java.io.IOException
public void setTimestamp(double time)
time
- The new unix time (seconds since 1970)public void setTimestampMillis(long timestampMillis)
public long getTimestampMillis()
public double getTimestamp()
public java.util.Date getDate()
public java.lang.Number getAsNumber(java.lang.String fieldName)
IMessage
getAsNumber
in interface IMessage
fieldName
- The name of the field to consultpublic java.lang.String getAsString(java.lang.String fieldName)
IMessage
getAsString
in interface IMessage
fieldName
- The name of the field to consultpublic int getMgid()
public java.lang.String getAbbrev()
public java.lang.String getLongName()
getLongName
in interface IMessage
public java.lang.String[] getFieldNames()
getFieldNames
in interface IMessage
public java.lang.String getLongFieldName(java.lang.String fieldName)
IMessage
getLongFieldName
in interface IMessage
fieldName
- The field's (abbreviated) namepublic java.lang.String getTypeOf(java.lang.String fieldName)
IMessage
public java.lang.String getUnitsOf(java.lang.String fieldName)
IMessage
getUnitsOf
in interface IMessage
public boolean hasFlag(java.lang.String flagName)
IMessage
public boolean isPeriodic()
public void validate() throws InvalidMessageException
IMessage
validate
in interface IMessage
InvalidMessageException
public IMessageProtocol<? extends IMessage> getProtocolFactory()
getProtocolFactory
in interface IMessage
public boolean isNull()
public void dump(java.io.OutputStream err)
IMCMessage estate = new IMCMessage("EstimatedState"); estate.dump(System.out);
err
- Where to write this message to.public void hexdump(java.io.OutputStream err)
public static IMCMessage parseJson(java.lang.String json)
public java.lang.String asJSON()
public java.lang.String asJSON(boolean includeHeader)
public java.lang.String asXmlStripped(int tabAmount, boolean isInline)
public java.util.Map<java.lang.String,java.lang.Object> asMap(boolean inner)
public java.lang.String asXml(boolean isInline)
public byte[] payloadMD5()
public <T> T get(java.lang.String field, java.lang.Class<T> type) throws java.lang.ClassCastException
java.lang.ClassCastException
public static IMCMessage parseXml(java.lang.String xml) throws java.lang.Exception
xml
- The xml to be parsedjava.lang.Exception
- Malformed XML, incompatible types, etcpublic int compareTo(IMCMessage arg0)
compareTo
in interface java.lang.Comparable<IMCMessage>
public double getAgeInSeconds()
public void makeImmutable()
public final pt.lsts.neptus.messages.listener.MessageInfo getMessageInfo()
public int serialize(java.nio.ByteBuffer destination, int offset)
public int serializePayload(java.nio.ByteBuffer destination, int offset)
public final void setMessageInfo(pt.lsts.neptus.messages.listener.MessageInfo messageInfo)
messageInfo
- the messageInfo to setpublic static void main(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception