use of org.openremote.agent.protocol.simulator.SimulatorProtocol in project openremote by openremote.
the class SimulatorService method publishSimulatorState.
protected void publishSimulatorState(String sessionKey, String agentId) {
LOG.finer("Attempting to publish simulator state: Agent ID=" + agentId);
Protocol<?> protocol = agentService.getProtocolInstance(agentId);
if (!(protocol instanceof SimulatorProtocol)) {
LOG.warning("Failed to publish simulator state, agent is not a simulator agent: Agent ID=" + agentId);
return;
}
SimulatorProtocol simulatorProtocol = (SimulatorProtocol) protocol;
SimulatorState simulatorState = getSimulatorState(simulatorProtocol);
if (sessionKey != null) {
clientEventService.sendToSession(sessionKey, simulatorState);
} else {
clientEventService.publishEvent(simulatorState);
}
}
use of org.openremote.agent.protocol.simulator.SimulatorProtocol in project openremote by openremote.
the class SimulatorService method getSimulatorState.
/**
* Get info about all attributes linked to this instance (for frontend usage)
*/
protected SimulatorState getSimulatorState(SimulatorProtocol protocolInstance) {
return withLockReturning(protocolInstance.getProtocolInstanceUri() + "::getSimulatorInfo", () -> {
LOG.info("Getting simulator info for protocol instance: " + protocolInstance);
// We need asset names instead of identifiers for user-friendly display
List<String> linkedAssetIds = protocolInstance.getLinkedAttributes().keySet().stream().map(AttributeRef::getId).distinct().collect(Collectors.toList());
List<String> assetNames = assetStorageService.findNames(linkedAssetIds.toArray(new String[0]));
if (assetNames.size() != linkedAssetIds.size()) {
LOG.warning("Retrieved asset names don't match requested asset IDs");
return null;
}
SimulatorAttributeInfo[] attributeInfos = protocolInstance.getLinkedAttributes().entrySet().stream().map(refAttributeEntry -> {
String assetName = assetNames.get(linkedAssetIds.indexOf(refAttributeEntry.getKey().getId()));
return new SimulatorAttributeInfo(assetName, refAttributeEntry.getKey().getId(), refAttributeEntry.getValue(), protocolInstance.getReplayMap().containsKey(refAttributeEntry.getKey()));
}).toArray(SimulatorAttributeInfo[]::new);
return new SimulatorState(protocolInstance.getAgent().getId(), attributeInfos);
});
}
Aggregations