當前位置: 首頁>>代碼示例>>Java>>正文


Java CuratorFrameworkState.STARTED屬性代碼示例

本文整理匯總了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 + ").");
}
 
開發者ID:AsuraTeam,項目名稱:asura,代碼行數:31,代碼來源:ConfigPublisher.java

示例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.");
}
 
開發者ID:xiaolongzuo,項目名稱:niubi-job,代碼行數:18,代碼來源:MasterSlaveNode.java

示例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.");
}
 
開發者ID:xiaolongzuo,項目名稱:niubi-job,代碼行數:19,代碼來源:StandbyNode.java

示例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);
    }
  }
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:16,代碼來源:StateManager.java

示例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);
	}
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-zookeeper,代碼行數:20,代碼來源:ZookeeperHealthIndicator.java

示例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;
	}
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-cluster,代碼行數:21,代碼來源:LeaderInitiator.java

示例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));
  }
}
 
開發者ID:kijiproject,項目名稱:kiji-rest,代碼行數:25,代碼來源:ManagedKijiClient.java

示例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();
}
 
開發者ID:librato,項目名稱:rollout-java,代碼行數:17,代碼來源:RolloutZKClient.java

示例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!!");
    }
}
 
開發者ID:zhongmingmao,項目名稱:id_center,代碼行數:34,代碼來源:ZkManager.java

示例10: logout

/**
 * 關閉注冊
 */
@Override
public synchronized void logout() {
	CuratorFramework client = (CuratorFramework) regCenter.getRawClient();
	if (client.getState() == CuratorFrameworkState.STARTED) {
		// 移除注冊節點
		regCenter.remove(nodePath.getWorkerIdPath());
		// 關閉連接
		regCenter.close();
	}
}
 
開發者ID:imadcn,項目名稱:idworker,代碼行數:13,代碼來源:ZookeeperWorkerRegister.java

示例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 + ").");
}
 
開發者ID:AsuraTeam,項目名稱:asura,代碼行數:40,代碼來源:ConfigSubscriber.java

示例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();
    }
}
 
開發者ID:salesforce,項目名稱:storm-dynamic-spout,代碼行數:11,代碼來源:CuratorHelper.java

示例13: closeCurator

void closeCurator() {
    if (curatorFramework.getState() == CuratorFrameworkState.STARTED) {
        log.info("Closing curator");
        curatorFramework.close();
    }
    dataStoreSupport.shutdown();
}
 
開發者ID:Comcast,項目名稱:redirector,代碼行數:7,代碼來源:BaseOfflineIntegrationTest.java

示例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;
}
 
開發者ID:netboynb,項目名稱:coco,代碼行數:30,代碼來源:RegisterHolder.java

示例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);
        }
    }
}
 
開發者ID:apache,項目名稱:ignite,代碼行數:27,代碼來源:TcpDiscoveryZookeeperIpFinder.java


注:本文中的org.apache.curator.framework.imps.CuratorFrameworkState.STARTED屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。