本文整理匯總了Java中org.apache.curator.retry.ExponentialBackoffRetry類的典型用法代碼示例。如果您正苦於以下問題:Java ExponentialBackoffRetry類的具體用法?Java ExponentialBackoffRetry怎麽用?Java ExponentialBackoffRetry使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ExponentialBackoffRetry類屬於org.apache.curator.retry包,在下文中一共展示了ExponentialBackoffRetry類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setUp
import org.apache.curator.retry.ExponentialBackoffRetry; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
zookeeper = new ZooKeeper("127.0.0.1:2181", 10000, event -> {
if (event.getState() == Watcher.Event.KeeperState.SyncConnected) {
System.out.println("Zookeeper connected.");
} else {
throw new RuntimeException("Error connecting to zookeeper");
}
latch.countDown();
});
latch.await();
CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient("127.0.0.1:2181", new ExponentialBackoffRetry(1000, 3));
curatorFramework.start();
AsyncCuratorFramework asyncCuratorFramework = AsyncCuratorFramework.wrap(curatorFramework);
logInfoStorage = new LogInfoStorageImpl(asyncCuratorFramework);
}
示例2: get
import org.apache.curator.retry.ExponentialBackoffRetry; //導入依賴的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;
}
示例3: buildConnection
import org.apache.curator.retry.ExponentialBackoffRetry; //導入依賴的package包/類
private static CuratorFramework buildConnection(String url) {
CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient(url, new ExponentialBackoffRetry(100, 6));
// start connection
curatorFramework.start();
// wait 3 second to establish connect
try {
curatorFramework.blockUntilConnected(3, TimeUnit.SECONDS);
if (curatorFramework.getZookeeperClient().isConnected()) {
return curatorFramework.usingNamespace("");
}
} catch (InterruptedException ignored) {
Thread.currentThread().interrupt();
}
// fail situation
curatorFramework.close();
throw new RuntimeException("failed to connect to zookeeper service : " + url);
}
示例4: SingularityCuratorProvider
import org.apache.curator.retry.ExponentialBackoffRetry; //導入依賴的package包/類
@Inject
public SingularityCuratorProvider(final SingularityConfiguration configuration, final Set<ConnectionStateListener> connectionStateListeners) {
checkNotNull(configuration, "configuration is null");
checkNotNull(connectionStateListeners, "connectionStateListeners is null");
ZooKeeperConfiguration zookeeperConfig = configuration.getZooKeeperConfiguration();
this.curatorFramework = CuratorFrameworkFactory.builder()
.defaultData(null)
.sessionTimeoutMs(zookeeperConfig.getSessionTimeoutMillis())
.connectionTimeoutMs(zookeeperConfig.getConnectTimeoutMillis())
.connectString(zookeeperConfig.getQuorum())
.retryPolicy(new ExponentialBackoffRetry(zookeeperConfig.getRetryBaseSleepTimeMilliseconds(), zookeeperConfig.getRetryMaxTries()))
.namespace(zookeeperConfig.getZkNamespace()).build();
for (ConnectionStateListener connectionStateListener : connectionStateListeners) {
curatorFramework.getConnectionStateListenable().addListener(connectionStateListener);
}
}
示例5: run
import org.apache.curator.retry.ExponentialBackoffRetry; //導入依賴的package包/類
@Override
public void run(String... strings) throws Exception {
client = CuratorFrameworkFactory.newClient(zookeeperConnString,
new ExponentialBackoffRetry(1000, Integer.MAX_VALUE));
client.start();
client.getZookeeperClient().blockUntilConnectedOrTimedOut();
leaderLatch = new LeaderLatch(client, "/http-job-scheduler/leader",
ManagementFactory.getRuntimeMXBean().getName());
leaderLatch.addListener(new LeaderLatchListener() {
@Override
public void isLeader() {
setMaster(true);
masterJobScheduler.resume();
}
@Override
public void notLeader() {
setMaster(false);
masterJobScheduler.pause();
}
});
leaderLatch.start();
}
示例6: setUp
import org.apache.curator.retry.ExponentialBackoffRetry; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
Configurator
.initialize("FastMQ", Thread.currentThread().getContextClassLoader(), "log4j2.xml");
Log log = new Log();
LogSegment logSegment = new LogSegment();
logSegment.setLedgerId(ledgerId);
logSegment.setTimestamp(System.currentTimeMillis());
log.setSegments(Collections.singletonList(logSegment));
when(logInfoStorage.getLogInfo(any())).thenReturn(log);
CuratorFramework curatorFramework = CuratorFrameworkFactory
.newClient("127.0.0.1:2181", new ExponentialBackoffRetry(1000, 3));
curatorFramework.start();
asyncCuratorFramework = AsyncCuratorFramework.wrap(curatorFramework);
offsetStorage = new ZkOffsetStorageImpl(logInfoStorage, asyncCuratorFramework);
}
示例7: CuratorUtils
import org.apache.curator.retry.ExponentialBackoffRetry; //導入依賴的package包/類
public CuratorUtils(String connectString, Host host) {
this.host = host;
client = CuratorFrameworkFactory.builder()
.connectString(connectString)
.sessionTimeoutMs(10000)
.connectionTimeoutMs(10000)
.retryPolicy(new ExponentialBackoffRetry(1000, 3))
.build();
client.start();
try {
path = generatePath();
if (null == path) {
log.error("init curator failed due to path is null!");
throw new DriverException("init curator failed due to path is null, servie will down");
}
} catch (Exception e) {
log.error("CuratorUtils construct failed, service will down!");
client.close();
System.exit(-1);
}
}
示例8: get
import org.apache.curator.retry.ExponentialBackoffRetry; //導入依賴的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;
}
示例9: createConnection
import org.apache.curator.retry.ExponentialBackoffRetry; //導入依賴的package包/類
private static CuratorFramework createConnection() {
String url= ZkConfig.getInstance().getZkURL();
CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient(url, new ExponentialBackoffRetry(100, 6));
// start connection
curatorFramework.start();
// wait 3 second to establish connect
try {
curatorFramework.blockUntilConnected(3, TimeUnit.SECONDS);
if (curatorFramework.getZookeeperClient().isConnected()) {
return curatorFramework;
}
} catch (InterruptedException ignored) {
Thread.currentThread().interrupt();
}
// fail situation
curatorFramework.close();
throw new RuntimeException("failed to connect to zookeeper service : " + url);
}
示例10: checkAndGetZK
import org.apache.curator.retry.ExponentialBackoffRetry; //導入依賴的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;
}
示例11: createConnection
import org.apache.curator.retry.ExponentialBackoffRetry; //導入依賴的package包/類
private static CuratorFramework createConnection() {
String url = ZkConfig.getInstance().getZkURL();
CuratorFramework framework = CuratorFrameworkFactory.newClient(url, new ExponentialBackoffRetry(100, 6));
// start connection
framework.start();
// wait 3 second to establish connect
try {
framework.blockUntilConnected(3, TimeUnit.SECONDS);
if (framework.getZookeeperClient().isConnected()) {
LOGGER.info("CuratorFramework createConnection success");
return framework;
}
} catch (InterruptedException ignored) {
LOGGER.info("CuratorFramework createConnection error", ignored);
Thread.currentThread().interrupt();
}
// fail situation
framework.close();
throw new RuntimeException("failed to connect to zookeeper service : " + url);
}
示例12: main
import org.apache.curator.retry.ExponentialBackoffRetry; //導入依賴的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;
}
});
}
示例13: CacheClusterViewer
import org.apache.curator.retry.ExponentialBackoffRetry; //導入依賴的package包/類
public CacheClusterViewer(Config config) throws RuntimeException {
try {
if (config == null) {
config = ConfigFactory.load();
}
this.zookeeperConnectionUrl = config.getString("zookeeper.connection_url");
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
zkClient = CuratorFrameworkFactory.newClient(zookeeperConnectionUrl, retryPolicy);
zkClient.start();
clusterGlobalLock = new InterProcessReadWriteLock(zkClient, Constants.CACHE_CLUSTER_PATH);
cacheCluster = doGetCacheClusterMeta();
monitorThread = new Thread(new ClusterStatusMonitor());
monitorThread.start();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例14: serviceInit
import org.apache.curator.retry.ExponentialBackoffRetry; //導入依賴的package包/類
@Override
protected void serviceInit(Configuration conf) throws Exception {
super.serviceInit(conf);
String zkConnectString = conf.get(ProxyConfig.MOUNT_TABLE_ZK_QUORUM);
zkMountTablePath = conf.get(ProxyConfig.MOUNT_TABLE_ZK_PATH);
int sessionTimeout = conf.getInt(ProxyConfig.MOUNT_TABLE_ZK_SESSION_TIMEOUT,
ProxyConfig.MOUNT_TABLE_ZK_SESSION_TIMEOUT_DEFAULT);
int connectionTimeout = conf.getInt(ProxyConfig.MOUNT_TABLE_ZK_CONNECTION_TIMEOUT,
ProxyConfig.MOUNT_TABLE_ZK_CONNECTION_TIMEOUT_DEFAULT);
int maxRetries = conf.getInt(ProxyConfig.MOUNT_TABLE_ZK_MAX_RETRIES,
ProxyConfig.MOUNT_TABLE_ZK_MAX_RETRIES_DEFAULT);
int retryBaseSleep = conf.getInt(ProxyConfig.MOUNT_TABLE_ZK_RETRY_BASE_SLEEP,
ProxyConfig.MOUNT_TABLE_ZK_RETRY_BASE_SLEEP_DEFAULT);
framework = CuratorFrameworkFactory.newClient(
zkConnectString, sessionTimeout, connectionTimeout,
new ExponentialBackoffRetry(retryBaseSleep, maxRetries));
installed = false;
}
示例15: getCurator
import org.apache.curator.retry.ExponentialBackoffRetry; //導入依賴的package包/類
/**
*
* method provide CuratorFramework object
*
* @param settings
* @return
*
*
*
*/
public static CuratorFramework getCurator(rrNvReadable settings) {
String Setting_ZkConfigDbServers =com.att.ajsc.filemonitor.AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, CambriaConstants.kSetting_ZkConfigDbServers);
if(null==Setting_ZkConfigDbServers)
Setting_ZkConfigDbServers =CambriaConstants.kDefault_ZkConfigDbServers;
String strSetting_ZkSessionTimeoutMs = com.att.ajsc.filemonitor.AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, CambriaConstants.kSetting_ZkSessionTimeoutMs);
if (strSetting_ZkSessionTimeoutMs==null) strSetting_ZkSessionTimeoutMs = CambriaConstants.kDefault_ZkSessionTimeoutMs+"";
int Setting_ZkSessionTimeoutMs = Integer.parseInt(strSetting_ZkSessionTimeoutMs);
String str_ZkConnectionTimeoutMs = com.att.ajsc.filemonitor.AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, CambriaConstants.kSetting_ZkSessionTimeoutMs);
if (str_ZkConnectionTimeoutMs==null) str_ZkConnectionTimeoutMs = CambriaConstants.kDefault_ZkConnectionTimeoutMs+"";
int setting_ZkConnectionTimeoutMs = Integer.parseInt(str_ZkConnectionTimeoutMs);
CuratorFramework curator = CuratorFrameworkFactory.newClient(
Setting_ZkConfigDbServers,Setting_ZkSessionTimeoutMs,setting_ZkConnectionTimeoutMs
,new ExponentialBackoffRetry(1000, 5));
return curator;
}