use of org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager in project open-smart-grid-platform by OSGP.
the class SetAlarmNotificationsCommandExecutor method executeForAlarmFilter.
private AccessResultCode executeForAlarmFilter(final DlmsConnectionManager conn, final AttributeAddress alarmFilterAttributeAddress, final AlarmNotificationsDto alarmNotifications, final DlmsObjectType alarmRegisterDlmsObjectType) throws ProtocolAdapterException {
try {
final AlarmNotificationsDto alarmNotificationsOnDevice = this.retrieveCurrentAlarmNotifications(conn, alarmFilterAttributeAddress, alarmRegisterDlmsObjectType);
LOGGER.info("Alarm Filter on device before setting notifications: {}", alarmNotificationsOnDevice);
final Set<AlarmTypeDto> alarmTypesForRegister = this.alarmHelperService.alarmTypesForRegister(alarmRegisterDlmsObjectType);
final Set<AlarmNotificationDto> alarmNotificationsSet = alarmNotifications.getAlarmNotificationsSet().stream().filter(alarmNotificationDto -> alarmTypesForRegister.contains(alarmNotificationDto.getAlarmType())).collect(Collectors.toSet());
final long alarmFilterLongValueOnDevice = this.alarmFilterLongValue(alarmNotificationsOnDevice);
final long updatedAlarmFilterLongValue = this.calculateAlarmFilterLongValue(alarmNotificationsOnDevice, alarmNotificationsSet);
if (alarmFilterLongValueOnDevice == updatedAlarmFilterLongValue) {
return AccessResultCode.SUCCESS;
}
LOGGER.info("Modified Alarm Filter long value for device: {}", updatedAlarmFilterLongValue);
return this.writeUpdatedAlarmNotifications(conn, updatedAlarmFilterLongValue, alarmFilterAttributeAddress);
} catch (final IOException e) {
throw new ConnectionException(e);
}
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager 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.domain.factories.DlmsConnectionManager in project open-smart-grid-platform by OSGP.
the class DlmsHelperTest method assertGetWithListException.
private void assertGetWithListException(final Class<? extends Exception> jdlmsExceptionClazz, final Class<? extends Exception> exceptionClazz) throws IOException {
final DlmsConnection dlmsConnection = mock(DlmsConnection.class);
final DlmsConnectionManager connectionManager = mock(DlmsConnectionManager.class);
final DlmsDevice dlmsDevice = mock(DlmsDevice.class);
when(dlmsDevice.getDeviceIdentification()).thenReturn("666");
when(connectionManager.getConnection()).thenReturn(dlmsConnection);
final AttributeAddress[] attrAddresses = new AttributeAddress[1];
attrAddresses[0] = mock(AttributeAddress.class);
when(dlmsDevice.isWithListSupported()).thenReturn(true);
when(dlmsConnection.get(Arrays.asList(attrAddresses))).thenThrow(jdlmsExceptionClazz);
final Exception exception = assertThrows(exceptionClazz, () -> {
this.dlmsHelper.getWithList(connectionManager, dlmsDevice, attrAddresses);
});
assertThat(exception.getMessage()).contains(dlmsDevice.getDeviceIdentification());
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager 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