您好,登錄后才能下訂單哦!
這期內容當中小編將會給大家帶來有關nacos中DelegateConsistencyServiceImpl的作用是什么,文章內容豐富且以專業的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
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定義了put、remove、get、listen、unlisten、isAvailable方法
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).listen(key, listener); } @Override public void unlisten(String key, RecordListener listener) throws NacosException { mapConsistencyService(key).unlisten(key, listener); } @Override public boolean isAvailable() { return ephemeralConsistencyService.isAvailable() && persistentConsistencyService.isAvailable(); } private ConsistencyService mapConsistencyService(String key) { return KeyBuilder.matchEphemeralKey(key) ? ephemeralConsistencyService : persistentConsistencyService; } }
DelegateConsistencyServiceImpl實現了ConsistencyService接口;其put、remove、get、listen、unlisten方法內部都使用了mapConsistencyService來判斷是使用ephemeralConsistencyService還persistentConsistencyService;其isAvailable方法要求ephemeralConsistencyService及persistentConsistencyService都是available
ConsistencyService定義了put、remove、get、listen、unlisten、isAvailable方法;DelegateConsistencyServiceImpl實現了ConsistencyService接口;其put、remove、get、listen、unlisten方法內部都使用了mapConsistencyService來判斷是使用ephemeralConsistencyService還persistentConsistencyService;其isAvailable方法要求ephemeralConsistencyService及persistentConsistencyService都是available
上述就是小編為大家分享的nacos中DelegateConsistencyServiceImpl的作用是什么了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關知識,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。