public PagingStoreFactoryDatabase(final DatabaseStorageConfiguration dbConf, final StorageManager storageManager, final long syncTimeout, final ScheduledExecutorService scheduledExecutor, final ExecutorFactory executorFactory, final boolean syncNonTransactional, final IOCriticalErrorListener critialErrorListener) throws Exception { this.storageManager = storageManager; this.executorFactory = executorFactory; this.syncNonTransactional = syncNonTransactional; this.scheduledExecutor = scheduledExecutor; this.syncTimeout = syncTimeout; this.dbConf = dbConf; this.criticalErrorListener = critialErrorListener; this.factoryToTableName = new HashMap<>(); start(); }
protected PagingStoreFactory getPagingStoreFactory() throws Exception { if (configuration.getStoreConfiguration() != null && configuration.getStoreConfiguration().getStoreType() == StoreConfiguration.StoreType.DATABASE) { DatabaseStorageConfiguration dbConf = (DatabaseStorageConfiguration) configuration.getStoreConfiguration(); return new PagingStoreFactoryDatabase(dbConf, storageManager, configuration.getJournalBufferTimeout_NIO(), scheduledPool, ioExecutorFactory, false, shutdownOnCriticalIO); } return new PagingStoreFactoryNIO(storageManager, configuration.getPagingLocation(), configuration.getJournalBufferTimeout_NIO(), scheduledPool, ioExecutorFactory, configuration.isJournalSyncNonTransactional(), shutdownOnCriticalIO); }
@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; }
@Override public synchronized void removeFileFactory(SequentialFileFactory fileFactory) throws Exception { ((JDBCSequentialFileFactory)fileFactory).destroy(); String tableName = factoryToTableName.remove(fileFactory); if (tableName != null) { SimpleString removeTableName = SimpleString.toSimpleString(tableName); JDBCSequentialFile directoryList = (JDBCSequentialFile) pagingFactoryFileFactory.createSequentialFile(DIRECTORY_NAME); directoryList.open(); int size = ((Long) directoryList.size()).intValue(); ActiveMQBuffer buffer = readActiveMQBuffer(directoryList, size); ActiveMQBuffer writeBuffer = ActiveMQBuffers.fixedBuffer(size); while (buffer.readableBytes() > 0) { SimpleString table = buffer.readSimpleString(); if (!removeTableName.equals(table)) { writeBuffer.writeSimpleString(table); } } directoryList.write(writeBuffer, true, null, false); directoryList.close(); } }
@Override public synchronized SequentialFileFactory newFileFactory(final SimpleString address) throws Exception { String tableName = "" + storageManager.generateID(); SequentialFileFactory factory = newFileFactory(tableName, true); factory.start(); SequentialFile file = factory.createSequentialFile(PagingStoreFactoryDatabase.ADDRESS_FILE); file.open(); ActiveMQBuffer buffer = ActiveMQBuffers.fixedBuffer(SimpleString.sizeofNullableString(address)); buffer.writeSimpleString(address); file.write(buffer, true); file.close(); return factory; }
private synchronized SequentialFileFactory newFileFactory(final String directoryName, boolean writeToDirectory) throws Exception { JDBCSequentialFile directoryList = (JDBCSequentialFile) pagingFactoryFileFactory.createSequentialFile(DIRECTORY_NAME); directoryList.open(); SimpleString simpleString = SimpleString.toSimpleString(directoryName); ActiveMQBuffer buffer = ActiveMQBuffers.fixedBuffer(simpleString.sizeof()); buffer.writeSimpleString(simpleString); if (writeToDirectory) directoryList.write(buffer, true); directoryList.close(); final SQLProvider sqlProvider; if (dbConf.getDataSource() != null) { final SQLProvider.Factory sqlProviderFactory; if (dbConf.getSqlProviderFactory() != null) { sqlProviderFactory = dbConf.getSqlProviderFactory(); } else { sqlProviderFactory = new PropertySQLProvider.Factory(dbConf.getDataSource()); } sqlProvider = sqlProviderFactory.create(getTableNameForGUID(directoryName), SQLProvider.DatabaseStoreType.PAGE); } else { sqlProvider = JDBCUtils.getSQLProvider(dbConf.getJdbcDriverClassName(), getTableNameForGUID(directoryName), SQLProvider.DatabaseStoreType.PAGE); } final JDBCSequentialFileFactory fileFactory = new JDBCSequentialFileFactory(pagingFactoryFileFactory.getDbDriver().getConnection(), sqlProvider, executorFactory.getExecutor(), criticalErrorListener); final int jdbcNetworkTimeout = dbConf.getJdbcNetworkTimeout(); if (jdbcNetworkTimeout >= 0) { fileFactory.setNetworkTimeout(this.executorFactory.getExecutor(), jdbcNetworkTimeout); } factoryToTableName.put(fileFactory, directoryName); return fileFactory; }
protected void initializeJournal(Configuration configuration) throws Exception { this.config = configuration; executor = Executors.newFixedThreadPool(5, ActiveMQThreadFactory.defaultThreadFactory()); executorFactory = new OrderedExecutorFactory(executor); scheduledExecutorService = new ScheduledThreadPoolExecutor(configuration.getScheduledThreadPoolMaxSize(), new ThreadFactory() { @Override public Thread newThread(Runnable r) { return new Thread(r); } }); HierarchicalRepository<AddressSettings> addressSettingsRepository = new HierarchicalObjectRepository<>(config.getWildcardConfiguration()); addressSettingsRepository.setDefault(new AddressSettings()); if (configuration.isJDBC()) { storageManager = new JDBCJournalStorageManager(config, null, scheduledExecutorService, executorFactory, executorFactory, null); PagingStoreFactory pageStoreFactory = new PagingStoreFactoryDatabase((DatabaseStorageConfiguration) configuration.getStoreConfiguration(), storageManager, 1000L, scheduledExecutorService, executorFactory, false, null); pagingmanager = new PagingManagerImpl(pageStoreFactory, addressSettingsRepository, configuration.getManagementAddress()); } else { storageManager = new JournalStorageManager(config, EmptyCriticalAnalyzer.getInstance(), executorFactory, executorFactory); PagingStoreFactory pageStoreFactory = new PagingStoreFactoryNIO(storageManager, config.getPagingLocation(), 1000L, scheduledExecutorService, executorFactory, true, null); pagingmanager = new PagingManagerImpl(pageStoreFactory, addressSettingsRepository, configuration.getManagementAddress()); } }
protected void initializeJournal(Configuration configuration) throws Exception { this.config = configuration; executor = Executors.newFixedThreadPool(5, ActiveMQThreadFactory.defaultThreadFactory()); executorFactory = new OrderedExecutorFactory(executor); scheduledExecutorService = new ScheduledThreadPoolExecutor(configuration.getScheduledThreadPoolMaxSize(), new ThreadFactory() { @Override public Thread newThread(Runnable r) { return new Thread(r); } }); HierarchicalRepository<AddressSettings> addressSettingsRepository = new HierarchicalObjectRepository<>(config.getWildcardConfiguration()); addressSettingsRepository.setDefault(new AddressSettings()); if (configuration.isJDBC()) { storageManager = new JDBCJournalStorageManager(config, null, scheduledExecutorService, executorFactory, executorFactory, null); PagingStoreFactory pageStoreFactory = new PagingStoreFactoryDatabase((DatabaseStorageConfiguration) configuration.getStoreConfiguration(), storageManager, 1000L, scheduledExecutorService, executorFactory, false, null); pagingmanager = new PagingManagerImpl(pageStoreFactory, addressSettingsRepository, configuration.getManagementAddress()); } else { storageManager = new JournalStorageManager(config, EmptyCriticalAnalyzer.getInstance(), executorFactory, executorFactory); PagingStoreFactory pageStoreFactory = new PagingStoreFactoryNIO(storageManager, config.getPagingLocation(), 1000L, scheduledExecutorService, executorFactory, true, null); pagingmanager = new PagingManagerImpl(pageStoreFactory, addressSettingsRepository, configuration.getManagementAddress()); } }