當前位置: 首頁>>代碼示例>>Java>>正文


Java RetryPolicy類代碼示例

本文整理匯總了Java中org.apache.curator.RetryPolicy的典型用法代碼示例。如果您正苦於以下問題:Java RetryPolicy類的具體用法?Java RetryPolicy怎麽用?Java RetryPolicy使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


RetryPolicy類屬於org.apache.curator包,在下文中一共展示了RetryPolicy類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: get

import org.apache.curator.RetryPolicy; //導入依賴的package包/類
@Override
public CuratorFramework get() {
    String quorum = zookeeperConfig.getQuorum();
    String serviceDiscoveryPath = zookeeperConfig.getServiceDiscoveryPath();
    String connectionString = quorum + (serviceDiscoveryPath == null ? "" : serviceDiscoveryPath);

    RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);

    LOGGER.info("Initiating Curator connection to Zookeeper using: [{}]", connectionString);
    // Use chroot so all subsequent paths are below /stroom-services to avoid conflicts with hbase/zookeeper/kafka etc.
    CuratorFramework client = CuratorFrameworkFactory.newClient(connectionString, retryPolicy);
    client.start();

    try {
        //Ensure the chrooted path for stroom-services exists
        Stat stat = client.checkExists().forPath("/");
        if (stat == null) {
            LOGGER.info("Creating chroot-ed root node inside " + serviceDiscoveryPath);
            client.create().forPath("/");
        }
    } catch (Exception e) {
        throw new RuntimeException("Error connecting to zookeeper using connection String: " + connectionString, e);
    }
    return client;
}
 
開發者ID:gchq,項目名稱:stroom-stats,代碼行數:26,代碼來源:ServiceDiscoveryCuratorFrameworkProvider.java

示例2: get

import org.apache.curator.RetryPolicy; //導入依賴的package包/類
@Override
public CuratorFramework get() {
    String quorum = zookeeperConfig.getQuorum();
    String statsPath = zookeeperConfig.getPropertyServicePath();
    String connectionString = quorum + (statsPath == null ? "" : statsPath);

    RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);

    LOGGER.info("Initiating Curator connection to Zookeeper using: [{}]", connectionString);
    // Use chroot so all subsequent paths are below /stroom-stats to avoid conflicts with hbase/zookeeper/kafka etc.
    CuratorFramework client = CuratorFrameworkFactory.newClient(connectionString, retryPolicy);
    client.start();

    try {
        // Ensure the chrooted root path exists (i.e. /stroom-stats)
        Stat stat = client.checkExists().forPath("/");
        if (stat == null) {
            LOGGER.info("Creating chroot-ed root node inside " + statsPath);
            client.create().forPath("/");
        }
    } catch (Exception e) {
        throw new RuntimeException("Error connecting to zookeeper using connection String: " + connectionString, e);
    }
    return client;
}
 
開發者ID:gchq,項目名稱:stroom-stats,代碼行數:26,代碼來源:StroomPropertyServiceCuratorFrameworkProvider.java

示例3: checkAndGetZK

import org.apache.curator.RetryPolicy; //導入依賴的package包/類
/**
 * 檢查ZooKeeper的連接狀態和它的Znode目錄樹
 *
 * @param
 * @return
 */
public static CuratorFramework checkAndGetZK() {
    CuratorFramework client;
    try {
        RetryPolicy retryPolicy =
                new ExponentialBackoffRetry(configuration.ZK_RETRY_INTERVAL, configuration.ZK_RETRY_TIMES);
        client = CuratorFrameworkFactory
                .newClient(configuration.ZK_CONNECT_STRING
                        , configuration.ZK_SESSION_TIMEOUT, configuration.ZK_INIT_TIMEOUT, retryPolicy);
        client.start();
        client.checkExists().forPath(ZNodeStaticSetting.TASKS_PATH);
        client.checkExists().forPath(ZNodeStaticSetting.MANAGERS_PATH);
        client.checkExists().forPath(ZNodeStaticSetting.WORKERS_PATH);
        client.checkExists().forPath(ZNodeStaticSetting.FILTERS_ROOT);
    } catch (Throwable e) {
        client = null;
        logger.error(e.getMessage());
    }
    return client;
}
 
開發者ID:xiongbeer,項目名稱:Cobweb,代碼行數:26,代碼來源:SelfTest.java

