Search in sources :

Example 1 with ThrowingConsumer

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);
    }
}
Also used : FirmwareFileDto(org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) DlmsConnectionManager(org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) Logger(org.slf4j.Logger) OsgpResponseMessageProcessor(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.responses.from.core.OsgpResponseMessageProcessor) UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) LoggerFactory(org.slf4j.LoggerFactory) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Autowired(org.springframework.beans.factory.annotation.Autowired) ObjectMessage(javax.jms.ObjectMessage) MessageType(org.opensmartgridplatform.shared.infra.jms.MessageType) JMSException(javax.jms.JMSException) Serializable(java.io.Serializable) Component(org.springframework.stereotype.Component) FirmwareService(org.opensmartgridplatform.adapter.protocol.dlms.application.services.FirmwareService) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) ThrowingConsumer(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ThrowingConsumer) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) SilentException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.SilentException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Serializable(java.io.Serializable) DlmsConnectionManager(org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager)

Example 2 with ThrowingConsumer

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);
    }
}
Also used : DomainHelperService(org.opensmartgridplatform.adapter.protocol.dlms.application.services.DomainHelperService) MessageProcessorMap(org.opensmartgridplatform.shared.infra.jms.MessageProcessorMap) MessageProcessor(org.opensmartgridplatform.shared.infra.jms.MessageProcessor) DlmsConnectionManager(org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager) Logger(org.slf4j.Logger) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) LoggerFactory(org.slf4j.LoggerFactory) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Autowired(org.springframework.beans.factory.annotation.Autowired) ObjectMessage(javax.jms.ObjectMessage) MessageType(org.opensmartgridplatform.shared.infra.jms.MessageType) JMSException(javax.jms.JMSException) Serializable(java.io.Serializable) PostConstruct(javax.annotation.PostConstruct) DeviceResponseMessageSender(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DeviceResponseMessageSender) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ThrowingConsumer(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ThrowingConsumer) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) DlmsConnectionMessageProcessor(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DlmsConnectionMessageProcessor) Message(javax.jms.Message) SilentException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.SilentException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Serializable(java.io.Serializable) DlmsConnectionManager(org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager)

Example 3 with ThrowingConsumer

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);
    }
}
Also used : MessageProcessor(org.opensmartgridplatform.shared.infra.jms.MessageProcessor) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) DeviceKeyProcessAlreadyRunningException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.DeviceKeyProcessAlreadyRunningException) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Autowired(org.springframework.beans.factory.annotation.Autowired) ObjectMessage(javax.jms.ObjectMessage) FunctionalExceptionType(org.opensmartgridplatform.shared.exceptionhandling.FunctionalExceptionType) MessageType(org.opensmartgridplatform.shared.infra.jms.MessageType) ThrottlingPermitDeniedException(org.opensmartgridplatform.throttling.ThrottlingPermitDeniedException) Value(org.springframework.beans.factory.annotation.Value) Duration(java.time.Duration) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ThrowingConsumer(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ThrowingConsumer) ComponentType(org.opensmartgridplatform.shared.exceptionhandling.ComponentType) DomainHelperService(org.opensmartgridplatform.adapter.protocol.dlms.application.services.DomainHelperService) MessageProcessorMap(org.opensmartgridplatform.shared.infra.jms.MessageProcessorMap) DlmsConnectionManager(org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) Instant(java.time.Instant) JMSException(javax.jms.JMSException) Serializable(java.io.Serializable) Slf4j(lombok.extern.slf4j.Slf4j) PostConstruct(javax.annotation.PostConstruct) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) SilentException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.SilentException) DeviceKeyProcessAlreadyRunningException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.DeviceKeyProcessAlreadyRunningException) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Serializable(java.io.Serializable) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) DlmsConnectionManager(org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager) ThrottlingPermitDeniedException(org.opensmartgridplatform.throttling.ThrottlingPermitDeniedException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) DeviceKeyProcessAlreadyRunningException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.DeviceKeyProcessAlreadyRunningException) ThrottlingPermitDeniedException(org.opensmartgridplatform.throttling.ThrottlingPermitDeniedException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException) SilentException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.SilentException)

Aggregations

Serializable (java.io.Serializable)3 JMSException (javax.jms.JMSException)3 ObjectMessage (javax.jms.ObjectMessage)3 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)3 DlmsConnectionManager (org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager)3 SilentException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.SilentException)3 ThrowingConsumer (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ThrowingConsumer)3 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)3 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)3 MessageType (org.opensmartgridplatform.shared.infra.jms.MessageType)3 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 PostConstruct (javax.annotation.PostConstruct)2 DomainHelperService (org.opensmartgridplatform.adapter.protocol.dlms.application.services.DomainHelperService)2 MessageProcessor (org.opensmartgridplatform.shared.infra.jms.MessageProcessor)2 MessageProcessorMap (org.opensmartgridplatform.shared.infra.jms.MessageProcessorMap)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Qualifier (org.springframework.beans.factory.annotation.Qualifier)2 Duration (java.time.Duration)1