class DeviceResponseMessageSender implements ResponseMessageSender {

    @Override
    public void send(final ResponseMessage responseMessage) {
        if (!(responseMessage instanceof ProtocolResponseMessage)) {
            LOGGER.error(LOG_MESSAGE_RESPONSE_MESSAGE_OF_WRONG_TYPE, responseMessage.getClass().getName());
            return;
        }

        final ProtocolResponseMessage msg = (ProtocolResponseMessage) responseMessage;

        if (!ProtocolResponseMessageValidator.isValid(msg, LOGGER)) {
            return;
        }

        try {
            this.sendMessage(msg);
        } catch (final IllegalStateException | UncategorizedJmsException e) {
            /*
             * IllegalStateException occurs when activemq connection pool is
             * exhausted or activemq failover timeout is reached
             * UncategorizedJmsException might also occur when activemq failover
             * timeout is reached
             */
            if (this.isCloseConnectionsOnBrokerFailure) {
                LOGGER.error(LOG_MESSAGE_JMS_EXCEPTION, e);
                this.iec60870DeviceConnectionService.closeAllConnections();
            }
            throw e;
        }
    }

}