use of org.openmuc.framework.parser.spi.SerializationException in project OpenMUC by isc-konstanz.
the class MqttLogMsgBuilder method logSingle.
private List<MqttLogMsg> logSingle(List<LoggingRecord> loggingRecords) {
List<MqttLogMsg> logMessages = new ArrayList<>();
for (LoggingRecord loggingRecord : loggingRecords) {
try {
String topic = channelsToLog.get(loggingRecord.getChannelId()).topic;
byte[] message = parserService.serialize(loggingRecord);
logMessages.add(new MqttLogMsg(loggingRecord.getChannelId(), message, topic));
} catch (SerializationException e) {
logger.error("failed to parse records {}", e.getMessage());
}
}
return logMessages;
}
use of org.openmuc.framework.parser.spi.SerializationException in project OpenMUC by isc-konstanz.
the class AmqpDriverConnection method write.
@Override
public Object write(List<ChannelValueContainer> containers, Object containerListHandle) throws UnsupportedOperationException {
for (ChannelValueContainer container : containers) {
Record record = new Record(container.getValue(), System.currentTimeMillis());
if (parsers.containsKey(setting.parser)) {
byte[] message = new byte[0];
try {
message = parsers.get(setting.parser).serialize(record, container);
} catch (SerializationException e) {
logger.error(e.getMessage());
}
writer.write(container.getChannelAddress(), message);
container.setFlag(Flag.VALID);
} else {
throw new UnsupportedOperationException("A parser is needed to write messages");
}
}
return null;
}
use of org.openmuc.framework.parser.spi.SerializationException in project OpenMUC by isc-konstanz.
the class MqttLogMsgBuilder method logMultiple.
private List<MqttLogMsg> logMultiple(List<LoggingRecord> loggingRecords) {
List<MqttLogMsg> logMessages = new ArrayList<>();
if (hasDifferentTopics()) {
throw new UnsupportedOperationException("logMultiple feature is an experimental feature: logMultiple=true is not possible with " + "different topics in logSettings. Set logMultiple=false OR leave it true " + "and assign same topic to all channels.");
// TODO make improvement: check only for given channels
// TODO make improvement:
// CASE A - OK
// ch1, ch2, ch3 = 5 s - topic1
// CASE B - NOT SUPPORTED YET
// ch1, ch2 logInterval = 5 s - topic1
// ch3, ch3 logInterval = 10 s - topic2
// ch4 logInterval 20 s - topic 3
// if isLogMultiple=true, then group channels per topic
// or default: log warning and use logSingle instead
} else {
try {
// since all topics are the same, get the topic of
String topic = channelsToLog.get(loggingRecords.get(0).getChannelId()).topic;
byte[] message = parserService.serialize(loggingRecords);
String channelIds = loggingRecords.stream().map(record -> record.getChannelId()).collect(Collectors.toList()).toString();
logMessages.add(new MqttLogMsg(channelIds, message, topic));
} catch (SerializationException e) {
logger.error("failed to parse records {}", e.getMessage());
}
}
return logMessages;
}
use of org.openmuc.framework.parser.spi.SerializationException in project OpenMUC by isc-konstanz.
the class MqttDriverConnection method write.
@Override
public Object write(List<ChannelValueContainer> containers, Object containerListHandle) throws UnsupportedOperationException, ConnectionException {
for (ChannelValueContainer container : containers) {
Record record = new Record(container.getValue(), System.currentTimeMillis());
if (parsers.containsKey(settings.getProperty("parser"))) {
byte[] message;
try {
message = parsers.get(settings.getProperty("parser")).serialize(record, container);
} catch (SerializationException e) {
logger.error(e.getMessage());
continue;
}
String topic = Stream.of(container.getChannelAddress().split(";")).findFirst().orElse(ChannelConfig.ADDRESS_DEFAULT);
mqttWriter.write(topic, message);
container.setFlag(Flag.VALID);
} else {
logger.error("A parser is needed to write messages and none have been registered.");
throw new UnsupportedOperationException();
}
}
return null;
}
Aggregations