use of com.bonree.brfs.client.meta.impl.DiskServiceMetaCache in project BRFS by zhangnianli.
the class ServiceSelectorManager method useDiskSelector.
/**
* 概述:选择相应的selector缓存
* @param snIndex
* @return
* @throws Exception
* @user <a href=mailto:weizheng@bonree.com>魏征</a>
*/
public ReaderServiceSelector useDiskSelector(int snIndex) throws Exception {
ReaderServiceSelector readServerSelector = diskServiceSelectorCachaMap.get(snIndex);
if (readServerSelector != null) {
return readServerSelector;
}
DiskServiceMetaCache diskServiceMetaCache = new DiskServiceMetaCache(zkClient, zkServerIDPath, snIndex, diskServiceGroup);
serviceManager.addServiceStateListener(diskServiceGroup, new ServiceStateListener() {
@Override
public void serviceRemoved(Service service) {
diskServiceMetaCache.removeService(service);
}
@Override
public void serviceAdded(Service service) {
diskServiceMetaCache.addService(service);
}
});
diskServiceMetaCache.loadMetaCachae(serviceManager);
RouteRoleCache routeCache = new RouteRoleCache(zkClient, snIndex, baseRoutePath);
RouteParser routeParser = new RouteParser(routeCache);
// 兼容余鹏的client读取
readServerSelector = new ReaderServiceSelector(diskServiceMetaCache, routeParser);
RouteCacheListener cacheListener = new RouteCacheListener(routeCache);
treeCache.getListenable().addListener(cacheListener);
diskServiceSelectorCachaMap.put(snIndex, readServerSelector);
return readServerSelector;
}
Aggregations