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.
public <T extends IMCMessage> T last(java.lang.Class<T> msgType, java.lang.String entity)
msgType
- The class to be receivedentity
- The entity that should have produced the messagenull if no such message exists.
public <T extends IMCMessage> T poll(java.lang.Class<T> msgType, long timeoutMillis)
msgType
- The type to be expectedtimeoutMillis
- The maximum amount of time to wait for the messagenull if no such message was received.
public <T extends IMCMessage> T poll(java.lang.Class<T> msgType, java.lang.String entityName, long timeoutMillis)
msgType
- The type to be expectedentityName
- The name of the entity that should be producing the messagetimeoutMillis
- The maximum amount of time to wait for the messagenull if no such message was received.
public boolean isActive()
public void setMessage(IMCMessage msg)
msg
- The message to be integrated into this IMC statepublic void clear()
public final java.util.LinkedHashMap<java.lang.String,IMCMessage> lastMessagesOfType(java.lang.String messageAbbrev)
messageAbbrev
- The name of the message to be retrieved"MessageAbbrev" -> IMCMessageThus, the last received message (from all entities) will be repeated in the "MessageAbbrev" entry of the HashMap
"MessageAbbrev.Entity1" -> IMCMessage
"MessageAbbrev.Entity2" -> IMCMessage
...
public java.lang.Object expr(java.lang.String expression)
public final IMCMessage get(java.lang.String messageAbbrev)
messageAbbrev
- The name of the message to be retrievedpublic final IMCMessage get(int msgId)
msgId
- The imc id of the message typepublic final IMCMessage get(int msgId, int entityId)
msgId
- The imc id of the message typeentityId
- The numeric id of the entitypublic java.lang.String getEntityName(int entityId)
entityId
- The numeric id of the entitypublic final java.lang.Object get(int msgId, int entityId, java.lang.String field)
msgId
- The imc id of the message typeentityId
- The numeric id of the entityfield
- The name of the field to be retrievedpublic final java.lang.Object get(int msgId, java.lang.String field)
msgId
- The imc id of the message typefield
- The name of the field to be retrievedpublic final <T> T get(int msgId, java.lang.String field, java.lang.Class<T> type) throws java.lang.ClassCastException
msgId
- The imc id of the message typefield
- The name of the field to be retrievedtype
- The value of the field in the last received message of given
type (independently of originating entity)java.lang.ClassCastException
public final <T> T get(java.lang.String query, java.lang.Class<T> type)
query
- The query to be performed. Valid queries:
type
- The desired type of the returnpublic double getDouble(java.lang.String query)
#get(String, Class)}
public java.lang.String getString(java.lang.String query)
#get(String, Class)}
public int getInteger(java.lang.String query)
#get(String, Class)}
public long getLong(java.lang.String query)
#get(String, Class)}
public byte[] getRawData(java.lang.String query)
#get(String, Class)}
public IMCMessage getMessage(java.lang.String query)
#get(String, Class)}
public final java.util.Collection<java.lang.String> availableMessages()
public final IMCDefinition getDefinitions()
public boolean isIgnoreEntities()
public void setIgnoreEntities(boolean ignoreEntities)
public static void main(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception