@Override public synchronized PagingStore newStore(final SimpleString address, final AddressSettings settings) { return new PagingStoreImpl(address, scheduledExecutor, syncTimeout, pagingManager, storageManager, null, this, address, settings, executorFactory.getExecutor(), syncNonTransactional); }
@Override public synchronized PagingStore newStore(final SimpleString address, final AddressSettings settings) { return new PagingStoreImpl(address, scheduledExecutor, syncTimeout, pagingManager, storageManager, null, this, address, settings, executorFactory.getExecutor(), executorFactory.getExecutor(), syncNonTransactional); }
@Override public List<PagingStore> reloadStores(final HierarchicalRepository<AddressSettings> addressSettingsRepository) throws Exception { File[] files = directory.listFiles(); if (files == null) { return Collections.<PagingStore>emptyList(); } else { ArrayList<PagingStore> storesReturn = new ArrayList<>(files.length); for (File file : files) { final String guid = file.getName(); final File addressFile = new File(file, PagingStoreFactoryNIO.ADDRESS_FILE); if (!addressFile.exists()) { // This means this folder is from a replication copy, nothing to worry about it, we just skip it if (!file.getName().contains(FileMoveManager.PREFIX)) { ActiveMQServerLogger.LOGGER.pageStoreFactoryNoIdFile(file.toString(), PagingStoreFactoryNIO.ADDRESS_FILE); } continue; } String addressString; try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(addressFile)))) { addressString = reader.readLine(); } SimpleString address = new SimpleString(addressString); SequentialFileFactory factory = newFileFactory(guid); AddressSettings settings = addressSettingsRepository.getMatch(address.toString()); PagingStore store = new PagingStoreImpl(address, scheduledExecutor, syncTimeout, pagingManager, storageManager, factory, this, address, settings, executorFactory.getExecutor(), executorFactory.getExecutor(), syncNonTransactional); storesReturn.add(store); } return storesReturn; } }
@Override public synchronized List<PagingStore> reloadStores(final HierarchicalRepository<AddressSettings> addressSettingsRepository) throws Exception { // We assume the directory list < Integer.MAX_VALUE (this is only a list of addresses). JDBCSequentialFile directoryList = (JDBCSequentialFile) pagingFactoryFileFactory.createSequentialFile(DIRECTORY_NAME); directoryList.open(); int size = ((Long) directoryList.size()).intValue(); ActiveMQBuffer buffer = readActiveMQBuffer(directoryList, size); ArrayList<PagingStore> storesReturn = new ArrayList<>(); while (buffer.readableBytes() > 0) { SimpleString table = buffer.readSimpleString(); JDBCSequentialFileFactory factory = (JDBCSequentialFileFactory) newFileFactory(table.toString(), false); factory.start(); JDBCSequentialFile addressFile = (JDBCSequentialFile) factory.createSequentialFile(ADDRESS_FILE); addressFile.open(); size = ((Long) addressFile.size()).intValue(); if (size == 0) { continue; } ActiveMQBuffer addrBuffer = readActiveMQBuffer(addressFile, size); SimpleString address = addrBuffer.readSimpleString(); AddressSettings settings = addressSettingsRepository.getMatch(address.toString()); PagingStore store = new PagingStoreImpl(address, scheduledExecutor, syncTimeout, pagingManager, storageManager, factory, this, address, settings, executorFactory.getExecutor(), syncNonTransactional); storesReturn.add(store); } directoryList.close(); return storesReturn; }
@Test public void testDoubleStart() throws Exception { SequentialFileFactory factory = new FakeSequentialFileFactory(); PagingStore storeImpl = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, new FakeStoreFactory(factory), PagingStoreImplTest.destinationTestName, new AddressSettings().setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE), getExecutorFactory().getExecutor(), true); storeImpl.start(); // this is not supposed to throw an exception. // As you could have start being called twice as Stores are dynamically // created, on a multi-thread environment storeImpl.start(); storeImpl.stop(); }
@Test public void testRestartPage() throws Throwable { clearDataRecreateServerDirs(); SequentialFileFactory factory = new NIOSequentialFileFactory(new File(getPageDir()), 1); PagingStoreFactory storeFactory = new FakeStoreFactory(factory); final int MAX_SIZE = 1024 * 10; AddressSettings settings = new AddressSettings().setPageSizeBytes(MAX_SIZE).setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE); final PagingStore storeImpl = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, storeFactory, new SimpleString("test"), settings, getExecutorFactory().getExecutor(), true); storeImpl.start(); Assert.assertEquals(0, storeImpl.getNumberOfPages()); // Marked the store to be paged storeImpl.startPaging(); storeImpl.depage(); Assert.assertNull(storeImpl.getCurrentPage()); storeImpl.startPaging(); Assert.assertNotNull(storeImpl.getCurrentPage()); storeImpl.stop(); }
@Test public void testStore() throws Exception { SequentialFileFactory factory = new FakeSequentialFileFactory(); PagingStoreFactory storeFactory = new FakeStoreFactory(factory); AddressSettings addressSettings = new AddressSettings().setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE); PagingStore storeImpl = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, storeFactory, PagingStoreImplTest.destinationTestName, addressSettings, getExecutorFactory().getExecutor(), true); storeImpl.start(); Assert.assertEquals(0, storeImpl.getNumberOfPages()); storeImpl.startPaging(); Assert.assertEquals(1, storeImpl.getNumberOfPages()); List<ActiveMQBuffer> buffers = new ArrayList<>(); ActiveMQBuffer buffer = createRandomBuffer(0, 10); buffers.add(buffer); SimpleString destination = new SimpleString("test"); Message msg = createMessage(1, storeImpl, destination, buffer); Assert.assertTrue(storeImpl.isPaging()); final RoutingContextImpl ctx = new RoutingContextImpl(null); Assert.assertTrue(storeImpl.page(msg, ctx.getTransaction(), ctx.getContextListing(storeImpl.getStoreName()), lock)); Assert.assertEquals(1, storeImpl.getNumberOfPages()); storeImpl.sync(); storeImpl = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, storeFactory, PagingStoreImplTest.destinationTestName, addressSettings, getExecutorFactory().getExecutor(), true); storeImpl.start(); Assert.assertEquals(1, storeImpl.getNumberOfPages()); }
final PagingStore store = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, storeFactory, new SimpleString("test"), settings, getExecutorFactory().getExecutor(), false);
PagingStoreImpl storeImpl = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, storeFactory, PagingStoreImplTest.destinationTestName, new AddressSettings().setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE), getExecutorFactory().getExecutor(), true);
final PagingStore storeImpl = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, storeFactory, new SimpleString("test"), settings, getExecutorFactory().getExecutor(), true); PagingStore storeImpl2 = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, storeFactory, new SimpleString("test"), settings, getExecutorFactory().getExecutor(), true); storeImpl2.start();
PagingStoreImpl store = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, storeFactory, PagingStoreImplTest.destinationTestName, new AddressSettings().setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE), getExecutorFactory().getExecutor(), true);