Search in sources :

Example 1 with RouteCacheListener

use of com.bonree.brfs.client.route.listener.RouteCacheListener 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;
}
Also used : ReaderServiceSelector(com.bonree.brfs.client.route.impl.ReaderServiceSelector) ServiceStateListener(com.bonree.brfs.common.service.ServiceStateListener) DiskServiceMetaCache(com.bonree.brfs.client.meta.impl.DiskServiceMetaCache) Service(com.bonree.brfs.common.service.Service) RouteCacheListener(com.bonree.brfs.client.route.listener.RouteCacheListener)

Aggregations

DiskServiceMetaCache (com.bonree.brfs.client.meta.impl.DiskServiceMetaCache)1 ReaderServiceSelector (com.bonree.brfs.client.route.impl.ReaderServiceSelector)1 RouteCacheListener (com.bonree.brfs.client.route.listener.RouteCacheListener)1 Service (com.bonree.brfs.common.service.Service)1 ServiceStateListener (com.bonree.brfs.common.service.ServiceStateListener)1