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);
}
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);
}
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;
}
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);
}
}
}
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);
}
}
}
Aggregations