本文整理匯總了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
});
}
示例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();
}
示例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;
}
示例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();
}
}
示例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()
));
}
}
示例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;
}
示例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();
}
示例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();
}
});
}
示例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;
}
示例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);
}
}
示例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();
}