Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the function of DelegateConsistencyServiceImpl in nacos

Shulou Source: shulou.com Published: 2022-06-02 11:11:23 09月12日 Update

In this issue, the editor will bring you about the role of DelegateConsistencyServiceImpl in nacos. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

ConsistencyService

Nacos-1.1.3/naming/src/main/java/com/alibaba/nacos/naming/consistency/ConsistencyService.java

Public interface ConsistencyService {/ * * Put a data related to a key to Nacos cluster * * @ param key key of data, this key should be globally unique * @ param value value of data * @ throws NacosException * @ see * / void put (String key, Record value) throws NacosException / * Remove a data from Nacos cluster * * @ param key key of data * @ throws NacosException * / void remove (String key) throws NacosException; / * Get a data from Nacos cluster * * @ param key key of data * @ return data related to the key * @ throws NacosException * / Datum get (String key) throws NacosException / * Listen for changes of a data * * @ param key key of data * @ param listener callback of data change * @ throws NacosException * / void listen (String key, RecordListener listener) throws NacosException / * Cancel listening of a data * * @ param key key of data * @ param listener callback of data change * @ throws NacosException * / void unlisten (String key, RecordListener listener) throws NacosException; / * * Tell the status of this consistency service * * @ return true if available * / boolean isAvailable ();}

ConsistencyService defines put, remove, get, listen, unlisten, isAvailable methods

DelegateConsistencyServiceImpl

Nacos-1.1.3/naming/src/main/java/com/alibaba/nacos/naming/consistency/DelegateConsistencyServiceImpl.java

@ Service ("consistencyDelegate") public class DelegateConsistencyServiceImpl implements ConsistencyService {@ Autowired private PersistentConsistencyService persistentConsistencyService; @ Autowired private EphemeralConsistencyService ephemeralConsistencyService; @ Override public void put (String key, Record value) throws NacosException {mapConsistencyService (key) .put (key, value);} @ Override public void remove (String key) throws NacosException {mapConsistencyService (key) .remove (key);} @ Override public Datum get (String key) throws NacosException {return mapConsistencyService (key) .get (key) } @ Override public void listen (String key, RecordListener listener) throws NacosException {/ / this special key is listened by both: if (KeyBuilder.SERVICE_META_KEY_PREFIX.equals (key)) {persistentConsistencyService.listen (key, listener); ephemeralConsistencyService.listen (key, listener); return;} mapConsistencyService (key) .requests (key, listener) } @ Override public void unlisten (String key, RecordListener listener) throws NacosException {mapConsistencyService (key) .unchecked (key, listener);} @ Override public boolean isAvailable () {return ephemeralConsistencyService.isAvailable () & & persistentConsistencyService.isAvailable ();} private ConsistencyService mapConsistencyService (String key) {return KeyBuilder.matchEphemeralKey (key)? EphemeralConsistencyService: persistentConsistencyService;}}

DelegateConsistencyServiceImpl implements the ConsistencyService interface; mapConsistencyService is used inside its put, remove, get, listen and unlisten methods to determine whether to use ephemeralConsistencyService or persistentConsistencyService;. Its isAvailable method requires that both ephemeralConsistencyService and persistentConsistencyService are available.

Summary

ConsistencyService defines put, remove, get, listen, unlisten, isAvailable methods; DelegateConsistencyServiceImpl implements the ConsistencyService interface; mapConsistencyService is used inside its put, remove, get, listen and unlisten methods to determine whether to use ephemeralConsistencyService or persistentConsistencyService; and its isAvailable method requires ephemeralConsistencyService and persistentConsistencyService to be available

The above is what the role of DelegateConsistencyServiceImpl in nacos is shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Tags: Methods functions content interfaces analysis specialties small and medium-sized rich in content summary that is articles more knowledge articles industries perspectives information channels channels related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Docker Microsoft MariaDB Shulou Information