当前位置: 首页>>代码示例>>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;未经允许,请勿转载。