private void sendManageRequest() throws MqttException {
   if (dmClient.manage(0)) {
     System.out.println("Device connected as Managed device now!");
   } else {
     System.err.println("Managed request failed!");
   }
 }
  /**
   * This method publishes a sample device event for every 5 seconds for 1000 times.
   *
   * <p>This sample shows that one can publish events while carrying out the device management
   * operations.
   */
  private void publishDeviceEvents() {

    Random random = new Random();
    // Lets publish an event for every 5 seconds for 1000 times
    for (int i = 0; i < 1000; i++) {
      // Generate a JSON object of the event to be published
      JsonObject event = new JsonObject();
      event.addProperty("name", "foo");
      event.addProperty("cpu", random.nextInt(100));
      event.addProperty("mem", random.nextInt(100));

      System.out.println("Publishing device event:: " + event);
      // Registered flow allows 0, 1 and 2 QoS
      dmClient.publishEvent("status", event);

      try {
        Thread.sleep(5000 * 2);
      } catch (InterruptedException ie) {

      }
    }
  }
 private void disConnect() throws Exception {
   dmClient.disconnect();
 }
 /** This method connects the device to the IoT Foundation as normal device */
 private void connect() throws Exception {
   dmClient.connect();
 }