Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Commit

Permalink
An Interface method should not allow for throwing a generic Exception (
Browse files Browse the repository at this point in the history
…#3467)

* An Interface method should not allow for throwing a generic Exception
* Loglevel reduced to trace with exception
* Removed placeholder for exception from log message

Fixes #2396
Signed-off-by: Stefan Triller <stefan.triller@telekom.de>
  • Loading branch information
triller-telekom authored and Simon Kaufmann committed May 22, 2017
1 parent c1270f0 commit 38b3e20
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/
package org.eclipse.smarthome.io.transport.mqtt;

import java.io.IOException;

/**
* Callback interface for sending a message to the MqttBrokerConnection.
*
Expand All @@ -19,8 +21,8 @@ public interface MqttSenderChannel {
*
* @param topic Topic to publish the message to.
* @param message message payload.
* @throws Exception if an error occurs during sending.
* @throws IOException if an error occurs during sending.
*/
public void publish(String topic, byte[] message) throws Exception;
public void publish(String topic, byte[] message) throws IOException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
package org.eclipse.smarthome.io.transport.mqtt.internal;

import java.io.IOException;
import java.security.cert.X509Certificate;
import java.util.List;
import java.util.Properties;
Expand Down Expand Up @@ -443,7 +444,7 @@ private void startProducer(MqttMessageProducer publisher) {
publisher.setSenderChannel(new MqttSenderChannel() {

@Override
public void publish(String topic, byte[] payload) throws Exception {
public void publish(String topic, byte[] payload) throws IOException {

if (!started) {
logger.warn("Broker connection not started. Cannot publish message to topic '{}'", topic);
Expand All @@ -457,19 +458,22 @@ public void publish(String topic, byte[] payload) throws Exception {

// publish message asynchronously
MqttTopic mqttTopic = client.getTopic(topic);
MqttDeliveryToken deliveryToken = mqttTopic.publish(message);

logger.debug("Publishing message {} to topic '{}'", deliveryToken.getMessageId(), topic);
if (!async) {
// wait for publish confirmation
deliveryToken.waitForCompletion(10000);
if (!deliveryToken.isComplete()) {
logger.error(
"Did not receive completion message within timeout limit whilst publishing to topic '{}'",
topic);
MqttDeliveryToken deliveryToken;
try {
deliveryToken = mqttTopic.publish(message);
logger.debug("Publishing message {} to topic '{}'", deliveryToken.getMessageId(), topic);
if (!async) {
// wait for publish confirmation
deliveryToken.waitForCompletion(10000);
if (!deliveryToken.isComplete()) {
logger.error(
"Did not receive completion message within timeout limit whilst publishing to topic '{}'",
topic);
}
}
} catch (MqttException e) {
logger.error("Could not publish message to topic {}", topic, e);
}

}
});

Expand Down

0 comments on commit 38b3e20

Please sign in to comment.