Examples of PageCache


Examples of org.hornetq.core.paging.cursor.PageCache

   /**
    * No need to synchronize this method since the private getPageCache will have a synchronized call
    */
   public PageCache getPageCache(PagePosition pos)
   {
      PageCache cache = pos.getPageCache();
      if (cache == null)
      {
         cache = getPageCache(pos.getPageNr());
         pos.setPageCache(cache);
      }
View Full Code Here

Examples of org.hornetq.core.paging.cursor.PageCache

   private PageCache getPageCache(final long pageId)
   {
      try
      {
         boolean needToRead = false;
         PageCache cache = null;
         synchronized (softCache)
         {
            if (pageId > pagingStore.getCurrentWritingPage())
            {
               return null;
            }

            cache = softCache.get(pageId);
            if (cache == null)
            {
               cache = createPageCache(pageId);
               needToRead = true;
               // anyone reading from this cache will have to wait reading to finish first
               // we also want only one thread reading this cache
               cache.lock();
               softCache.put(pageId, cache);
            }
         }

         // Reading is done outside of the synchronized block, however
         // the page stays locked until the entire reading is finished
         if (needToRead)
         {
            Page page = null;
            try
            {
               page = pagingStore.createPage((int)pageId);

               page.open();

               List<PagedMessage> pgdMessages = page.read();

               for (PagedMessage pdgMessage : pgdMessages)
               {
                  pdgMessage.initMessage(storageManager);
               }

               cache.setMessages(pgdMessages.toArray(new PagedMessage[pgdMessages.size()]));

            }
            finally
            {
               try
               {
                  if (page != null)
                  {
                     page.close();
                  }
               }
               catch (Throwable ignored)
               {
               }
               cache.unlock();
            }
         }

         return cache;
      }
View Full Code Here

Examples of org.hornetq.core.paging.cursor.PageCache

                                                                         server.getExecutorFactory().getExecutor(),
                                                                         5);

      for (int i = 0; i < numberOfPages; i++)
      {
         PageCache cache = cursorProvider.getPageCache(new PagePositionImpl(i + 1, 0));
         System.out.println("Page " + i + " had " + cache.getNumberOfMessages() + " messages");

      }

      forceGC();
View Full Code Here

Examples of org.hornetq.core.paging.cursor.PageCache

      System.out.println("NumberOfPages = " + numberOfPages);

      PageCursorProvider cursorProvider = lookupCursorProvider();

      PageCache cache = cursorProvider.getPageCache(new PagePositionImpl(2, 0));

      assertNull(cache);
   }
View Full Code Here

Examples of org.hornetq.core.paging.cursor.PageCache

      PageSubscription cursor = this.server.getPagingManager()
                                           .getPageStore(ADDRESS)
                                           .getCursorProvier()
                                           .getSubscription(queue.getID());

      PageCache firstPage = cursorProvider.getPageCache(new PagePositionImpl(server.getPagingManager()
                                                                                   .getPageStore(ADDRESS)
                                                                                   .getFirstPage(), 0));

      int firstPageSize = firstPage.getNumberOfMessages();

      firstPage = null;

      System.out.println("Cursor: " + cursor);
      cursorProvider.printDebug();
View Full Code Here

Examples of org.hornetq.core.paging.cursor.PageCache

      System.out.println("NumberOfPages = " + numberOfPages);

      PageCursorProvider cursorProvider = lookupCursorProvider();

      PageCache cache = cursorProvider.getPageCache(new PagePositionImpl(5, 0));

      PageSubscription cursor = cursorProvider.getSubscription(queue.getID());
      PagePosition startingPos = new PagePositionImpl(5, cache.getNumberOfMessages() / 2);
      cursor.bookmark(startingPos);

      // We can't proceed until the operation has finished
      server.getStorageManager().waitOnOperations();
     
      PagedMessage msg = cache.getMessage(startingPos.getMessageNr() + 1);
      msg.initMessage(server.getStorageManager());
      int initialKey = msg.getMessage().getIntProperty("key").intValue();
      int key = initialKey;

      msg = null;
