1. 程式人生 > >Curator連線Zookeeper的策略

Curator連線Zookeeper的策略

Curator連線Zookeeper的五種策略:

 public CuratorOperator(){
        /*
        *
        * Curator連線Zookeeper的策略:ExponentialBackoffRetry
        * baseSleepTimeMs:初始sleep的時間
        * maxRetries:最大重試次數
        * maxSleepMs:最大重試時間
        *
        * */
//        RetryPolicy retryPolicy1 = new ExponentialBackoffRetry(1000,5);

        /*
        *
        * Curator連線Zookeeper的策略:RetryNTimes
        * n:重試次數
        * sleepMsBetweenRetries:每次重試間隔的時間
        * */
        RetryPolicy retryPolicy2 =new RetryNTimes(3,500);


        /*
        *
        * Curator連線Zookeeper的策略:retryPolicy
        * sleepMsBetweenRetry:每次重試間隔的時間
        * */
//        RetryPolicy retryPolicy3 = new RetryOneTime(500);

        /*
        * Curator連線Zookeeper的策略:RetryForever
        * 永遠重試,不推薦使用
        * */
//        RetryPolicy retryPolicy4 = new RetryForever(retryIntervalMs);

        /*
        *
        * Curator連線Zookeeper的策略:RetryUntilElapsed
        * maxElapsedTimeMs:最大重試時間
        * sleepMsBetweenRetries:每次重試間隔的時間
        * 重試時間超過maxElapsedTimeMs後,不在重試
        * */
        RetryPolicy retryPolicy5 = new RetryUntilElapsed(2000,3000);

        client = CuratorFrameworkFactory.builder()
                .connectString(zkServerPath)
                .sessionTimeoutMs(10000).retryPolicy(retryPolicy2)
                .namespace("workspace").build();
        client.start();

    }