本文整理汇总了Java中com.netflix.curator.retry.RetryNTimes类的典型用法代码示例。如果您正苦于以下问题:Java RetryNTimes类的具体用法?Java RetryNTimes怎么用?Java RetryNTimes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RetryNTimes类属于com.netflix.curator.retry包,在下文中一共展示了RetryNTimes类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createZookeeperConnection
import com.netflix.curator.retry.RetryNTimes; //导入依赖的package包/类
public static CuratorFramework createZookeeperConnection(String connectString,
int sessionTimeoutMs, int connectionTimeoutMs, ConnectionStateListener cnxnListener,
int retrycount, int retryWaitTime, long sessionId, byte[] sessionPwd) throws Exception {
RetryPolicy retryPolicy = new RetryNTimes(retrycount , retryWaitTime);
ZookeeperFactory factory = new ZooKeeperFactory(sessionId, sessionPwd);
CuratorFramework client = CuratorFrameworkFactory.builder().zookeeperFactory(factory)
.sessionTimeoutMs(sessionTimeoutMs)
.connectionTimeoutMs(connectionTimeoutMs)
.connectString(connectString).retryPolicy(retryPolicy).build();
client.getConnectionStateListenable().addListener(cnxnListener);
client.start();
return client;
}
示例2: ZkConnector
import com.netflix.curator.retry.RetryNTimes; //导入依赖的package包/类
public ZkConnector(String zkConnect, int zkConnectionTimeoutMs,
int zkSessionTimeoutMs, int retryTimes, int sleepMsBetweenRetries) {
curator = CuratorFrameworkFactory.newClient(zkConnect,
zkSessionTimeoutMs, zkConnectionTimeoutMs, new RetryNTimes(
retryTimes, sleepMsBetweenRetries));
curator.start();
curator.getConnectionStateListenable().addListener(
createConnectionStateListener());
boolean success = false;
try {
success = curator.getZookeeperClient()
.blockUntilConnectedOrTimedOut();
} catch (InterruptedException e) {
}
if (!success)
throw new RuntimeException(
"Fail to establish zookeeper connection.");
else
LOGGER.log(Level.INFO, "Zookeeper connection is established.");
}
示例3: createCurator
import com.netflix.curator.retry.RetryNTimes; //导入依赖的package包/类
private void createCurator() {
String resolvablcnxnstr = findDNSResolvableZkHosts(m_config.getZkConnect());
m_curator = CuratorFrameworkFactory.newClient(
resolvablcnxnstr,
m_config.getZkSessionTimeoutMs(),
m_config.getZkConnectionTimeoutMs(),
new RetryNTimes(m_config.getRetryTimes(), m_config
.getSleepMsBetweenRetries()));
m_curator.getConnectionStateListenable().addListener(
createConnectionStateListener());
m_curator.start();
boolean success = false;
try {
success = m_curator.getZookeeperClient()
.blockUntilConnectedOrTimedOut();
} catch (InterruptedException e) {
}
if (!success)
throw new RuntimeException(
"Fail to establish zookeeper connection.");
else {
if (LOGGER.isInfoEnabled())
LOGGER.info(
"Zookeeper connection is established.");
}
}
示例4: ThriftDirectoryClient
import com.netflix.curator.retry.RetryNTimes; //导入依赖的package包/类
public ThriftDirectoryClient(KeyStore keystore, Properties props) throws Exception {
// Extract Directory PSK
SIPHASH_PSK = SipHashInline.getKey(keystore.getKey(KeyStore.SIPHASH_DIRECTORY_PSK));
this.curatorFramework = CuratorFrameworkFactory.builder()
.connectionTimeoutMs(1000)
.retryPolicy(new RetryNTimes(10, 500))
.connectString(props.getProperty(Configuration.DIRECTORY_ZK_QUORUM))
.build();
this.curatorFramework.start();
if ("true".equals(props.getProperty(Configuration.DIRECTORY_STREAMING_NOPROXY))) {
this.noProxy = true;
} else {
this.noProxy = false;
}
ServiceDiscovery<Map> discovery = ServiceDiscoveryBuilder.builder(Map.class)
.basePath(props.getProperty(Configuration.DIRECTORY_ZK_ZNODE))
.client(curatorFramework)
.build();
discovery.start();
serviceCache = discovery.serviceCacheBuilder().name(Directory.DIRECTORY_SERVICE).build();
serviceCache.addListener(this);
serviceCache.start();
cacheChanged();
}
示例5: GeoDirectoryThriftClient
import com.netflix.curator.retry.RetryNTimes; //导入依赖的package包/类
public GeoDirectoryThriftClient(KeyStore keystore, Properties props) throws Exception {
if (!props.containsKey(Configuration.GEODIR_ZK_SERVICE_QUORUM) || !props.containsKey(Configuration.GEODIR_ZK_SERVICE_ZNODE)) {
curatorFramework = null;
serviceCache = null;
return;
}
curatorFramework = CuratorFrameworkFactory.builder()
.connectionTimeoutMs(1000)
.retryPolicy(new RetryNTimes(10, 500))
.connectString(props.getProperty(Configuration.GEODIR_ZK_SERVICE_QUORUM))
.build();
curatorFramework.start();
ServiceDiscovery<Map> discovery = ServiceDiscoveryBuilder.builder(Map.class)
.basePath(props.getProperty(Configuration.GEODIR_ZK_SERVICE_ZNODE))
.client(curatorFramework)
.build();
discovery.start();
serviceCache = discovery.serviceCacheBuilder().name(GeoDirectory.GEODIR_SERVICE).build();
serviceCache.addListener(this);
serviceCache.start();
cacheChanged();
}
示例6: build
import com.netflix.curator.retry.RetryNTimes; //导入依赖的package包/类
public IdGenerator build() {
RetryPolicy policy = new RetryNTimes(1, 100);
if (zkCounter == null) {
zkCounter = new DistributedAtomicLong(client, rootPath + "/" + counterName, policy);
}
return new ZKGenerator(zkCounter, seed, rootPath, counterName, maxIdsToFetch, maxAttempts);
}
示例7: main
import com.netflix.curator.retry.RetryNTimes; //导入依赖的package包/类
public static void main(String[] args) {
RetryPolicy policy = new RetryNTimes(1, 100);
CuratorFramework zkClient = CuratorFrameworkFactory.newClient("localhost:2181", 3000, 3000, policy);
zkClient.start();
IdGenerator zkGen = ZKGenerator.newBuilder(zkClient).setCounterName("mark_test").setMaxIdsToFetch(1000)
.setRootPath("/id_gen").build();
runGenerator(zkGen);
Jedis redisClient = new Jedis("localhost");;
IdGenerator redisGen = RedisGenerator.newBuilder(redisClient).setCounterName("alex_test").setMaxIdsToFetch(1000).build();
runGenerator(redisGen);
}
示例8: newCurator
import com.netflix.curator.retry.RetryNTimes; //导入依赖的package包/类
private CuratorFramework newCurator(Map stateConf) throws Exception {
Integer port = (Integer) stateConf.get(Config.TRANSACTIONAL_ZOOKEEPER_PORT);
String serverPorts = "";
for (String server : (List<String>) stateConf.get(Config.TRANSACTIONAL_ZOOKEEPER_SERVERS)) {
serverPorts = serverPorts + server + ":" + port + ",";
}
return CuratorFrameworkFactory.newClient(serverPorts,
Utils.getInt(stateConf.get(Config.STORM_ZOOKEEPER_SESSION_TIMEOUT)),
15000,
new RetryNTimes(Utils.getInt(stateConf.get(Config.STORM_ZOOKEEPER_RETRY_TIMES)),
Utils.getInt(stateConf.get(Config.STORM_ZOOKEEPER_RETRY_INTERVAL))));
}
示例9: DynamicBrokersReader
import com.netflix.curator.retry.RetryNTimes; //导入依赖的package包/类
public DynamicBrokersReader(Map conf, String zkStr, String zkPath, String topic) {
_zkPath = zkPath;
_topic = topic;
try {
_curator = CuratorFrameworkFactory.newClient(
zkStr,
Utils.getInt(conf.get(Config.STORM_ZOOKEEPER_SESSION_TIMEOUT)),
15000,
new RetryNTimes(Utils.getInt(conf.get(Config.STORM_ZOOKEEPER_RETRY_TIMES)),
Utils.getInt(conf.get(Config.STORM_ZOOKEEPER_RETRY_INTERVAL))));
_curator.start();
} catch (Exception ex) {
LOG.error("can't connect to zookeeper");
}
}
示例10: connect
import com.netflix.curator.retry.RetryNTimes; //导入依赖的package包/类
void connect(String zk, String broker, int port)
{
try {
consumer = new SimpleConsumer(broker, port, 1000, 1024*1024*10);
curator = CuratorFrameworkFactory.newClient(zk, 1000, 15000, new RetryNTimes(5, 2000));
curator.start();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例11: DynamicBrokersReader
import com.netflix.curator.retry.RetryNTimes; //导入依赖的package包/类
public DynamicBrokersReader(Map conf, String zkStr, String zkPath, String topic) {
_zkPath = zkPath;
_topic = topic;
_curator = CuratorFrameworkFactory.newClient(
zkStr,
Utils.getInt(conf.get(Config.STORM_ZOOKEEPER_SESSION_TIMEOUT)),
15000,
new RetryNTimes(Utils.getInt(conf.get(Config.STORM_ZOOKEEPER_RETRY_TIMES)),
Utils.getInt(conf.get(Config.STORM_ZOOKEEPER_RETRY_INTERVAL))));
_curator.start();
}
示例12: run
import com.netflix.curator.retry.RetryNTimes; //导入依赖的package包/类
@Override
public void run() {
//
// Initialize Curator
//
this.curatorFramework = CuratorFrameworkFactory.builder()
.connectionTimeoutMs(5000)
.retryPolicy(new RetryNTimes(10, 500))
.connectString(properties.getProperty(io.warp10.continuum.Configuration.PLASMA_BACKEND_SUBSCRIPTIONS_ZKCONNECT))
.build();
this.curatorFramework.start();
//
// Create a Path Cache
//
this.cache = new NodeCache(curatorFramework, properties.getProperty(io.warp10.continuum.Configuration.PLASMA_BACKEND_SUBSCRIPTIONS_ZNODE));
cache.getListenable().addListener(this);
try {
cache.start(true);
} catch (Exception e) {
e.printStackTrace();
}
//
// Endlessly update the subscriptions, at most once every second
//
while(true) {
try { Thread.sleep(1000L); } catch (InterruptedException ie) { }
boolean update = this.updateSubscriptions.getAndSet(false);
if (!update) {
continue;
}
subscriptionUpdate();
}
}
示例13: create
import com.netflix.curator.retry.RetryNTimes; //导入依赖的package包/类
public static MigdalorCuratorClientImpl create(String ZKConnect)
{
RetryPolicy retryPolicy = new RetryNTimes(RETRIES, SLEEP_MS_BETWEEN_RETRIES);
return new MigdalorCuratorClientImpl(CuratorFrameworkFactory.newClient(ZKConnect, retryPolicy));
}