Example #1
0
 @Override
 public void run() {
   while (keepRunning) {
     List<Resource> resources = resourceSettings.getAllResources();
     for (Resource resource : resources) {
       long lastUpdate;
       if (lastUpdateMap.containsKey(resource.getUrl())) {
         lastUpdate = lastUpdateMap.get(resource.getUrl());
       } else {
         long currentTime = System.currentTimeMillis();
         lastUpdateMap.put(resource.getUrl(), currentTime);
         lastUpdate = 0;
       }
       if (timeToUpdate(resource, lastUpdate)) {
         GenericResourceJob job = new GenericResourceJob(resource);
         executorService.submit(job);
         setUpdateTime(resource, System.currentTimeMillis());
       }
     }
     try {
       Thread.sleep(sleepTime);
     } catch (InterruptedException e) {
       LOGGER.warning("Resource engine thread was interrupted: " + e.getMessage());
     }
   }
 }
Example #2
0
 private void setUpdateTime(final Resource resource, final long time) {
   lastUpdateMap.put(resource.getUrl(), time);
 }
Example #3
0
 private boolean timeToUpdate(final Resource resource, long lastUpdate) {
   long currentTime = System.currentTimeMillis();
   long updateInterval = resource.getTimer();
   return currentTime > lastUpdate + updateInterval;
 }