【Curator NodeCache 源码解析】

NodeCache

  1. NodeCache在new对象时候会调用client.newWatcherRemoveCuratorFramework去新建一个监听客户端。
  /**
     * @param client curztor client
     * @param path the full path to the node to cache
     * @param dataIsCompressed if true, data in the path is compressed
     */
    public NodeCache(CuratorFramework client, String path, boolean dataIsCompressed)
    {
   
        this.client = client.newWatcherRemoveCuratorFramework();
        this.path = PathUtils.validatePath(path);
        this.dataIsCompressed = dataIsCompressed;
    }

  1. start() 启动缓存服务
 public void     start(boolean buildInitial) throws Exception
    {
   
      //设值启动状态
       Preconditions.checkState(state.compareAndSet(State.LATENT,              State.STARTED), "Cannot be started more than once");

      //增加连接状态监听 client.getConnectionStateListenable().addListener(connectionStateListener);
    // 进行初始化操作
        if ( buildInitial )
        {
   
            client.checkExists().creatingParentContainersIfNeeded().forPath(path);
            internalRebuild();
        }
        reset();
    }
    // 判断是否是启动连接状态,判断节点是否存在
   private void     reset() throws Exception
    {
   
        if ( (state.get
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值