示例4: curatorFramework

import org.apache.curator.RetryPolicy; //導入依賴的package包/類
@Bean(destroyMethod = "close")
@ConditionalOnMissingBean
public CuratorFramework curatorFramework(AlbedoRpcProperties albedoRpcProperties, RetryPolicy retryPolicy) throws InterruptedException {
    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
    String namespace = environment.getProperty("albedo.rpc.namespace", albedoRpcProperties.getNamespace());
    AlbedoRpcProperties.Zookeeper zookeeper = albedoRpcProperties.getZookeeper();
    String connectString = environment.getProperty("albedo.rpc.zookeeper.connectString", zookeeper.getConnectString());
    Integer blockUntilConnectedWait = Integer.parseInt(environment.getProperty("albedo.rpc.zookeeper.blockUntilConnectedWait",
            zookeeper.getBlockUntilConnectedWait()+""));
    logger.info("CuratorFramework namespace {}", namespace);
    CuratorFramework curator = builder
            .retryPolicy(retryPolicy)
            .canBeReadOnly(true)
            .namespace(namespace)
            .connectString(connectString)
            .defaultData(null)
            .build();
    curator.blockUntilConnected(blockUntilConnectedWait,
            TimeUnit.SECONDS);
    curator.start();
    return curator;
}
 
開發者ID:somewhereMrli,項目名稱:albedo-thrift,代碼行數:23,代碼來源:CommonAutoConfiguration.java

示例5: main

import org.apache.curator.RetryPolicy; //導入依賴的package包/類
public static void main(String[] args){
    RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
    CuratorFramework client = CuratorFrameworkFactory.newClient("127.0.0.1:2181", retryPolicy);
    client.start();

    final ZkDistributedLockTemplate template=new ZkDistributedLockTemplate(client);//本類多線程安全,可通過spring注入
    template.execute("訂單流水號", 5000, new Callback() {
        @Override
        public Object onGetLock() throws InterruptedException {
            //TODO 獲得鎖後要做的事
            return null;
        }

        @Override
        public Object onTimeout() throws InterruptedException {
            //TODO 獲得鎖超時後要做的事
            return null;
        }
    });
}
 
開發者ID:yujiasun,項目名稱:Distributed-Kit,代碼行數:21,代碼來源:ZkReentrantLockTemplateTest.java

示例6: initializeCurator

import org.apache.curator.RetryPolicy; //導入依賴的package包/類
private Completable initializeCurator()
{
    // Create/start CuratorFramework client
    RetryPolicy retryPolicy = new BoundedExponentialBackoffRetry(retryBaseTime, retryMaxTime, retryLimit);
    EnsembleProvider ensembleProvider = new FixedEnsembleProvider(connectionString);
    curator = CuratorFrameworkFactory.builder()
        .ensembleProvider(ensembleProvider)
        .retryPolicy(retryPolicy)
        .namespace(namespace)
        .sessionTimeoutMs(sessionTimeout)
        .connectionTimeoutMs(connectionTimeout)
        .build();
    curator.start();

    // Create a NodeCache for each config descriptor
    // This creates N node caches at a time on the RxJava IO scheduler thread pool.
    return Observable.from(configDescriptors)
        .flatMap(desc -> buildNodeCache(desc)
            .subscribeOn(Schedulers.io())
            .map(nc -> this.configNodeCaches.put(desc, nc)), getConcurrentNodeCacheCreations())
        .toCompletable();
}
 
開發者ID:kikinteractive,項目名稱:ice,代碼行數:23,代碼來源:ZooKeeperDynamicConfigSource.java

示例7: createProperties

import org.apache.curator.RetryPolicy; //導入依賴的package包/類
@Override
protected Properties createProperties() throws IOException {
	Properties prop = super.createProperties();
	if (zkLocation == null || "".equals(zkLocation))
		zkLocation = environment.getProperty(this.zkLocationEnvName);
	if (zkLocation == null) {
		logger.warn("ZK connection string env var does not exist, skip zk based configuration.");
		return prop;
	}
	try {
		RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
		CuratorFramework client = CuratorFrameworkFactory.newClient(zkLocation, retryPolicy);
		client.start();
		int count = CuratorUtils.loadToProperties(client, prop, "/");
		logger.info(String.format("Loaded %d properties from zookeeper.", count));
		client.close();
	} catch (Exception ex) {
		logger.warn("Failed to load configuration from ZK.", ex);
	}
	return prop;
}
 
