private Future<Void> processCommand(final Command command) {
LOG.info("Command sent to device... [request will timeout in {} seconds]", requestTimeoutInSecs);
final Future<CommandClient> commandClient = client.getOrCreateCommandClient(tenantId, deviceId);
return commandClient
.map(this::setRequestTimeOut)
.compose(c -> {
if (command.isOneWay()) {
return c
.sendOneWayCommand(command.getName(), command.getContentType(), Buffer.buffer(command.getPayload()), null)
.map(ok -> c);
} else {
return c
.sendCommand(command.getName(), command.getContentType(), Buffer.buffer(command.getPayload()), null)
.map(this::printResponse)
.map(ok -> c);
}
})
.map(this::closeCommandClient)
.otherwise(error -> {
LOG.error("Error sending command: {}", error.getMessage());
if (commandClient.succeeded()) {
return closeCommandClient(commandClient.result());
} else {
return null;
}
});
}