View Full Code Here

Examples of org.hornetq.core.paging.cursor.PageCache

      {
         if (wasLive)
         {
            // if the page was live at any point, we need to
            // get the number of messages from the page-cache
            PageCache localcache = this.cache.get();
            if (localcache == null)
            {
               localcache = cursorProvider.getPageCache(pageId);
               this.cache = new WeakReference<PageCache>(localcache);
            }

            return localcache.getNumberOfMessages();
         }
         else
         {
            return numberOfMessages;
         }
View Full Code Here

Examples of org.hornetq.core.paging.cursor.PageCache

      return activeCursors.get(cursorID);
   }

   public PagedMessage getMessage(final PagePosition pos) throws Exception
   {
      PageCache cache = getPageCache(pos.getPageNr());

      if (cache == null || pos.getMessageNr() >= cache.getNumberOfMessages())
      {
         // sanity check, this should never happen unless there's a bug
         throw new IllegalStateException("Invalid messageNumber passed = " + pos + " on " + cache);
      }

      return cache.getMessage(pos.getMessageNr());
   }
View Full Code Here

Examples of org.hornetq.core.paging.cursor.PageCache

   public PageCache getPageCache(final long pageId)
   {
      try
      {
         boolean needToRead = false;
         PageCache cache = null;
         synchronized (softCache)
         {
            if (pageId > pagingStore.getCurrentWritingPage())
            {
               return null;
            }

            cache = softCache.get(pageId);
            if (cache == null)
            {
               if (!pagingStore.checkPageFileExists((int)pageId))
               {
                  return null;
               }

               cache = createPageCache(pageId);
               needToRead = true;
               // anyone reading from this cache will have to wait reading to finish first
               // we also want only one thread reading this cache
               cache.lock();
               if (isTrace)
               {
                  HornetQServerLogger.LOGGER.trace("adding " + pageId +  " into cursor = " + this.pagingStore.getAddress());
               }
               softCache.put(pageId, cache);
            }
         }

         // Reading is done outside of the synchronized block, however
         // the page stays locked until the entire reading is finished
         if (needToRead)
         {
            Page page = null;
            try
            {
               page = pagingStore.createPage((int)pageId);

               storageManager.beforePageRead();
               page.open();

               List<PagedMessage> pgdMessages = page.read(storageManager);
               cache.setMessages(pgdMessages.toArray(new PagedMessage[pgdMessages.size()]));
            }
            finally
            {
               try
               {
                  if (page != null)
                  {
                     page.close();
                  }
               }
               catch (Throwable ignored)
               {
               }
               storageManager.afterPageRead();
               cache.unlock();
            }
         }

         return cache;
      }
View Full Code Here

Examples of org.hornetq.core.paging.cursor.PageCache

      try
      {
         for (Page depagedPage : depagedPages)
         {
            PageCache cache;
            PagedMessage[] pgdMessages;
            synchronized (softCache)
            {
               cache = softCache.get((long)depagedPage.getPageId());
            }

            if (isTrace)
            {
               HornetQServerLogger.LOGGER.trace("Removing page " + depagedPage.getPageId() + " from page-cache");
            }

            if (cache == null)
            {
               // The page is not on cache any more
               // We need to read the page-file before deleting it
               // to make sure we remove any large-messages pending
               storageManager.beforePageRead();

               List<PagedMessage> pgdMessagesList = null;
               try
               {
                  depagedPage.open();
                  pgdMessagesList = depagedPage.read(storageManager);
               }
               finally
               {
                  try
                  {
                     depagedPage.close();
                  }
                  catch (Exception e)
                  {
                  }

                  storageManager.afterPageRead();
               }
               depagedPage.close();
               pgdMessages = pgdMessagesList.toArray(new PagedMessage[pgdMessagesList.size()]);
            }
            else
            {
               pgdMessages = cache.getMessages();
            }

            depagedPage.delete(pgdMessages);
            onDeletePage(depagedPage);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.