use of org.opensmartgridplatform.adapter.protocol.iec61850.device.da.rtu.DaDeviceResponse in project Protocol-Adapter-IEC61850 by OSGP.
the class DaRtuDeviceRequestMessageProcessor method handleDeviceResponse.
/**
* Override to include the data in the response
*/
@Override
public void handleDeviceResponse(final DeviceResponse deviceResponse, final ResponseMessageSender responseMessageSender, final String domain, final String domainVersion, final String messageType, final int retryCount, final int messagePriority, final Long scheduleTime) {
ResponseMessageResultType result = ResponseMessageResultType.OK;
OsgpException ex = null;
Serializable dataObject = null;
try {
final DaDeviceResponse response = (DaDeviceResponse) deviceResponse;
this.deviceResponseService.handleDeviceMessageStatus(response.getStatus());
dataObject = response.getDataResponse();
} catch (final OsgpException e) {
LOGGER.error("Device Response Exception", e);
result = ResponseMessageResultType.NOT_OK;
ex = e;
}
final DeviceMessageMetadata deviceMessageMetadata = new DeviceMessageMetadata(deviceResponse.getDeviceIdentification(), deviceResponse.getOrganisationIdentification(), deviceResponse.getCorrelationUid(), messageType, messagePriority, scheduleTime);
final ProtocolResponseMessage protocolResponseMessage = new ProtocolResponseMessage.Builder().domain(domain).domainVersion(domainVersion).deviceMessageMetadata(deviceMessageMetadata).result(result).osgpException(ex).dataObject(dataObject).retryCount(retryCount).build();
responseMessageSender.send(protocolResponseMessage);
}
use of org.opensmartgridplatform.adapter.protocol.iec61850.device.da.rtu.DaDeviceResponse in project Protocol-Adapter-IEC61850 by OSGP.
the class Iec61850DaRtuDeviceService method getData.
@Override
public void getData(final DaDeviceRequest deviceRequest, final DeviceResponseHandler deviceResponseHandler, final DaRtuDeviceRequestMessageProcessor messageProcessor) throws JMSException {
try {
final String serverName = this.getServerName(deviceRequest);
final ServerModel serverModel = this.connectAndRetrieveServerModel(deviceRequest, serverName);
final ClientAssociation clientAssociation = this.iec61850DeviceConnectionService.getClientAssociation(deviceRequest.getDeviceIdentification());
final Serializable dataResponse = this.handleGetData(new DeviceConnection(new Iec61850Connection(new Iec61850ClientAssociation(clientAssociation, null), serverModel), deviceRequest.getDeviceIdentification(), deviceRequest.getOrganisationIdentification(), serverName), deviceRequest, messageProcessor);
final DaDeviceResponse deviceResponse = new DaDeviceResponse(deviceRequest.getOrganisationIdentification(), deviceRequest.getDeviceIdentification(), deviceRequest.getCorrelationUid(), DeviceMessageStatus.OK, dataResponse);
deviceResponseHandler.handleResponse(deviceResponse);
} catch (final ConnectionFailureException se) {
LOGGER.error("Could not connect to device after all retries", se);
final EmptyDeviceResponse deviceResponse = new EmptyDeviceResponse(deviceRequest.getOrganisationIdentification(), deviceRequest.getDeviceIdentification(), deviceRequest.getCorrelationUid(), DeviceMessageStatus.FAILURE);
deviceResponseHandler.handleConnectionFailure(se, deviceResponse);
} catch (final Exception e) {
LOGGER.error("Unexpected exception during Get Data", e);
final EmptyDeviceResponse deviceResponse = new EmptyDeviceResponse(deviceRequest.getOrganisationIdentification(), deviceRequest.getDeviceIdentification(), deviceRequest.getCorrelationUid(), DeviceMessageStatus.FAILURE);
deviceResponseHandler.handleException(e, deviceResponse);
}
}
use of org.opensmartgridplatform.adapter.protocol.iec61850.device.da.rtu.DaDeviceResponse in project open-smart-grid-platform by OSGP.
the class Iec61850DaRtuDeviceService method getData.
@Override
public void getData(final DaDeviceRequest deviceRequest, final DeviceResponseHandler deviceResponseHandler, final DaRtuDeviceRequestMessageProcessor messageProcessor) throws JMSException {
try {
final String serverName = this.getServerName(deviceRequest);
final ServerModel serverModel = this.connectAndRetrieveServerModel(deviceRequest, serverName);
final ClientAssociation clientAssociation = this.iec61850DeviceConnectionService.getClientAssociation(deviceRequest.getDeviceIdentification());
final Serializable dataResponse = this.handleGetData(new DeviceConnection(new Iec61850Connection(new Iec61850ClientAssociation(clientAssociation, null), serverModel), deviceRequest.getDeviceIdentification(), deviceRequest.getOrganisationIdentification(), serverName), deviceRequest, messageProcessor);
final DaDeviceResponse deviceResponse = new DaDeviceResponse(deviceRequest, DeviceMessageStatus.OK, dataResponse);
deviceResponseHandler.handleResponse(deviceResponse);
} catch (final ConnectionFailureException se) {
LOGGER.error("Could not connect to device after all retries", se);
final EmptyDeviceResponse deviceResponse = new EmptyDeviceResponse(deviceRequest, DeviceMessageStatus.FAILURE);
deviceResponseHandler.handleConnectionFailure(se, deviceResponse);
} catch (final Exception e) {
LOGGER.error("Unexpected exception during Get Data", e);
final EmptyDeviceResponse deviceResponse = new EmptyDeviceResponse(deviceRequest, DeviceMessageStatus.FAILURE);
deviceResponseHandler.handleException(e, deviceResponse);
}
}
use of org.opensmartgridplatform.adapter.protocol.iec61850.device.da.rtu.DaDeviceResponse in project open-smart-grid-platform by OSGP.
the class DaRtuDeviceRequestMessageProcessor method handleDeviceResponse.
/**
* Override to include the data in the response
*/
@Override
public void handleDeviceResponse(final DeviceResponse deviceResponse, final ResponseMessageSender responseMessageSender, final DomainInformation domainInformation, final String messageType, final int retryCount, final boolean isScheduled) {
ResponseMessageResultType result = ResponseMessageResultType.OK;
OsgpException ex = null;
Serializable dataObject = null;
try {
final DaDeviceResponse response = (DaDeviceResponse) deviceResponse;
this.deviceResponseService.handleDeviceMessageStatus(response.getStatus());
dataObject = response.getDataResponse();
} catch (final OsgpException e) {
LOGGER.error("Device Response Exception", e);
result = ResponseMessageResultType.NOT_OK;
ex = e;
}
final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withDeviceIdentification(deviceResponse.getDeviceIdentification()).withOrganisationIdentification(deviceResponse.getOrganisationIdentification()).withCorrelationUid(deviceResponse.getCorrelationUid()).withMessageType(messageType).withDomain(domainInformation.getDomain()).withDomainVersion(domainInformation.getDomainVersion()).withScheduled(isScheduled).withRetryCount(retryCount).build();
final ProtocolResponseMessage protocolResponseMessage = ProtocolResponseMessage.newBuilder().messageMetadata(messageMetadata).result(result).osgpException(ex).dataObject(dataObject).build();
responseMessageSender.send(protocolResponseMessage);
}
Aggregations