public static void localWatchDog() {
    Logger.info("  --local watchdog");

    Long nImages = checkNumberOfNewLocalImages();

    if (nImages > 0) { // there are new images to take care of
      Logger.info("    number of new images: " + nImages);

      List<String> images = null;

      // get the list of local images
      try {
        images = readLocalFolder();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      // TODO check if the image is already in db, double images problem!!!
      // for each new image
      for (int i = images.size() - 1; i > images.size() - 1 - nImages; i--) {
        Logger.info("    image name: " + images.get(i));
        // add new images to db
        Date date = new Date();
        String dateS = "" + date.getTime() / 1000;
        MImages newDbImage =
            new MImages(
                images.get(i),
                urlPath + images.get(i),
                "local",
                "Usi Display",
                "http://pdnet.inf.unisi.ch/devel/public/logo-usi-67540.gif",
                dateS,
                (long) 0,
                (long) 0);
        MImages.addNew(newDbImage);

        // send the new image to clients
        sendImageToClients(newDbImage);
      }

      // update the tag count
      LocalInfo.delete((long) 1);
      Logger.info("		update the local info +");
      LocalInfo.addNew(new LocalInfo(urlPath, getNumberOfLocalImages()));

    } else if (nImages < 0) {
      // TODO
      // some images have been deleted
      // for now keep them in the db, later consider deleting them

      // update the tag
      LocalInfo.delete((long) 1);
      Logger.info("		update the local info -");
      LocalInfo.addNew(new LocalInfo(urlPath, getNumberOfLocalImages()));
    }

    Logger.info("  --local watchdog---");
  } // checkLocalFolder
  public static void addLocalImagesToDb() {
    Logger.info("  --Add local images to db-------------");

    List<String> images = null;

    // get the list of local images
    try {
      images = readLocalFolder();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    if (images != null) {
      for (int i = 0; i < images.size(); i++) {
        Logger.info("    image name: " + images.get(i));
        // add local image to db
        // MImages.addNew(new MImages(image.getId(),
        // image.getImages().getLowResolution().getImageUrl(), "instagram",
        // caption.getFrom().getFullName(), caption.getFrom().getProfilePicture(),
        // image.getCreatedTime(), (long)image.getLikes().getCount(), (long)0));
        Date date = new Date();
        String dateS = "" + date.getTime() / 1000;
        MImages.addNew(
            new MImages(
                images.get(i),
                urlPath + images.get(i),
                "local",
                "Usi Display",
                "http://pdnet.inf.unisi.ch/devel/public/logo-usi-67540.gif",
                dateS,
                (long) 0,
                (long) 0));
      } // for
    } // if

    Logger.info("  ------------------------------------");
  } // addLocalImagesToDb
  public static void updateLikesInDbLocal(String imageId, String displayId) {
    Logger.info("  --update local likes in db for image: " + imageId);
    List<MImages> images = new ArrayList<MImages>();
    images = MImages.all();

    // find the right image based on imageId
    for (int i = 0; i < images.size(); i++) {
      MImages image = images.get(i);
      if (image.idInstagram.equals(imageId)) {
        Logger.info(
            "    i= " + i + " imageId: " + image.idInstagram + " author: " + image.authorName);
        // update likes in db (local likes +1)
        // TODO find a way to update the filed, not to delete and add the same image
        image.updateNumberOfLikesLocal();
        MImages.delete(image.id);
        MImages.addNew(
            new MImages(
                image.idInstagram,
                image.url,
                "instagram",
                image.authorName,
                image.authorPic,
                image.timeCreated,
                image.numberOfLikesIns,
                image.numberOfLikesLocall));
      } // if
    } // for

    // send the like update to all clients except the source
    sendLikeUpdateToClients(imageId, displayId);

    // update the hot images
    updateHotImages();

    Logger.info("-----------------------------");
  } // updateLikesInDbLocal
  // ----------------------------------------------------------------
  // ---- Image Database---------------------------------------------
  public static void addImagesToDB(Instagram instagram) {
    Logger.info("  --Add images to db-------------");

    TagMediaFeed mediaFeed = getMediaFeed(instagram);

    List<MediaFeedData> images = mediaFeed.getData();
    List<MediaFeedData> imagesAll = new ArrayList<MediaFeedData>();

    // add first media feeds to imagesAll
    for (int i = 0; i < images.size(); i++) {
      if (imagesAll.size() < maxNumberOfImagesInst) {
        imagesAll.add(0, images.get(i));
      }
    }

    // add additional media feed to imagesAll[maxNumberOfImagesInst]
    String nextMaxId = getPagination(mediaFeed);
    while ((imagesAll.size() < maxNumberOfImagesInst) && (nextMaxId != null)) {
      // get new set of images
      TagMediaFeed nextMediaFeed = getNextMediaFeed(instagram, nextMaxId);
      List<MediaFeedData> imagesNext = nextMediaFeed.getData();

      // add  imagesNext to imagesAll
      for (int i = 0; i < imagesNext.size(); i++) {
        if (imagesAll.size() < maxNumberOfImagesInst) {
          imagesAll.add(0, imagesNext.get(i));
        }
      }

      nextMaxId = getPagination(nextMediaFeed);

      // Logger.info("imagesNext: "+imagesNext.size());
      Logger.info("imagesAll: " + imagesAll.size());
    } // while

    // print all images and add them to the db
    Logger.info("imagesAll: " + imagesAll.size());
    if (imagesAll != null) {
      int counter = 1;
      for (MediaFeedData image : imagesAll) {
        if (image != null) {
          Date d = new Date(Long.parseLong(image.getCreatedTime()) * 1000);
          Caption caption = image.getCaption();
          Logger.info(
              "   " + (counter++) + "." + " id:" + image.getId() + " time: " + d.toString() + " ");

          if (caption != null) {
            Logger.info("       from, full name: " + caption.getFrom().getFullName());
            // add image to db
            MImages.addNew(
                new MImages(
                    image.getId(),
                    image.getImages().getLowResolution().getImageUrl(),
                    "instagram",
                    caption.getFrom().getFullName(),
                    caption.getFrom().getProfilePicture(),
                    image.getCreatedTime(),
                    (long) image.getLikes().getCount(),
                    (long) 0));
          } // if
        } // if
      } // for
    } // if
  } // addImagesToDB
  public static void tagWatchDog(Instagram instagram) {
    Logger.info("  --tag watchdog");

    Long nImages = checkNumberOfNewImages(instagram, appDisplayNameTag);

    if (nImages > 0) { // there are new images to take care of
      Logger.info("    number of new images: " + nImages);

      // get the first page of media feeds (images)
      TagMediaFeed mediaFeed = getMediaFeed(instagram);
      List<MediaFeedData> images = mediaFeed.getData();

      // TODO: support adding new images from other pages
      // limit number of new images to the first page
      if (nImages > images.size()) { // number of new images excides the first page
        nImages = (long) images.size();
        Logger.info("    number of limited images: " + nImages);
      }

      // TODO check if the image is already in db, double images problem!!!
      // for each new image from the first page
      for (int i = (int) (nImages - 1); i >= 0; i--) {
        // add new images to db
        MediaFeedData image = images.get(i);
        Caption caption = image.getCaption();
        MImages newDbImage =
            new MImages(
                image.getId(),
                image.getImages().getLowResolution().getImageUrl(),
                "instagram",
                caption.getFrom().getFullName(),
                caption.getFrom().getProfilePicture(),
                image.getCreatedTime(),
                (long) image.getLikes().getCount(),
                (long) 0);
        MImages.addNew(newDbImage);
        Logger.info(
            "    add image to db: index: "
                + i
                + " id: "
                + image.getId()
                + " from: "
                + caption.getFrom().getFullName());

        // send the new image to clients
        sendImageToClients(newDbImage);
      }

      // update the tag count
      TagInfo.delete((long) 1);
      Logger.info("		update the tag +");
      TagInfo.addNew(
          new TagInfo(appDisplayNameTag, getNumberOfImagesByTag(instagram, appDisplayNameTag)));
      displayTagInfo();

    } else if (nImages < 0) {
      // TODO
      // some images have been deleted
      // for now keep them in the db, later consider deleting them

      // update the tag
      TagInfo.delete((long) 1);
      Logger.info("		update the tag -");
      TagInfo.addNew(
          new TagInfo(appDisplayNameTag, getNumberOfImagesByTag(instagram, appDisplayNameTag)));
      displayTagInfo();
    }

    Logger.info("  --tag watchdog---");
  } // tagWatchDog()