@Test public void testRepsitory() { MetadataContext context = new MetadataContext(); context.setRefreshRepsitory(false); List<Repository> oldRepos = repositoryService.getRepositories(context); Assert.assertTrue(oldRepos.size() > 0); List<Repository> cachedRepos = repositoryService.getRepositories(context); for (final Repository repo : oldRepos) { Assert.assertNotNull(CollectionUtils.find(cachedRepos, new Predicate() { @Override public boolean evaluate(Object object) { if (object == repo) { return true; } return false; } })); } context.setRefreshRepsitory(true); List<Repository> newRepos = repositoryService.getRepositories(context); for (final Repository repo : newRepos) { Assert.assertNull(CollectionUtils.find(cachedRepos, new Predicate() { @Override public boolean evaluate(Object object) { if (object == repo) { return true; } return false; } })); } }
@Override public List<Repository> getRepositories(MetadataContext ctx) { MetadataContext context = ctx != null ? ctx : new MetadataContext(); if (!context.isRefreshRepsitory()) { return cache.values(); } ExpirableCache<Repository> newCache = new ExpirableCache<Repository>(maxCacheSize, cacheExpiredTime); BasicDBObject query = new BasicDBObject(); query.put(Repository.STATE_FIELD, Repository.StateEnum.normal.toString()); List<Repository> result = new ArrayList<Repository>(); DBCursor cursor = repoCollection.find(query); while (cursor.hasNext()) { DBObject object = cursor.next(); Repository r = repositoryConverter.fromBson(object, Repository.class); createServiceForRepository(r); result.add(r); newCache.putObject(r.getRepositoryName(), r); } cache = newCache; return result; }
MongoRepositoryServiceImpl implements IRepositoryService { @Override public List<Repository> getRepositories(MetadataContext ctx) { MetadataContext context = ctx != null ? ctx : new MetadataContext(); if (!context.isRefreshRepsitory()) { return cache.values(); } ExpirableCache<Repository> newCache = new ExpirableCache<Repository>(maxCacheSize, cacheExpiredTime); BasicDBObject query = new BasicDBObject(); query.put(Repository.STATE_FIELD, Repository.StateEnum.normal.toString()); List<Repository> result = new ArrayList<Repository>(); DBCursor cursor = repoCollection.find(query); while (cursor.hasNext()) { DBObject object = cursor.next(); Repository r = repositoryConverter.fromBson(object, Repository.class); createServiceForRepository(r); result.add(r); newCache.putObject(r.getRepositoryName(), r); } cache = newCache; return result; } }
MongoRepositoryServiceImpl implements IRepositoryService { @Override public List<Repository> getRepositories(MetadataContext ctx) { MetadataContext context = ctx != null ? ctx : new MetadataContext(); if (!context.isRefreshRepsitory()) { return cache.values(); } ExpirableCache<Repository> newCache = new ExpirableCache<Repository>(maxCacheSize, cacheExpiredTime); BasicDBObject query = new BasicDBObject(); query.put(Repository.STATE_FIELD, Repository.StateEnum.normal.toString()); List<Repository> result = new ArrayList<Repository>(); DBCursor cursor = repoCollection.find(query); while (cursor.hasNext()) { DBObject object = cursor.next(); Repository r = repositoryConverter.fromBson(object, Repository.class); createServiceForRepository(r); result.add(r); newCache.putObject(r.getRepositoryName(), r); } cache = newCache; return result; } MongoRepositoryServiceImpl(Mongo mongo, int maxCacheSize, int cacheExpiredTime,
			int collectionCountCacheSize, int collectionCountCacheExpiredTime, ICMSLock metadataLock,
			WriteConcern writeConcern); }
MongoRepositoryServiceImpl implements IRepositoryService { @Override public List<Repository> getRepositories(MetadataContext ctx) { MetadataContext context = ctx != null ? ctx : new MetadataContext(); if (!context.isRefreshRepsitory()) { return cache.values(); } ExpirableCache<Repository> newCache = new ExpirableCache<Repository>(maxCacheSize, cacheExpiredTime); BasicDBObject query = new BasicDBObject(); query.put(Repository.STATE_FIELD, Repository.StateEnum.normal.toString()); List<Repository> result = new ArrayList<Repository>(); DBCursor cursor = repoCollection.find(query); while (cursor.hasNext()) { DBObject object = cursor.next(); Repository r = repositoryConverter.fromBson(object, Repository.class); createServiceForRepository(r); result.add(r); newCache.putObject(r.getRepositoryName(), r); } cache = newCache; return result; } MongoRepositoryServiceImpl(Mongo mongo, int maxCacheSize, int cacheExpiredTime,
			int collectionCountCacheSize, int collectionCountCacheExpiredTime, ICMSLock metadataLock,
			WriteConcern writeConcern); static void prepareSystemDB(Mongo mongo); @Override Repository createRepository(Repository repo); @Override Repository createRepository(Repository repo, WriteConcern writeConcern); @Override void updateRepository(Repository repo); @Override Repository getRepository(String repositoryName); @Override List<Repository> getRepositories(MetadataContext ctx); @Override void deleteRepository(String repositoryName); @Override List<Repository> getRepositories(AccessType type); @Override void setHistoryService(IMetadataHistoryService historyService); }
MongoRepositoryServiceImpl implements IRepositoryService { @Override public List<Repository> getRepositories(MetadataContext ctx) { MetadataContext context = ctx != null ? ctx : new MetadataContext(); if (!context.isRefreshRepsitory()) { return cache.values(); } ExpirableCache<Repository> newCache = new ExpirableCache<Repository>(maxCacheSize, cacheExpiredTime); BasicDBObject query = new BasicDBObject(); query.put(Repository.STATE_FIELD, Repository.StateEnum.normal.toString()); List<Repository> result = new ArrayList<Repository>(); DBCursor cursor = repoCollection.find(query); while (cursor.hasNext()) { DBObject object = cursor.next(); Repository r = repositoryConverter.fromBson(object, Repository.class); createServiceForRepository(r); result.add(r); newCache.putObject(r.getRepositoryName(), r); } cache = newCache; return result; } MongoRepositoryServiceImpl(Mongo mongo, int maxCacheSize, int cacheExpiredTime,
			int collectionCountCacheSize, int collectionCountCacheExpiredTime, ICMSLock metadataLock,
			WriteConcern writeConcern); static void prepareSystemDB(Mongo mongo); @Override Repository createRepository(Repository repo); @Override Repository createRepository(Repository repo, WriteConcern writeConcern); @Override void updateRepository(Repository repo); @Override Repository getRepository(String repositoryName); @Override List<Repository> getRepositories(MetadataContext ctx); @Override void deleteRepository(String repositoryName); @Override List<Repository> getRepositories(AccessType type); @Override void setHistoryService(IMetadataHistoryService historyService);  }