@Override protected DataStore createDataStore(ComponentContext context, Map<String, Object> config) { long cacheSize = PropertiesUtil.toLong(config.get(CACHE_SIZE), 0L); // return CachingFDS when cacheSize > 0 if (cacheSize > 0) { String fsBackendPath = PropertiesUtil.toString(config.get(PATH), null); Preconditions.checkNotNull(fsBackendPath, "Cannot create " + "FileDataStoreService with caching. [{path}] property not configured."); config.remove(PATH); config.remove(CACHE_SIZE); config.put(FS_BACKEND_PATH, fsBackendPath); config.put("cacheSize", cacheSize); String cachePath = PropertiesUtil.toString(config.get(CACHE_PATH), null); if (cachePath != null) { config.remove(CACHE_PATH); config.put(PATH, cachePath); } Properties properties = new Properties(); properties.putAll(config); log.info("Initializing with properties " + properties); return getCachingDataStore(properties, context); } else { log.info("OakFileDataStore initialized"); return new OakFileDataStore(); } }
private DataStore getCachingDataStore(Properties props, ComponentContext context) { CachingFileDataStore dataStore = new CachingFileDataStore(); dataStore.setStagingSplitPercentage( PropertiesUtil.toInteger(props.get("stagingSplitPercentage"), 0)); dataStore.setProperties(props); Dictionary<String, Object> config = new Hashtable<String, Object>(); config.put(Constants.SERVICE_PID, dataStore.getClass().getName()); config.put(DESCRIPTION, getDescription()); delegateReg = context.getBundleContext().registerService(new String[] { AbstractSharedCachingDataStore.class.getName(), AbstractSharedCachingDataStore.class.getName() }, dataStore , config); return dataStore; }
private DataStore getAssertCachingFileDataStore(String nasPath, String cachePath) throws RepositoryException { long cacheSize = 100L; Map<String, Object> config = new HashMap<String, Object>(); config.put("repository.home", folder.getRoot().getAbsolutePath()); config.put(FileDataStoreService.CACHE_SIZE, cacheSize); config.put(FileDataStoreService.PATH, nasPath); config.put(FileDataStoreService.CACHE_PATH, cachePath); FileDataStoreService fdsSvc = new FileDataStoreService(); DataStore ds = fdsSvc.createDataStore(context.componentContext(), config); PropertiesUtil.populate(ds, config, false); ds.init(folder.getRoot().getAbsolutePath()); assertTrue("not instance of CachingFDS", ds instanceof CachingFileDataStore); return ds; }
@Test public void mbeanRegs() throws Exception{ Map<String, Object> config = ImmutableMap.<String, Object>of( "repository.home", folder.getRoot().getAbsolutePath() ); FileDataStoreService fds = new FileDataStoreService(); fds.setStatisticsProvider(StatisticsProvider.NOOP); MockOsgi.activate(fds, context.bundleContext(), config); assertNotNull(context.getService(BlobStoreStatsMBean.class)); assertNotNull(context.getService(CacheStatsMBean.class)); }
/** * * Test to verify @FileDataStore is returned if cacheSize is not configured. */ @Test public void configFileDataStore() throws Exception { String nasPath = folder.getRoot().getAbsolutePath() + "/NASPath"; String cachePath = folder.getRoot().getAbsolutePath() + "/cachePath"; Map<String, Object> config = new HashMap<String, Object>(); config.put("repository.home", folder.getRoot().getAbsolutePath()); config.put(FileDataStoreService.PATH, nasPath); config.put(FileDataStoreService.CACHE_PATH, cachePath); FileDataStoreService fdsSvc = new FileDataStoreService(); DataStore ds = fdsSvc.createDataStore(context.componentContext(), config); PropertiesUtil.populate(ds, config, false); ds.init(folder.getRoot().getAbsolutePath()); assertTrue("not instance of FileDataStore", ds instanceof FileDataStore); FileDataStore fds = (FileDataStore) ds; assertEquals("path not equal", nasPath, fds.getPath()); }
private DataStore getCachingDataStore(Properties props, ComponentContext context) { CachingFileDataStore dataStore = new CachingFileDataStore(); dataStore.setStagingSplitPercentage( PropertiesUtil.toInteger(props.get("stagingSplitPercentage"), 0)); dataStore.setProperties(props); Dictionary<String, Object> config = new Hashtable<String, Object>(); config.put(Constants.SERVICE_PID, dataStore.getClass().getName()); config.put(DESCRIPTION, getDescription()); delegateReg = context.getBundleContext().registerService(new String[] { AbstractSharedCachingDataStore.class.getName(), AbstractSharedCachingDataStore.class.getName() }, dataStore , config); return dataStore; }
@Override protected DataStore createDataStore(ComponentContext context, Map<String, Object> config) { long cacheSize = PropertiesUtil.toLong(config.get(CACHE_SIZE), 0L); // return CachingFDS when cacheSize > 0 if (cacheSize > 0) { String fsBackendPath = PropertiesUtil.toString(config.get(PATH), null); Preconditions.checkNotNull(fsBackendPath, "Cannot create " + "FileDataStoreService with caching. [{path}] property not configured."); config.remove(PATH); config.remove(CACHE_SIZE); config.put(FS_BACKEND_PATH, fsBackendPath); config.put("cacheSize", cacheSize); String cachePath = PropertiesUtil.toString(config.get(CACHE_PATH), null); if (cachePath != null) { config.remove(CACHE_PATH); config.put(PATH, cachePath); } Properties properties = new Properties(); properties.putAll(config); log.info("Initializing with properties " + properties); return getCachingDataStore(properties, context); } else { log.info("OakFileDataStore initialized"); return new OakFileDataStore(); } }
private DataStore getCachingDataStore(Properties props, ComponentContext context) { CachingFileDataStore dataStore = new CachingFileDataStore(); dataStore.setStagingSplitPercentage( PropertiesUtil.toInteger(props.get("stagingSplitPercentage"), 0)); dataStore.setProperties(props); Dictionary<String, Object> config = new Hashtable<String, Object>(); config.put(Constants.SERVICE_PID, dataStore.getClass().getName()); config.put(DESCRIPTION, getDescription()); delegateReg = context.getBundleContext().registerService(new String[] { AbstractSharedCachingDataStore.class.getName(), AbstractSharedCachingDataStore.class.getName() }, dataStore , config); return dataStore; }
@Override protected DataStore createDataStore(ComponentContext context, Map<String, Object> config) { long cacheSize = PropertiesUtil.toLong(config.get(CACHE_SIZE), 0L); // return CachingFDS when cacheSize > 0 if (cacheSize > 0) { String fsBackendPath = PropertiesUtil.toString(config.get(PATH), null); Preconditions.checkNotNull(fsBackendPath, "Cannot create " + "FileDataStoreService with caching. [{path}] property not configured."); config.remove(PATH); config.remove(CACHE_SIZE); config.put(FS_BACKEND_PATH, fsBackendPath); config.put("cacheSize", cacheSize); String cachePath = PropertiesUtil.toString(config.get(CACHE_PATH), null); if (cachePath != null) { config.remove(CACHE_PATH); config.put(PATH, cachePath); } Properties properties = new Properties(); properties.putAll(config); log.info("Initializing with properties " + properties); return getCachingDataStore(properties, context); } else { log.info("OakFileDataStore initialized"); return new OakFileDataStore(); } }