예제 #1
0
 public void addEntry(AbstractGridEntry newEntry, int x, int y) {
   if (innerCacheArea.contains(x, y)) {
     service.addLoadJob(newEntry, true);
   } else {
     if (fullCacheArea.contains(x, y)) {
       service.addLoadJob(newEntry, false);
     }
   }
 }
예제 #2
0
  public void updateMonitorPosition(int x, int y) {
    innerCacheArea.setLocation(x, y);
    // Check if we are outside the fullCacheArea
    //		if (!fullCacheArea.contains(innerCacheArea)) {
    service.clearHighPriorityQueue();
    checkOnReloadPrimary();

    //	}
    int cacheDistX =
        Math.min((fullCacheArea.width >> 1), fullCacheArea.width - innerCacheArea.width - 2);
    int cacheDistY =
        Math.min((fullCacheArea.height >> 1), fullCacheArea.height - innerCacheArea.height - 2);
    int fcx = x - cacheDistX;
    int fcy = y - cacheDistY;
    if (fcx < 0) fcx = 0;
    if (fullCacheArea.width >= totalGridArea.width) fcx = 0;
    if (fcy < 0) fcy = 0;
    if (fullCacheArea.height >= totalGridArea.height) fcy = 0;
    Rectangle newFullCacheArea = new Rectangle(fcx, fcy, fullCacheArea.width, fullCacheArea.height);
    if (!fullCacheArea.contains(newFullCacheArea)) {
      service.clearLowPriorityQueue();
      // compute out of cache areas
      Rectangle[] outAreas = subtraction(newFullCacheArea, fullCacheArea);
      // purge old entries from memory
      for (int i = 0; i < outAreas.length; i++) {
        Rectangle purgeArea = outAreas[i];
        for (int ry = 0; ry < purgeArea.height; ry++) {
          for (int rx = 0; rx < purgeArea.width; rx++) {
            int xPos = rx + purgeArea.x;
            int yPos = ry + purgeArea.y;
            AbstractGridEntry entry = grid.getGridEntry(xPos, yPos);
            if (entry != null) entry.deActivate();
          }
        }
      }
      // compute new need to cache areas and load
      // entries
      for (int ry = 0; ry < newFullCacheArea.height; ry++) {
        for (int rx = 0; rx < newFullCacheArea.width; rx++) {
          int xPos = rx + newFullCacheArea.x;
          int yPos = ry + newFullCacheArea.y;
          if (!innerCacheArea.contains(xPos, yPos)) {
            AbstractGridEntry entry = grid.getGridEntry(xPos, yPos);
            if (entry != null && entry.isDeactivated()) {
              service.addLoadJob(entry, false);
            }
          }
        }
      }
    }
    fullCacheArea = newFullCacheArea;
  }
예제 #3
0
 private void checkOnReloadPrimary() {
   for (int y = innerCacheArea.y; y < innerCacheArea.y + innerCacheArea.height; y++)
     for (int x = innerCacheArea.x; x < innerCacheArea.x + innerCacheArea.width; x++) {
       AbstractGridEntry entry = grid.getGridEntry(x, y);
       if (entry != null
           && entry.isDeactivated()
           && entry.getStatus() != AbstractGridEntry.INVALIDSTATUS)
         service.addLoadJob(entry, true);
     }
 }
예제 #4
0
 public void stopLoading() {
   service.clearLowPriorityQueue();
   service.clearHighPriorityQueue();
 }
예제 #5
0
 public void dispose() {
   stopLoading();
   service.shutdown();
   execSvc.shutdownNow(); // We do not want these threads to be doing work now!
 }