예제 #1
0
 @Override
 public Collection<Integer> getCurrentIds() throws Exception {
   List<Integer> ids = new ArrayList<>();
   if (fileFactory != null) {
     for (String fileName : fileFactory.listFiles("page")) {
       ids.add(getPageIdFromFileName(fileName));
     }
   }
   return ids;
 }
예제 #2
0
  @Override
  public void start() throws Exception {
    lock.writeLock().lock();

    try {

      if (running) {
        // don't throw an exception.
        // You could have two threads adding PagingStore to a
        // ConcurrentHashMap,
        // and having both threads calling init. One of the calls should just
        // need to be ignored
        return;
      } else {
        running = true;
        firstPageId = Integer.MAX_VALUE;

        // There are no files yet on this Storage. We will just return it empty
        if (fileFactory != null) {

          currentPageId = 0;
          if (currentPage != null) {
            currentPage.close();
          }
          currentPage = null;

          List<String> files = fileFactory.listFiles("page");

          numberOfPages = files.size();

          for (String fileName : files) {
            final int fileId = PagingStoreImpl.getPageIdFromFileName(fileName);

            if (fileId > currentPageId) {
              currentPageId = fileId;
            }

            if (fileId < firstPageId) {
              firstPageId = fileId;
            }
          }

          if (currentPageId != 0) {
            currentPage = createPage(currentPageId);
            currentPage.open();

            List<PagedMessage> messages = currentPage.read(storageManager);

            LivePageCache pageCache = new LivePageCacheImpl(currentPage);

            for (PagedMessage msg : messages) {
              pageCache.addLiveMessage(msg);
              if (msg.getMessage().isLargeMessage()) {
                // We have to do this since addLIveMessage will increment an extra one
                ((LargeServerMessage) msg.getMessage()).decrementDelayDeletionCount();
              }
            }

            currentPage.setLiveCache(pageCache);

            currentPageSize.set(currentPage.getSize());

            cursorProvider.addPageCache(pageCache);
          }

          // We will not mark it for paging if there's only a single empty file
          if (currentPage != null && !(numberOfPages == 1 && currentPage.getSize() == 0)) {
            startPaging();
          }
        }
      }

    } finally {
      lock.writeLock().unlock();
    }
  }