本文整理匯總了Java中org.apache.curator.framework.imps.CuratorFrameworkState.STARTED屬性的典型用法代碼示例。如果您正苦於以下問題:Java CuratorFrameworkState.STARTED屬性的具體用法?Java CuratorFrameworkState.STARTED怎麽用?Java CuratorFrameworkState.STARTED使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.apache.curator.framework.imps.CuratorFrameworkState
的用法示例。
在下文中一共展示了CuratorFrameworkState.STARTED屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: init
/**
* 初始化
*
* @author zhangshaobin
* @created 2013-6-26 上午10:55:30
*/
private void init() {
applicationName = DynamicPropertyFactory.getInstance().getStringProperty(CommonConstant.CONFIG_APPLICATION_NAME_KEY, null).get();
String zkConfigEnsemble = DynamicPropertyFactory.getInstance().getStringProperty(CommonConstant.ZK_ENSEMABLE_KEY, null).get();
Integer zkConfigSessionTimeout = DynamicPropertyFactory.getInstance().getIntProperty(CommonConstant.ZK_SESSION_TIMEOUT_KEY, 15000).get();
Integer zkConfigConnTimeout = DynamicPropertyFactory.getInstance().getIntProperty(CommonConstant.ZK_CONN_TIMEOUT_KEY, 5000).get();
if (Check.NuNStr(zkConfigEnsemble)) {
logger.warn("ZooKeeper configuration running in file mode, zk is not enabled since not configured");
return;
}
try {
client = createAndStartZKClient(zkConfigEnsemble, zkConfigSessionTimeout, zkConfigConnTimeout);
if (client.getState() != CuratorFrameworkState.STARTED) {
throw new RuntimeException("ZooKeeper located at " + zkConfigEnsemble + " is not started.");
}
} catch (Exception e) {
e.printStackTrace();
logger.error("連接配置中心服務器超時,時間5000毫秒。", e.getCause());
System.exit(1);
}
System.out.println(new SimpleDateFormat("[yyyy-MM-dd HH:mm:ss] ").format(new Date()) + applicationName + " connected to cofnig server(" + zkConfigEnsemble + ").");
logger.info(applicationName + " connected to cofnig server(" + zkConfigEnsemble + ").");
}
示例2: relinquishLeadership
@Override
public void relinquishLeadership() {
try {
if (nodeCache != null) {
nodeCache.close();
}
LoggerHelper.info("node cache has been closed.");
} catch (Throwable e) {
LoggerHelper.warn("node cache close failed.", e);
}
if (client.getState() == CuratorFrameworkState.STARTED) {
MasterSlaveNodeData.Data nodeData = new MasterSlaveNodeData.Data(getNodeIp());
releaseJobs(nodePath, nodeData);
nodeData.setNodeState("Slave");
masterSlaveApiFactory.nodeApi().updateNode(nodePath, nodeData);
}
LoggerHelper.info("clear node successfully.");
}
示例3: relinquishLeadership
@Override
public void relinquishLeadership() {
try {
if (jobCache != null) {
jobCache.close();
}
LoggerHelper.info("job cache has been closed.");
} catch (Throwable e) {
LoggerHelper.warn("job cache close failed.", e);
}
LoggerHelper.info("begin stop scheduler manager.");
schedulerManager.shutdown();
if (client.getState() == CuratorFrameworkState.STARTED) {
StandbyNodeData.Data data = new StandbyNodeData.Data(getNodeIp());
standbyApiFactory.nodeApi().updateNode(nodePath, data);
LoggerHelper.info(getNodeIp() + " has been shutdown. [" + data + "]");
}
LoggerHelper.info("clear node successfully.");
}
示例4: save
public void save(SingularityHostState hostState) throws InterruptedException {
final String path = ZKPaths.makePath(ROOT_PATH, hostState.getHostname());
final byte[] data = hostStateTranscoder.toBytes(hostState);
if (curator.getState() == CuratorFrameworkState.STARTED) {
try {
if (exists(path)) {
curator.setData().forPath(path, data);
} else {
curator.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL).forPath(path, data);
}
} catch (Throwable t) {
throw Throwables.propagate(t);
}
}
}
示例5: doHealthCheck
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
try {
if (this.curator.getState() != CuratorFrameworkState.STARTED) {
builder.down().withDetail("error", "Client not started");
}
else if (this.curator.checkExists().forPath("/") == null) {
builder.down().withDetail("error", "Root for namespace does not exist");
}
else {
builder.up();
}
builder.withDetail("connectionString",
this.curator.getZookeeperClient().getCurrentConnectionString())
.withDetail("state", this.curator.getState());
}
catch (Exception e) {
builder.down(e);
}
}
示例6: start
/**
* Start the registration of the {@link #candidate} for leader election.
*/
@Override
public synchronized void start() {
if (!this.running) {
if (this.client.getState() != CuratorFrameworkState.STARTED) {
// we want to do curator start here because it needs to
// be started before leader selector and it gets a little
// complicated to control ordering via beans so that
// curator is fully started.
this.client.start();
}
this.leaderSelector = new LeaderSelector(this.client, buildLeaderPath(), new LeaderListener());
this.leaderSelector.setId(this.candidate.getId());
this.leaderSelector.autoRequeue();
this.leaderSelector.start();
this.running = true;
}
}
示例7: checkHealth
/**
* Check whether this KijiClient is healthy.
*
* @return health status of the KijiClient.
*/
public HealthCheck.Result checkHealth() {
final State state = mState.get();
Preconditions.checkState(state == State.STARTED,
"Can not check health while in state %s.", state);
List<String> issues = Lists.newArrayList();
if (mZKFramework.getState() != CuratorFrameworkState.STARTED) {
issues.add(String.format("ZooKeeper connection in unhealthy state %s.",
mZKFramework.getState()));
}
for (KijiInstanceCache instanceCache : mInstanceCaches.asMap().values()) {
issues.addAll(instanceCache.checkHealth());
}
if (issues.isEmpty()) {
return HealthCheck.Result.healthy();
} else {
return HealthCheck.Result.unhealthy(Joiner.on('\n').join(issues));
}
}
示例8: start
@Override
public void start() throws Exception {
if (!isStarted.compareAndSet(false, true)) {
throw new RuntimeException("Service already started!");
}
if (framework.getState() != CuratorFrameworkState.STARTED) {
throw new RuntimeException("CuratorFramework is not started!");
}
nodeCache.getListenable().addListener(new NodeCacheListener() {
@Override
public void nodeChanged() throws Exception {
build();
}
});
nodeCache.start(true);
build();
}
示例9: connect
/**
* 創建Zookeeper連接
*
* @throws InterruptedException
* @throws UnsupportedEncodingException
*/
@PostConstruct
public void connect() throws InterruptedException, UnsupportedEncodingException {
client = CuratorFrameworkFactory.builder()
.connectString(connectString)
.retryPolicy(new ExponentialBackoffRetry(DEFAULT_BASE_SLEEP_TIME_MS, DEFAULT_MAX_RETRIES))
.namespace(DEFAULT_NAMESPACE)
.authorization(DEFAULT_ACL_SCHEME, DEFAULT_ACL_AUTH.getBytes(DEFAULT_CHARSET)) // 設置權限
.aclProvider(new ACLProvider() { // 設置ACL規則
@Override
public List<ACL> getDefaultAcl() {
return DEFAULT_ACL_LIST;
}
@Override
public List<ACL> getAclForPath(String path) {
return DEFAULT_ACL_LIST;
}
})
.build();
if (CuratorFrameworkState.STARTED != client.getState()) {
client.start();
}
while (!client.blockUntilConnected(MAX_WAIT_SECONDS, TimeUnit.SECONDS)) {
log.info("can not connect to zookeeper , retry again!!");
}
}
示例10: logout
/**
* 關閉注冊
*/
@Override
public synchronized void logout() {
CuratorFramework client = (CuratorFramework) regCenter.getRawClient();
if (client.getState() == CuratorFrameworkState.STARTED) {
// 移除注冊節點
regCenter.remove(nodePath.getWorkerIdPath());
// 關閉連接
regCenter.close();
}
}
示例11: init
/**
* 初始化zk連接
*
* @author zhangshaobin
* @created 2013-6-26 上午10:21:34
*/
private void init() {
applicationName = DynamicPropertyFactory.getInstance().getStringProperty(CommonConstant.CONFIG_APPLICATION_NAME_KEY, null).get();
String zkConfigEnsemble = DynamicPropertyFactory.getInstance().getStringProperty(CommonConstant.ZK_ENSEMABLE_KEY, null).get();
Integer zkConfigSessionTimeout = DynamicPropertyFactory.getInstance().getIntProperty(CommonConstant.ZK_SESSION_TIMEOUT_KEY, 15000).get();
Integer zkConfigConnTimeout = DynamicPropertyFactory.getInstance().getIntProperty(CommonConstant.ZK_CONN_TIMEOUT_KEY, 5000).get();
Transaction tran = Cat.newTransaction("Asura Configuration init", applicationName + "_" + zkConfigEnsemble);
try {
if (Check.NuNStr(zkConfigEnsemble)) {
logger.warn("ZooKeeper configuration running in file mode, zk is not enabled since not configured");
Cat.logError("zk is not enabled since not configured", new RuntimeException("ZooKeeper located at " + zkConfigEnsemble + " is not started."));
return;
}
client = createAndStartZKClient(zkConfigEnsemble, zkConfigSessionTimeout, zkConfigConnTimeout);
if (client.getState() != CuratorFrameworkState.STARTED) {
throw new RuntimeException("ZooKeeper located at " + zkConfigEnsemble + " is not started.");
}
tran.setStatus(Transaction.SUCCESS);
} catch (Exception e) {
logger.error("連接配置中心服務器超時,時間5000毫秒。", e);
Cat.logError("asura configuration init exception", e);
tran.setStatus(e);
System.exit(1);
} finally {
tran.complete();
}
logger.info(new SimpleDateFormat("[yyyy-MM-dd HH:mm:ss] ").format(new Date()) + applicationName + " connected to cofnig server(" + zkConfigEnsemble + ").");
logger.info(applicationName + " connected to cofnig server(" + zkConfigEnsemble + ").");
}
示例12: ensureCuratorHasStarted
/**
* Quick check to ensure that Curator has been started.
*/
private void ensureCuratorHasStarted() {
// If our client isn't started yet
if (CuratorFrameworkState.STARTED != curator.getState()) {
// Lets start it!
logger.debug("Curator not started, starting it now!");
curator.start();
}
}
示例13: closeCurator
void closeCurator() {
if (curatorFramework.getState() == CuratorFrameworkState.STARTED) {
log.info("Closing curator");
curatorFramework.close();
}
dataStoreSupport.shutdown();
}
示例14: getClient
public static CuratorFramework getClient(String registerUrl) {
if (registerHolder == null) {
synchronized (RegisterHolder.class) {
if (registerHolder == null) {
registerHolder = new RegisterHolder();
curatorMap = Maps.newHashMap();
lock = new ReentrantLock();
}
}
}
CuratorFramework client = null;
lock.lock();
try {
String tempUrl = registerUrl.trim();
if (!curatorMap.containsKey(tempUrl)) {
ZkClientFactory zookeeperClientFactory = new ZkClientFactory().setAllAndGetClientFactory(tempUrl);
client = zookeeperClientFactory.newCuratorFramework();
CuratorFrameworkState state = client.getState();
if (state != CuratorFrameworkState.STARTED) {
client.start();
}
curatorMap.put(tempUrl, client);
} else {
client = curatorMap.get(tempUrl);
}
} finally {
lock.unlock();
}
return client;
}
示例15: unregisterAddresses
/** {@inheritDoc} */
@Override public void unregisterAddresses(Collection<InetSocketAddress> addrs) throws IgniteSpiException {
// if curator is not STARTED, we have nothing to unregister, because we are using ephemeral nodes,
// which means that our addresses will only be registered in ZK as long as our connection is alive
if (curator.getState() != CuratorFrameworkState.STARTED)
return;
if (log.isInfoEnabled())
log.info("Unregistering addresses with ZooKeeper IP Finder: " + addrs);
for (InetSocketAddress addr : addrs) {
ServiceInstance<IgniteInstanceDetails> si = ourInstances.get(addr);
if (si == null) {
log.warning("Asked to unregister address from ZooKeeper IP Finder, but no match was found in local " +
"instance map for: " + addrs);
continue;
}
try {
discovery.unregisterService(si);
}
catch (Exception e) {
log.warning("Error while unregistering an address from ZooKeeper IP Finder: " + addr, e);
}
}
}