public class ImcSystemState
extends java.lang.Object
Constructor and Description |
---|
ImcSystemState(IMCDefinition definitions)
Class constructor
|
Modifier and Type | Method and Description |
---|---|
java.util.Collection<java.lang.String> |
availableMessages()
Retrieve a list of received message types
|
void |
clear()
Clears this state and becomes inactive
|
java.lang.Object |
expr(java.lang.String expression) |
IMCMessage |
get(int msgId)
Retrieve the last message of a given type
|
IMCMessage |
get(int msgId,
int entityId)
Retrieve the last message of given type, generated in given entity
|
java.lang.Object |
get(int msgId,
int entityId,
java.lang.String field)
Retrieve the value of a given field
|
java.lang.Object |
get(int msgId,
java.lang.String field)
Retrieve the value of a given field
|
<T> T |
get(int msgId,
java.lang.String field,
java.lang.Class<T> type)
Retrieve the value of the field in the last received message, casting it
to desired type
|
IMCMessage |
get(java.lang.String messageAbbrev)
Retrieve the last received message of given type (independently of the
originating entity)
|
<T> T |
get(java.lang.String query,
java.lang.Class<T> type)
Retrieve data from this state
|
IMCDefinition |
getDefinitions()
Get the definitions being used to generate this state
|
double |
getDouble(java.lang.String query)
Same as get(query, Double.class)
|
java.lang.String |
getEntityName(int entityId)
Retrieve the name of the entity with given id (numeric)
|
int |
getInteger(java.lang.String query)
Same as get(query, Integer.class)
|
long |
getLong(java.lang.String query)
Same as get(query, Long.class)
|
IMCMessage |
getMessage(java.lang.String query)
Same as get(query, IMCMessage.class)
|
byte[] |
getRawData(java.lang.String query)
Same as get(query, String.class)
|
java.lang.String |
getString(java.lang.String query)
Same as get(query, String.class)
|
boolean |
isActive()
Verify if a system was already visible in the network
|
boolean |
isIgnoreEntities() |
<T extends IMCMessage> |
last(java.lang.Class<T> msgType)
Retrieve the last received message of a certain type
|
<T extends IMCMessage> |
last(java.lang.Class<T> msgType,
java.lang.String entity)
Retrieve the last received message of a certain type and specific entity
|
java.util.LinkedHashMap<java.lang.String,IMCMessage> |
lastMessagesOfType(java.lang.String messageAbbrev)
Retrieve all messages of the given type in this state (divided by entity
that created them)
|
static void |
main(java.lang.String[] args) |
<T extends IMCMessage> |
poll(java.lang.Class<T> msgType,
long timeoutMillis)
Wait for the next message of a certain type
|
<T extends IMCMessage> |
poll(java.lang.Class<T> msgType,
java.lang.String entityName,
long timeoutMillis)
Wait for the next message of a certain type, coming from a specific
entity
|
IMCMessage |
poll(java.lang.String messageType,
long timeoutMillis)
This method waits (blocks) and retrieves the next message of given type
|
IMCMessage |
poll(java.lang.String messageType,
java.lang.String entityName,
long timeoutMillis)
This method waits (blocks) and retrieves the next message of given type
|
void |
setIgnoreEntities(boolean ignoreEntities) |
void |
setMessage(IMCMessage msg)
Update this state by appending this message
|
public ImcSystemState(IMCDefinition definitions)
definitions
- The IMC definitions to be usedpublic IMCMessage poll(java.lang.String messageType, long timeoutMillis)
messageType
- The abbreviated name of the message to be retrievedtimeoutMillis
- The maximum number of milliseconds to blockpublic IMCMessage poll(java.lang.String messageType, java.lang.String entityName, long timeoutMillis)
messageType
- The abbreviated name of the message to be retrievedtimeoutMillis
- The maximum number of milliseconds to blockpublic <T extends IMCMessage> T last(java.lang.Class<T> msgType)
msgType
- The class to be receivednull if no such message exists.
-
last
public <T extends IMCMessage> T last(java.lang.Class<T> msgType,
java.lang.String entity)
Retrieve the last received message of a certain type and specific entity
- Parameters:
msgType
- The class to be received
entity
- The entity that should have produced the message
- Returns:
- The last received message of given type or
null if no such message exists.
-
poll
public <T extends IMCMessage> T poll(java.lang.Class<T> msgType,
long timeoutMillis)
Wait for the next message of a certain type
- Parameters:
msgType
- The type to be expected
timeoutMillis
- The maximum amount of time to wait for the message
- Returns:
- The newly received message or
null if no such message was received.
-
poll
public <T extends IMCMessage> T poll(java.lang.Class<T> msgType,
java.lang.String entityName,
long timeoutMillis)
Wait for the next message of a certain type, coming from a specific
entity
- Parameters:
msgType
- The type to be expected
entityName
- The name of the entity that should be producing the message
timeoutMillis
- The maximum amount of time to wait for the message
- Returns:
- The newly received message or
null if no such message was received.
-
isActive
public boolean isActive()
Verify if a system was already visible in the network
- Returns:
- false if this state is empty (no messages were
received)
-
setMessage
public void setMessage(IMCMessage msg)
Update this state by appending this message
- Parameters:
msg
- The message to be integrated into this IMC state
-
clear
public void clear()
Clears this state and becomes inactive
-
lastMessagesOfType
public final java.util.LinkedHashMap<java.lang.String,IMCMessage> lastMessagesOfType(java.lang.String messageAbbrev)
Retrieve all messages of the given type in this state (divided by entity
that created them)
- Parameters:
messageAbbrev
- The name of the message to be retrieved
- Returns:
- A map from Strings to messages as follows:
"MessageAbbrev" -> IMCMessage
"MessageAbbrev.Entity1" -> IMCMessage
"MessageAbbrev.Entity2" -> IMCMessage
...
Thus, the last received message (from all
entities) will be repeated in the "MessageAbbrev" entry of the
HashMap
-
expr
public java.lang.Object expr(java.lang.String expression)
-
get
public final IMCMessage get(java.lang.String messageAbbrev)
Retrieve the last received message of given type (independently of the
originating entity)
- Parameters:
messageAbbrev
- The name of the message to be retrieved
- Returns:
- the last received message of given type (independently of the
originating entity)
-
get
public final IMCMessage get(int msgId)
Retrieve the last message of a given type
- Parameters:
msgId
- The imc id of the message type
- Returns:
- the last received message of given type (independently of the
originating entity)
-
get
public final IMCMessage get(int msgId,
int entityId)
Retrieve the last message of given type, generated in given entity
- Parameters:
msgId
- The imc id of the message type
entityId
- The numeric id of the entity
- Returns:
- the last received message of given type (independently of the
originating entity)
-
getEntityName
public java.lang.String getEntityName(int entityId)
Retrieve the name of the entity with given id (numeric)
- Parameters:
entityId
- The numeric id of the entity
- Returns:
- The name of the entity or the numeric value converted to String
if no entity with that id is recognized
-
get
public final java.lang.Object get(int msgId,
int entityId,
java.lang.String field)
Retrieve the value of a given field
- Parameters:
msgId
- The imc id of the message type
entityId
- The numeric id of the entity
field
- The name of the field to be retrieved
- Returns:
- The value of the requested field (null if not found)
-
get
public final java.lang.Object get(int msgId,
java.lang.String field)
Retrieve the value of a given field
- Parameters:
msgId
- The imc id of the message type
field
- The name of the field to be retrieved
- Returns:
- The value of the field in the last received message of given type
(independently of originating entity)
-
get
public final <T> T get(int msgId,
java.lang.String field,
java.lang.Class<T> type)
throws java.lang.ClassCastException
Retrieve the value of the field in the last received message, casting it
to desired type
- Parameters:
msgId
- The imc id of the message type
field
- The name of the field to be retrieved
type
- The value of the field in the last received message of given
type (independently of originating entity)
- Returns:
- Throws:
java.lang.ClassCastException
-
get
public final <T> T get(java.lang.String query,
java.lang.Class<T> type)
Retrieve data from this state
- Parameters:
query
- The query to be performed. Valid queries:
- "MessageAbbrev" -> retrieve the last message of type
"MessageAbbrev"
- "MessageAbbrev.EntityName" -> retrieve the last message of
type "MessageAbbrev" generated by "EntityName"
- "MessageAbbrev.EntityName.FieldName" -> retrieve the value
of the field named "FieldName" from the last message of type
"MessageAbbrev" generated by "EntityName"
- "MessageAbbrev.*.FieldName" -> retrieve the value of the
field named "FieldName" from the last message of type
"MessageAbbrev"
type
- The desired type of the return
- Returns:
- The requested data, or null if no messages /
fields match the query.
-
getDouble
public double getDouble(java.lang.String query)
Same as get(query, Double.class)
- See Also:
#get(String, Class)}
-
getString
public java.lang.String getString(java.lang.String query)
Same as get(query, String.class)
- See Also:
#get(String, Class)}
-
getInteger
public int getInteger(java.lang.String query)
Same as get(query, Integer.class)
- See Also:
#get(String, Class)}
-
getLong
public long getLong(java.lang.String query)
Same as get(query, Long.class)
- See Also:
#get(String, Class)}
-
getRawData
public byte[] getRawData(java.lang.String query)
Same as get(query, String.class)
- See Also:
#get(String, Class)}
-
getMessage
public IMCMessage getMessage(java.lang.String query)
Same as get(query, IMCMessage.class)
- See Also:
#get(String, Class)}
-
availableMessages
public final java.util.Collection<java.lang.String> availableMessages()
Retrieve a list of received message types
- Returns:
- a list of received message types
-
getDefinitions
public final IMCDefinition getDefinitions()
Get the definitions being used to generate this state
- Returns:
- the definitions being used to generate this state
-
isIgnoreEntities
public boolean isIgnoreEntities()
-
setIgnoreEntities
public void setIgnoreEntities(boolean ignoreEntities)
-
main
public static void main(java.lang.String[] args)
throws java.lang.Exception
- Throws:
java.lang.Exception