Search in sources :

Example 1 with AbstractInterfaceConfig

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);
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) PathChildrenCacheListener(org.apache.curator.framework.recipes.cache.PathChildrenCacheListener) PathChildrenCacheEvent(org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent) SofaRpcRuntimeException(com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException) PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) AbstractInterfaceConfig(com.alipay.sofa.rpc.config.AbstractInterfaceConfig) KeeperException(org.apache.zookeeper.KeeperException) SofaRpcRuntimeException(com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException)

Example 2 with AbstractInterfaceConfig

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));
}
Also used : ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) AbstractInterfaceConfig(com.alipay.sofa.rpc.config.AbstractInterfaceConfig) Serializer(com.alipay.sofa.rpc.codec.Serializer) Test(org.junit.Test)

Example 3 with AbstractInterfaceConfig

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));
}
Also used : ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) AbstractInterfaceConfig(com.alipay.sofa.rpc.config.AbstractInterfaceConfig) Serializer(com.alipay.sofa.rpc.codec.Serializer) Test(org.junit.Test)

Example 4 with AbstractInterfaceConfig

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);
}
Also used : AbstractInterfaceConfig(com.alipay.sofa.rpc.config.AbstractInterfaceConfig)

Aggregations

AbstractInterfaceConfig (com.alipay.sofa.rpc.config.AbstractInterfaceConfig)4 Serializer (com.alipay.sofa.rpc.codec.Serializer)2 ProviderConfig (com.alipay.sofa.rpc.config.ProviderConfig)2 Test (org.junit.Test)2 SofaRpcRuntimeException (com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1 PathChildrenCache (org.apache.curator.framework.recipes.cache.PathChildrenCache)1 PathChildrenCacheEvent (org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent)1 PathChildrenCacheListener (org.apache.curator.framework.recipes.cache.PathChildrenCacheListener)1 KeeperException (org.apache.zookeeper.KeeperException)1