Review Code

This commit is contained in:
wusheng 2016-11-07 09:45:53 +08:00
parent dcf859dfc1
commit 3210d1ff82
3 changed files with 18 additions and 31 deletions

View File

@ -60,14 +60,21 @@ public class IndexDataCapacityMonitor {
public static void start() {
long timestamp = BlockIndexEngine.newFinder().findLastBlockIndex();
IndexDBConnector dbConnector = new IndexDBConnector(timestamp);
long count = 0;
//TODO: 为IndexDBConnector增加闭包执行函数
IndexDBConnector dbConnector = null;
try {
count = dbConnector.fetchIndexSize();
} catch (SQLException e) {
logger.error("Failed to to fetch index size from DB:{}", timestamp, e);
dbConnector = new IndexDBConnector(timestamp);
long count = 0;
try {
count = dbConnector.fetchIndexSize();
} catch (SQLException e) {
logger.error("Failed to to fetch index size from DB:{}", timestamp, e);
}
detector = new Detector(timestamp, count);
} finally {
if(dbConnector != null){
dbConnector.close();
}
}
detector = new Detector(timestamp, count);
}
}

View File

@ -136,4 +136,8 @@ public class IndexDBConnector {
return "jdbc:hsqldb:file:" + basePath + "/" + timestamp + "/" + dbFileName;
}
}
public void close(){
//TODO:
}
}

View File

@ -11,35 +11,11 @@ import java.util.List;
public class IndexMetaCollection implements Iterable<IndexMetaInfo> {
private List<IndexMetaInfo> metaInfo;
private BlockFinder finder;
public IndexMetaCollection() {
metaInfo = new ArrayList<>();
finder = BlockIndexEngine.newFinder();
}
public Iterator<IndexMetaGroup> group() {
List<IndexMetaGroup> indexMetaGroups = new ArrayList<IndexMetaGroup>();
for (IndexMetaInfo info : metaInfo) {
long timestamp = finder.find(info.getStartTime());
int index = indexMetaGroups.indexOf(new IndexMetaGroup(timestamp));
IndexMetaGroup metaGroup;
if (index == -1) {
metaGroup = new IndexMetaGroup(timestamp);
indexMetaGroups.add(metaGroup);
} else {
metaGroup = indexMetaGroups.get(index);
}
metaGroup.addIndexMetaInfo(info);
}
return indexMetaGroups.iterator();
}
public void add(IndexMetaInfo info) {
metaInfo.add(info);
}