use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ThrowingConsumer in project open-smart-grid-platform by OSGP.
the class GetFirmwareFileResponseMessageProcessor method processMessage.
@Override
public void processMessage(final ObjectMessage message) throws JMSException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Processing {} response message", this.messageType.name());
}
// Get metadata from message and update message type to update
// firmware
final MessageMetadata messageMetadata = new MessageMetadata.Builder(MessageMetadata.fromMessage(message)).withMessageType(MessageType.UPDATE_FIRMWARE.name()).build();
final Serializable messageObject = message.getObject();
final ThrowingConsumer<DlmsConnectionManager> taskForConnectionManager = conn -> this.processMessageTasks(messageObject, messageMetadata, conn);
try {
this.createAndHandleConnectionForDevice(this.domainHelperService.findDlmsDevice(messageMetadata), messageMetadata, taskForConnectionManager);
} catch (final OsgpException e) {
LOGGER.error("Something went wrong with the DlmsConnection", e);
}
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ThrowingConsumer in project open-smart-grid-platform by OSGP.
the class OsgpResponseMessageProcessor method processMessage.
@Override
public void processMessage(final ObjectMessage message) throws JMSException {
LOGGER.debug("Processing {} request message", this.messageType);
final MessageMetadata messageMetadata = MessageMetadata.fromMessage(message);
final Serializable messageObject = message.getObject();
final ThrowingConsumer<DlmsConnectionManager> taskForConnectionManager = conn -> this.processMessageTask(messageObject, messageMetadata, conn);
try {
if (this.usesDeviceConnection()) {
this.createAndHandleConnectionForDevice(this.domainHelperService.findDlmsDevice(messageMetadata), messageMetadata, taskForConnectionManager);
} else {
this.processMessageTask(messageObject, messageMetadata, null);
}
} catch (final OsgpException e) {
LOGGER.error("Something went wrong with the DlmsConnection", e);
}
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ThrowingConsumer in project open-smart-grid-platform by OSGP.
the class DeviceRequestMessageProcessor method processMessage.
@Override
public void processMessage(final ObjectMessage message) throws JMSException {
log.debug("Processing {} request message", this.messageType);
final MessageMetadata messageMetadata = MessageMetadata.fromMessage(message);
final Serializable messageObject = message.getObject();
try {
final DlmsDevice device;
if (this.requiresExistingDevice()) {
device = this.domainHelperService.findDlmsDevice(messageMetadata);
} else {
device = null;
}
if (this.usesDeviceConnection()) {
/*
* Set up a consumer to be called back with a DlmsConnectionManager for which the connection
* with the device has been created. Note that when usesDeviceConnection is true, in this
* way all logic in processMessageTasks is executed only after the connection to the device
* has successfully been established.
*/
final ThrowingConsumer<DlmsConnectionManager> taskForConnectionManager = connectionManager -> this.processMessageTasks(messageObject, messageMetadata, connectionManager, device);
this.createAndHandleConnectionForDevice(device, messageMetadata, taskForConnectionManager);
} else {
this.processMessageTasks(messageObject, messageMetadata, null, device);
}
} catch (final ThrottlingPermitDeniedException exception) {
/*
* Throttling permit for network access not granted, send the request back to the queue to be
* picked up again a little later by the message listener for device requests.
*/
this.deviceRequestMessageSender.send(messageObject, messageMetadata, this.throttlingClientConfig.permitRejectedDelay());
} catch (final DeviceKeyProcessAlreadyRunningException exception) {
this.deviceRequestMessageSender.send(messageObject, messageMetadata, this.deviceKeyProcessingTimeout);
} catch (final Exception exception) {
this.sendErrorResponse(messageMetadata, exception, messageObject);
}
}
Aggregations