/**
   * Checks the response validity.
   *
   * @param response
   */
  private static void checkResponse(RemoteCommand.Response response) {

    if (RemoteCommand.Response.ReturnCode.RC_ERROR.equals(response.getReturnCode())) {
      Logger.error(TAG, "#onPostExecute - response : " + response);
    } else {
      Logger.info(TAG, "#onPostExecute - response : " + response);
    }

    Assert.assertEquals(
        "Request failed : " + response.getMessage(),
        RemoteCommand.Response.ReturnCode.RC_SUCCESS,
        response.getReturnCode());
  }
  /**
   * Initializes the async task manager then send a request with it.
   *
   * @param request The request to send.
   */
  public void sendRequest(RemoteCommand.Request request) {

    if (AsyncMessageMgr.availablePermits() > 0) {
      AsyncMessageMgr task = new AsyncMessageMgr(mDevice, null);
      task.execute(request);
      Logger.info(TAG, "#sendRequest - Command sent.");

      try {
        checkResponse(task.get());
      } catch (InterruptedException e) {
        Assert.fail("#sendRequest - InterruptedException : " + e.getMessage());
      } catch (ExecutionException e) {
        Assert.fail("#sendRequest - ExecutionException : " + e.getMessage());
      }

    } else {
      Assert.fail("#sendRequest - No more permit available!");
    }
  }