use of org.eclipse.kura.KuraTimeoutException in project kura by eclipse.
the class MqttDataTransport method unsubscribe.
@Override
public void unsubscribe(String topic) throws KuraTimeoutException, KuraException, KuraNotConnectedException {
if (this.m_mqttClient == null || !this.m_mqttClient.isConnected()) {
throw new KuraNotConnectedException("Not connected");
}
topic = replaceTopicVariables(topic);
s_logger.info("Unsubscribing to topic: {}", topic);
try {
IMqttToken token = this.m_mqttClient.unsubscribe(topic);
token.waitForCompletion(getTimeToWaitMillis());
} catch (MqttException e) {
if (e.getReasonCode() == MqttException.REASON_CODE_CLIENT_TIMEOUT) {
s_logger.warn("Timeout unsubscribing to topic: {}", topic);
throw new KuraTimeoutException("Timeout unsubscribing to topic: " + topic, e);
} else {
s_logger.error("Cannot unsubscribe to topic: " + topic, e);
throw KuraException.internalError(e, "Cannot unsubscribe to topic: " + topic);
}
}
}
use of org.eclipse.kura.KuraTimeoutException in project kura by eclipse.
the class CloudCallServiceImpl method call.
@Override
public synchronized KuraResponsePayload call(String deviceId, String appId, String appTopic, KuraPayload appPayload, int timeout) throws KuraConnectException, KuraTimeoutException, KuraStoreException, KuraException {
// Generate the request ID
String requestId = s_generator.next();
StringBuilder sbReqTopic = new StringBuilder("$EDC").append("/").append(ACCOUNT_NAME_VAR_NAME).append("/").append(deviceId).append("/").append(appId).append("/").append(appTopic);
StringBuilder sbRespTopic = new StringBuilder("$EDC").append("/").append(ACCOUNT_NAME_VAR_NAME).append("/").append(CLIENT_ID_VAR_NAME).append("/").append(appId).append("/").append("REPLY").append("/").append(requestId);
KuraRequestPayload req = null;
if (appPayload != null) {
// Construct a request payload
req = new KuraRequestPayload(appPayload);
} else {
req = new KuraRequestPayload();
}
req.setRequestId(requestId);
req.setRequesterClientId(CLIENT_ID_VAR_NAME);
CloudPayloadProtoBufEncoderImpl encoder = new CloudPayloadProtoBufEncoderImpl(req);
byte[] rawPayload;
try {
rawPayload = encoder.getBytes();
} catch (IOException e) {
throw new KuraException(KuraErrorCode.INTERNAL_ERROR, e, "Cannot encode request");
}
this.m_respTopic = sbRespTopic.toString();
this.m_resp = null;
this.m_dataService.subscribe(this.m_respTopic, 0);
synchronized (this.m_lock) {
try {
this.m_dataService.publish(sbReqTopic.toString(), rawPayload, DFLT_PUB_QOS, DFLT_RETAIN, DFLT_PRIORITY);
this.m_lock.wait(timeout);
} catch (KuraStoreException e) {
throw e;
} catch (InterruptedException e) {
// Avoid re-throwing this exception which should not normally happen
s_logger.warn("Interrupted while waiting for the response");
Thread.interrupted();
} finally {
try {
this.m_dataService.unsubscribe(this.m_respTopic);
} catch (KuraException e) {
s_logger.error("Cannot unsubscribe");
}
this.m_respTopic = null;
}
}
if (this.m_resp == null) {
throw new KuraTimeoutException("Timed out while waiting for the response");
}
return this.m_resp;
}
use of org.eclipse.kura.KuraTimeoutException in project kura by eclipse.
the class MqttDataTransport method subscribe.
// ---------------------------------------------------------
//
// Subscription Management Methods
//
// ---------------------------------------------------------
@Override
public void subscribe(String topic, int qos) throws KuraTimeoutException, KuraException, KuraNotConnectedException {
if (this.m_mqttClient == null || !this.m_mqttClient.isConnected()) {
throw new KuraNotConnectedException("Not connected");
}
topic = replaceTopicVariables(topic);
s_logger.info("Subscribing to topic: {} with QoS: {}", topic, qos);
try {
IMqttToken token = this.m_mqttClient.subscribe(topic, qos);
token.waitForCompletion(getTimeToWaitMillis());
} catch (MqttException e) {
if (e.getReasonCode() == MqttException.REASON_CODE_CLIENT_TIMEOUT) {
s_logger.warn("Timeout subscribing to topic: {}", topic);
throw new KuraTimeoutException("Timeout subscribing to topic: " + topic, e);
} else {
s_logger.error("Cannot subscribe to topic: " + topic, e);
throw KuraException.internalError(e, "Cannot subscribe to topic: " + topic);
}
}
}
Aggregations