use of com.alipay.sofa.rpc.config.AbstractInterfaceConfig in project sofa-rpc by sofastack.
the class ZookeeperRegistry method subscribeOverride.
/**
* 订阅IP级配置(服务发布暂时不支持动态配置,暂时支持订阅ConsumerConfig参数设置)
*
* @param config consumer config
* @param listener config listener
*/
protected void subscribeOverride(final ConsumerConfig config, ConfigListener listener) {
try {
if (overrideObserver == null) {
// 初始化
overrideObserver = new ZookeeperOverrideObserver();
}
overrideObserver.addConfigListener(config, listener);
final String overridePath = buildOverridePath(rootPath, config);
final AbstractInterfaceConfig registerConfig = getRegisterConfig(config);
// 监听配置节点下 子节点增加、子节点删除、子节点Data修改事件
PathChildrenCache pathChildrenCache = new PathChildrenCache(zkClient, overridePath, true);
pathChildrenCache.getListenable().addListener(new PathChildrenCacheListener() {
@Override
public void childEvent(CuratorFramework client1, PathChildrenCacheEvent event) throws Exception {
if (LOGGER.isDebugEnabled(config.getAppName())) {
LOGGER.debug("Receive zookeeper event: " + "type=[" + event.getType() + "]");
}
switch(event.getType()) {
case // 新增IP级配置
CHILD_ADDED:
overrideObserver.addConfig(config, overridePath, event.getData());
break;
case // 删除IP级配置
CHILD_REMOVED:
overrideObserver.removeConfig(config, overridePath, event.getData(), registerConfig);
break;
case // 更新IP级配置
CHILD_UPDATED:
overrideObserver.updateConfig(config, overridePath, event.getData());
break;
default:
break;
}
}
});
pathChildrenCache.start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE);
INTERFACE_OVERRIDE_CACHE.put(overridePath, pathChildrenCache);
overrideObserver.updateConfigAll(config, overridePath, pathChildrenCache.getCurrentData());
} catch (Exception e) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_SUB_PROVIDER_OVERRIDE, EXT_NAME), e);
}
}
use of com.alipay.sofa.rpc.config.AbstractInterfaceConfig in project sofa-rpc by sofastack.
the class BeanIdMatchFilterTest method testIsMatch.
@Test
public void testIsMatch() {
TestCustomizeFilter testCustomizeFilter = new TestCustomizeFilter();
Assert.assertTrue(testCustomizeFilter.isMatch(""));
testCustomizeFilter = new TestCustomizeFilter();
testCustomizeFilter.setIdRule("AAA,BBB");
AbstractInterfaceConfig configA = new ProviderConfig();
configA.setInterfaceId(Serializer.class.getName());
configA.setId("AAA");
FilterInvoker filterInvokerA = new FilterInvoker(null, null, configA);
Assert.assertEquals(true, testCustomizeFilter.needToLoad(filterInvokerA));
}
use of com.alipay.sofa.rpc.config.AbstractInterfaceConfig in project sofa-rpc by sofastack.
the class BeanIdMatchFilterTest method testBeanIdMatch.
@Test
public void testBeanIdMatch() {
TestCustomizeFilter testCustomizeFilter = new TestCustomizeFilter();
testCustomizeFilter.setIdRule("AAA,!BBB");
Assert.assertEquals("AAA,!BBB", testCustomizeFilter.getIdRule());
AbstractInterfaceConfig configA = new ProviderConfig();
configA.setInterfaceId(Serializer.class.getName());
configA.setId("AAA");
FilterInvoker filterInvokerA = new FilterInvoker(null, null, configA);
AbstractInterfaceConfig configB = new ProviderConfig();
configB.setInterfaceId(Serializer.class.getName());
configB.setId("BBB");
FilterInvoker filterInvokerB = new FilterInvoker(null, null, configB);
AbstractInterfaceConfig configC = new ProviderConfig();
configC.setInterfaceId(Serializer.class.getName());
configC.setId("CCC");
FilterInvoker filterInvokerC = new FilterInvoker(null, null, configC);
Assert.assertEquals(true, testCustomizeFilter.needToLoad(filterInvokerA));
Assert.assertEquals(false, testCustomizeFilter.needToLoad(filterInvokerB));
Assert.assertEquals(true, testCustomizeFilter.needToLoad(filterInvokerC));
}
use of com.alipay.sofa.rpc.config.AbstractInterfaceConfig in project sofa-rpc by sofastack.
the class BeanIdMatchFilter method needToLoad.
@Override
public boolean needToLoad(FilterInvoker invoker) {
AbstractInterfaceConfig config = invoker.config;
String invokerId = config.getId();
if (!formatComplete) {
synchronized (formatLock) {
if (!formatComplete) {
formatId(idRule);
formatComplete = true;
}
}
}
return isMatch(invokerId);
}
Aggregations