Search in sources :

Example 86 with ConsumerConfig

use of com.alipay.sofa.rpc.config.ConsumerConfig in project sofa-rpc by sofastack.

the class MulticastRegistry method subscribe.

@Override
public List<ProviderGroup> subscribe(ConsumerConfig config) {
    if (!config.isSubscribe()) {
        return null;
    }
    String key = MulticastRegistryHelper.buildListDataId(config, config.getProtocol());
    List<ConsumerConfig> listeners = notifyListeners.get(key);
    if (listeners == null) {
        listeners = new ArrayList<ConsumerConfig>();
        notifyListeners.put(key, listeners);
    }
    listeners.add(config);
    multicast(SUBSCRIBE + key);
    ProviderGroup group = allProviderCache.get(key);
    if (group == null) {
        group = new ProviderGroup();
        allProviderCache.put(key, group);
    }
    if (EventBus.isEnable(ConsumerSubEvent.class)) {
        ConsumerSubEvent event = new ConsumerSubEvent(config);
        EventBus.post(event);
    }
    return Collections.singletonList(group);
}
Also used : ConsumerSubEvent(com.alipay.sofa.rpc.event.ConsumerSubEvent) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) ProviderGroup(com.alipay.sofa.rpc.client.ProviderGroup)

Example 87 with ConsumerConfig

use of com.alipay.sofa.rpc.config.ConsumerConfig in project sofa-rpc by sofastack.

the class LocalRegistryTest method notifyConsumerTest.

public void notifyConsumerTest() {
    LocalRegistry registry = new LocalRegistry(new RegistryConfig());
    ConsumerConfig<?> consumer = new ConsumerConfig();
    consumer.setInterfaceId("test");
    LocalRegistryTest.MockProviderInfoListener providerInfoListener = new LocalRegistryTest.MockProviderInfoListener();
    consumer.setProviderInfoListener(providerInfoListener);
    registry.subscribe(consumer);
    String key = LocalRegistryHelper.buildListDataId(consumer, consumer.getProtocol());
    registry.memoryCache.put(key, new ProviderGroup());
    Map<String, ProviderGroup> newCache = new HashMap<String, ProviderGroup>();
    ProviderGroup newProviderGroup = new ProviderGroup();
    ProviderInfo providerInfo = new ProviderInfo().setHost("0.0.0.0");
    newProviderGroup.add(providerInfo);
    newCache.put(key, newProviderGroup);
    registry.notifyConsumer(newCache);
    Map<String, ProviderGroup> ps = providerInfoListener.getData();
    Assert.assertTrue(ps.size() > 0);
    Assert.assertNotNull(ps.get(RpcConstants.ADDRESS_DEFAULT_GROUP));
    Assert.assertTrue(ps.get(RpcConstants.ADDRESS_DEFAULT_GROUP).size() == 1);
}
Also used : RegistryConfig(com.alipay.sofa.rpc.config.RegistryConfig) ProviderInfo(com.alipay.sofa.rpc.client.ProviderInfo) HashMap(java.util.HashMap) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) ProviderGroup(com.alipay.sofa.rpc.client.ProviderGroup)

Example 88 with ConsumerConfig

use of com.alipay.sofa.rpc.config.ConsumerConfig in project sofa-rpc by sofastack.

the class NacosRegistry method destroy.

@Override
public void destroy() {
    for (ProviderConfig providerConfig : providerInstances.keySet()) {
        unRegister(providerConfig);
    }
    for (ConsumerConfig consumerConfig : consumerListeners.keySet()) {
        unSubscribe(consumerConfig);
    }
    namingService = null;
    providerObserver = null;
}
Also used : ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig)

Example 89 with ConsumerConfig

use of com.alipay.sofa.rpc.config.ConsumerConfig in project sofa-rpc by sofastack.

the class MockTestRegistry method unRegister.

@Override
public void unRegister(ProviderConfig config) {
    String key = buildKey(config);
    ProviderGroup group = memoryCache.get(key);
    if (group != null) {
        List<ServerConfig> serverConfigs = config.getServer();
        if (CommonUtils.isNotEmpty(serverConfigs)) {
            for (ServerConfig server : serverConfigs) {
                group.remove(ProviderHelper.toProviderInfo(convertProviderToUrls(config, server)));
            }
        }
    }
    Map<ConsumerConfig, ProviderInfoListener> listeners = notifyListeners.get(key);
    if (listeners != null) {
        for (ProviderInfoListener listener : listeners.values()) {
            listener.updateProviders(group);
        }
    }
}
Also used : ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) ProviderInfoListener(com.alipay.sofa.rpc.listener.ProviderInfoListener) ProviderGroup(com.alipay.sofa.rpc.client.ProviderGroup) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig)

Example 90 with ConsumerConfig

use of com.alipay.sofa.rpc.config.ConsumerConfig in project sofa-rpc by sofastack.

the class MockTestRegistry method register.

@Override
public void register(ProviderConfig config) {
    String key = buildKey(config);
    ProviderGroup group = memoryCache.get(key);
    if (group == null) {
        group = buildProviderGroup();
        ProviderGroup old = memoryCache.putIfAbsent(key, group);
        if (old != null) {
            group = old;
        }
    }
    List<ServerConfig> serverConfigs = config.getServer();
    if (CommonUtils.isNotEmpty(serverConfigs)) {
        for (ServerConfig server : serverConfigs) {
            group.add(ProviderHelper.toProviderInfo(convertProviderToUrls(config, server)));
        }
    }
    Map<ConsumerConfig, ProviderInfoListener> listeners = notifyListeners.get(key);
    if (listeners != null) {
        for (ProviderInfoListener listener : listeners.values()) {
            listener.updateProviders(group);
        }
    }
}
Also used : ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) ProviderInfoListener(com.alipay.sofa.rpc.listener.ProviderInfoListener) ProviderGroup(com.alipay.sofa.rpc.client.ProviderGroup) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig)

Aggregations

ConsumerConfig (com.alipay.sofa.rpc.config.ConsumerConfig)139 Test (org.junit.Test)86 ServerConfig (com.alipay.sofa.rpc.config.ServerConfig)68 ApplicationConfig (com.alipay.sofa.rpc.config.ApplicationConfig)61 ProviderConfig (com.alipay.sofa.rpc.config.ProviderConfig)44 ActivelyDestroyTest (com.alipay.sofa.rpc.test.ActivelyDestroyTest)40 HelloService (com.alipay.sofa.rpc.test.HelloService)38 CountDownLatch (java.util.concurrent.CountDownLatch)27 SofaRpcException (com.alipay.sofa.rpc.core.exception.SofaRpcException)21 HelloServiceImpl (com.alipay.sofa.rpc.test.HelloServiceImpl)21 ArrayList (java.util.ArrayList)19 ProviderGroup (com.alipay.sofa.rpc.client.ProviderGroup)18 SofaResponseCallback (com.alipay.sofa.rpc.core.invoke.SofaResponseCallback)14 RegistryConfig (com.alipay.sofa.rpc.config.RegistryConfig)12 RequestBase (com.alipay.sofa.rpc.core.request.RequestBase)12 MethodConfig (com.alipay.sofa.rpc.config.MethodConfig)10 ProviderInfo (com.alipay.sofa.rpc.client.ProviderInfo)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 ConsumerBootstrap (com.alipay.sofa.rpc.bootstrap.ConsumerBootstrap)8 SofaTimeOutException (com.alipay.sofa.rpc.core.exception.SofaTimeOutException)8