public void close() throws Exception { close(false); }
private void openNewPage() throws Exception { lock.writeLock().lock(); try { numberOfPages++; int tmpCurrentPageId = currentPageId + 1; if (logger.isTraceEnabled()) { logger.trace("new pageNr=" + tmpCurrentPageId, new Exception("trace")); } if (currentPage != null) { currentPage.close(true); } currentPage = createPage(tmpCurrentPageId); LivePageCache pageCache = new LivePageCacheImpl(currentPage); currentPage.setLiveCache(pageCache); cursorProvider.addPageCache(pageCache); currentPageSize.set(0); currentPage.open(); currentPageId = tmpCurrentPageId; if (currentPageId < firstPageId) { firstPageId = currentPageId; } } finally { lock.writeLock().unlock(); } }
@Override public synchronized void stop() throws Exception { if (running) { cursorProvider.flushExecutors(); cursorProvider.stop(); final List<Runnable> pendingTasks = new ArrayList<>(); final int pendingTasksWhileShuttingDown = executor.shutdownNow(pendingTasks::add); if (pendingTasksWhileShuttingDown > 0) { logger.tracef("Try executing %d pending tasks on stop", pendingTasksWhileShuttingDown); for (Runnable pendingTask : pendingTasks) { try { pendingTask.run(); } catch (Throwable t) { logger.warn("Error while executing a pending task on shutdown", t); } } } running = false; if (currentPage != null) { currentPage.close(false); currentPage = null; } } }
private void readPage(int pageId, PageCache cache) throws Exception { Page page = null; try { page = pagingStore.createPage(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(false); } } catch (Throwable ignored) { } storageManager.afterPageRead(); } }
try { page.sync(); page.close(false); } catch (Exception e) { ActiveMQServerLogger.LOGGER.errorClosingPageOnReplication(e);
returnPage.close(false); currentPage = null;
page.open(); List<PagedMessage> msgs = page.read(sm); page.close();
page.open(); List<PagedMessage> msgs = page.read(sm); page.close();
/** * @param packet */ private void handlePageEvent(final ReplicationPageEventMessage packet) throws Exception { ConcurrentMap<Integer, Page> pages = getPageMap(packet.getStoreName()); Page page = pages.remove(packet.getPageNumber()); if (page == null) { page = getPage(packet.getStoreName(), packet.getPageNumber()); } if (page != null) { if (packet.isDelete()) { if (deletePages) { page.delete(null); } } else { page.close(false); } } }
currentPage.close(false);
page.open(); List<PagedMessage> messages = page.read(storageManager); page.close();
page.open(); List<PagedMessage> messages = page.read(storageManager); page.close();
/** * Validate if everything we add is recovered */ protected void testAdd(final SequentialFileFactory factory, final int numberOfElements) throws Exception { SequentialFile file = factory.createSequentialFile("00010.page"); Page impl = new Page(new SimpleString("something"), new NullStorageManager(), factory, file, 10); Assert.assertEquals(10, impl.getPageId()); impl.open(); Assert.assertEquals(1, factory.listFiles("page").size()); SimpleString simpleDestination = new SimpleString("Test"); addPageElements(simpleDestination, impl, numberOfElements); impl.sync(); impl.close(); file = factory.createSequentialFile("00010.page"); file.open(); impl = new Page(new SimpleString("something"), new NullStorageManager(), factory, file, 10); List<PagedMessage> msgs = impl.read(new NullStorageManager()); Assert.assertEquals(numberOfElements, msgs.size()); Assert.assertEquals(numberOfElements, impl.getNumberOfMessages()); for (int i = 0; i < msgs.size(); i++) { Assert.assertEquals(simpleDestination, msgs.get(i).getMessage().getAddressSimpleString()); } impl.delete(null); Assert.assertEquals(0, factory.listFiles(".page").size()); }
@Test public void testPagingManager() throws Exception { HierarchicalRepository<AddressSettings> addressSettings = new HierarchicalObjectRepository<>(); addressSettings.setDefault(new AddressSettings().setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE)); final StorageManager storageManager = new NullStorageManager(); PagingStoreFactoryNIO storeFactory = new PagingStoreFactoryNIO(storageManager, getPageDirFile(), 100, null, getOrderedExecutor(), true, null); PagingManagerImpl managerImpl = new PagingManagerImpl(storeFactory, addressSettings); managerImpl.start(); PagingStore store = managerImpl.getPageStore(new SimpleString("simple-test")); ICoreMessage msg = createMessage(1L, new SimpleString("simple-test"), createRandomBuffer(10)); final RoutingContextImpl ctx = new RoutingContextImpl(null); Assert.assertFalse(store.page(msg, ctx.getTransaction(), ctx.getContextListing(store.getStoreName()), lock)); store.startPaging(); Assert.assertTrue(store.page(msg, ctx.getTransaction(), ctx.getContextListing(store.getStoreName()), lock)); Page page = store.depage(); page.open(); List<PagedMessage> msgs = page.read(new NullStorageManager()); page.close(); Assert.assertEquals(1, msgs.size()); ActiveMQTestBase.assertEqualsByteArrays(msg.getBodyBuffer().writerIndex(), msg.getBodyBuffer().toByteBuffer().array(), (msgs.get(0).getMessage()).toCore().getBodyBuffer().toByteBuffer().array()); Assert.assertTrue(store.isPaging()); Assert.assertNull(store.depage()); final RoutingContextImpl ctx2 = new RoutingContextImpl(null); Assert.assertFalse(store.page(msg, ctx2.getTransaction(), ctx2.getContextListing(store.getStoreName()), lock)); }