use of com.bonree.brfs.common.service.ServiceStateListener in project BRFS by zhangnianli.
the class TestService method main.
public static void main(String[] args) throws Exception {
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
CuratorFramework client = CuratorFrameworkFactory.newClient("192.168.101.86:2181", 3000, 3000, retryPolicy);
client.start();
client.blockUntilConnected();
ServiceManager sm = new DefaultServiceManager(client.usingNamespace("test"));
sm.start();
Service s = new Service();
s.setServiceGroup("group");
s.setServiceId("ser_" + ID);
s.setHost("local");
sm.registerService(s);
Service tmp = sm.getServiceById(s.getServiceGroup(), s.getServiceId());
System.out.println(tmp);
sm.addServiceStateListener("group", new ServiceStateListener() {
@Override
public void serviceRemoved(Service service) {
System.out.println("remove--" + service.getServiceId());
}
@Override
public void serviceAdded(Service service) {
System.out.println("add--" + service.getServiceId());
}
});
System.out.println(sm.getServiceById(s.getServiceGroup(), s.getServiceId()));
}
use of com.bonree.brfs.common.service.ServiceStateListener 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