開發者ID:NewTranx,項目名稱:newtranx-utils,代碼行數:22,代碼來源:ZkPropertiesFactoryBean.java

示例8: prepare

import org.apache.curator.RetryPolicy; //導入依賴的package包/類
@Override
public void prepare(Map map, Object conf, TopologyContext topologyContext, IErrorReporter iErrorReporter) {
    Map<String, Object> config = (Map<String, Object>) conf;
    RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
    client = CuratorFrameworkFactory.newClient(config.get("zookeeper").toString(), retryPolicy);
    client.start();


    try {
        if (client.checkExists().forPath("/consumers/rb-storm") == null) {
            client.create().creatingParentsIfNeeded().forPath("/consumers/rb-storm");
            System.out.println("Creating /consumers/rb-storm path ...");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}
 
開發者ID:redBorder,項目名稱:rb-bi,代碼行數:19,代碼來源:KafkaConsumerMonitorMetrics.java

示例9: ZookeeperCoordinator

import org.apache.curator.RetryPolicy; //導入依賴的package包/類
/**
 * Zookeeper-based Coordinator implementation.
 *
 * @param configuration Replicator configuration
 */
public ZookeeperCoordinator(Configuration configuration)  {
    this.configuration = configuration;
    this.checkPointPath = String.format("%s/checkpoint", configuration.getZookeeperPath());

    RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);

    String cluster = configuration.getZookeeperQuorum();

    client = CuratorFrameworkFactory.newClient(cluster, retryPolicy);
    client.start();

    try {
        client.createContainers(configuration.getZookeeperPath());
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(String.format(
            "Failed to create Zookeeper Coordinator container at path: %s (Because of: %s)",
            configuration.getZookeeperPath(),
            e.getMessage()
        ));
    }
}
 
開發者ID:mysql-time-machine,項目名稱:replicator,代碼行數:28,代碼來源:ZookeeperCoordinator.java

示例10: provideInitializedZookeeperClient

import org.apache.curator.RetryPolicy; //導入依賴的package包/類
private static CuratorFramework provideInitializedZookeeperClient(String zkConnection) throws Exception {

        LOG.info("Creating Zookeeper Client connecting to {}", zkConnection);

        RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
        CuratorFramework zkClient = CuratorFrameworkFactory
                .builder()
                .namespace(NAMESPACE)
                .connectString(zkConnection)
                .retryPolicy(retryPolicy).build();

        LOG.info("Connecting to ZK cluster {}", zkClient.getState());
        zkClient.start();
        zkClient.blockUntilConnected();
        LOG.info("Connection to ZK cluster {}", zkClient.getState());

        return zkClient;
    }
 
開發者ID:apache,項目名稱:incubator-omid,代碼行數:19,代碼來源:TestEndToEndScenariosWithHA.java

示例11: cleanUpZK

import org.apache.curator.RetryPolicy; //導入依賴的package包/類
private void cleanUpZK() {
    String[] pathsTobeCleaned = {"/pravega", "/hostIndex", "/store", "/taskIndex"};

    RetryPolicy rp = new ExponentialBackoffRetry(1000, 3);
    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder()
            .connectString(zkUrl)
            .connectionTimeoutMs(5000)
            .sessionTimeoutMs(5000)
            .retryPolicy(rp);
    @Cleanup
    CuratorFramework zclient = builder.build();
    zclient.start();
    for ( String path : pathsTobeCleaned ) {
        try {
            zclient.delete().guaranteed().deletingChildrenIfNeeded()
                    .forPath(path);
        } catch (Exception e) {
            log.warn("Not able to delete path {} . Exception {}", path, e.getMessage());
        }
    }
    zclient.close();
}
 
開發者ID:pravega,項目名稱:pravega,代碼行數:23,代碼來源:InProcPravegaCluster.java

示例12: wait

import org.apache.curator.RetryPolicy; //導入依賴的package包/類
@Override
public WaitResult wait(DockerFacade dockerClient, Container container) {
  return new PortWait().wait(ZOOKEEPER_PORT, dockerClient, container, (ipAddress, externalPort) -> {
    String zookeeperConnectionString = String.format("%s:%s", ipAddress, externalPort);
    RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
    CuratorFramework client = CuratorFrameworkFactory.newClient(zookeeperConnectionString, retryPolicy);
    client.start();
    try {
      client.blockUntilConnected();
      CuratorFrameworkState status = client.getState();
      if (!status.equals(CuratorFrameworkState.STARTED)) {
        return WaitResult.failure("Status [%s] does not match expected [STARTED]", status);
      }
      return WaitResult.success();
    } catch (InterruptedException e) {
      throw new RuntimeException("Could not connect to Zookeeper", e);
    } finally {
      client.close();
    }

  });
}
 
開發者ID:Qorr,項目名稱:Hvalspik,代碼行數:23,代碼來源:CuratorWait.java

示例13: Curator

import org.apache.curator.RetryPolicy; //導入依賴的package包/類
private Curator(String connectionSpec,
                String zooKeeperEnsembleConnectionSpec,
                Function<RetryPolicy, CuratorFramework> curatorFactory,
                RetryPolicy retryPolicy) {
    this.connectionSpec = connectionSpec;
    this.retryPolicy = retryPolicy;
    this.curatorFramework = curatorFactory.apply(retryPolicy);
    if (this.curatorFramework != null) {
        validateConnectionSpec(connectionSpec);
        validateConnectionSpec(zooKeeperEnsembleConnectionSpec);
        addFakeListener();
        curatorFramework.start();
    }

    this.zooKeeperEnsembleConnectionSpec = zooKeeperEnsembleConnectionSpec;
    this.zooKeeperEnsembleCount = zooKeeperEnsembleConnectionSpec.split(",").length;
}
 
開發者ID:vespa-engine,項目名稱:vespa,代碼行數:18,代碼來源:Curator.java

示例14: main

import org.apache.curator.RetryPolicy; //導入依賴的package包/類
public static void main(String[] args) {
	
	String connectString = "192.168.1.101:2181,192.168.1.102:2181,192.168.1.103:2181/conf/easycode/auth";
	CuratorFramework client = null;
	RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
	try {
		client = CuratorFrameworkFactory.newClient(connectString, retryPolicy);
		client.start();
		ZooKeeperTest test = new ZooKeeperTest(client);
		
		test.addCfgFile2LatentIoNode("", Envs.DEV, new String[] {
				"zk-test.properties"
		});
		
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		CloseableUtils.closeQuietly(client);
	}
}
 
開發者ID:easycodebox,項目名稱:easycode,代碼行數:21,代碼來源:ZooKeeperTest.java

示例15: ZookeeperOffsetHandler

import org.apache.curator.RetryPolicy; //導入依賴的package包/類
public ZookeeperOffsetHandler(Properties props) {
	this.groupId = props.getProperty(ConsumerConfig.GROUP_ID_CONFIG);
	if (this.groupId == null) {
		throw new IllegalArgumentException("Required property '"
				+ ConsumerConfig.GROUP_ID_CONFIG + "' has not been set");
	}

	String zkConnect = props.getProperty("zookeeper.connect");
	if (zkConnect == null) {
		throw new IllegalArgumentException("Required property 'zookeeper.connect' has not been set");
	}

	// we use Curator's default timeouts
	int sessionTimeoutMs =  Integer.valueOf(props.getProperty("zookeeper.session.timeout.ms", "60000"));
	int connectionTimeoutMs = Integer.valueOf(props.getProperty("zookeeper.connection.timeout.ms", "15000"));

	// undocumented config options allowing users to configure the retry policy. (they are "flink." prefixed as they are no official kafka configs)
	int backoffBaseSleepTime = Integer.valueOf(props.getProperty("flink.zookeeper.base-sleep-time.ms", "100"));
	int backoffMaxRetries =  Integer.valueOf(props.getProperty("flink.zookeeper.max-retries", "10"));

	RetryPolicy retryPolicy = new ExponentialBackoffRetry(backoffBaseSleepTime, backoffMaxRetries);
	curatorClient = CuratorFrameworkFactory.newClient(zkConnect, sessionTimeoutMs, connectionTimeoutMs, retryPolicy);
	curatorClient.start();
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:25,代碼來源:ZookeeperOffsetHandler.java


注:本文中的org.apache.curator.RetryPolicy類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。