本文整理汇总了Java中org.apache.curator.framework.CuratorFramework.getState方法的典型用法代码示例。如果您正苦于以下问题:Java CuratorFramework.getState方法的具体用法?Java CuratorFramework.getState怎么用?Java CuratorFramework.getState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.curator.framework.CuratorFramework
的用法示例。
在下文中一共展示了CuratorFramework.getState方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: TopicPartition
import org.apache.curator.framework.CuratorFramework; //导入方法依赖的package包/类
/**
* 在拉完全量后将此schema的kafka consumer的offset设置为最新
* @param dbSchema
*/
/*public void setKafkaOffsetToLargest(String targetTopic){
if(targetTopic==null)
return;
TopicPartition partition0 = new TopicPartition(targetTopic, 0);
KafkaConsumerContainer.getInstances().getConsumer(targetTopic).seekToEnd(Arrays.asList(partition0));
}*/
protected <T> T deserialize(String path, Class<T> clazz) throws Exception {
T packet = null;
CuratorFramework curator = CuratorContainer.getInstance().getCurator();
if (curator.getState() == CuratorFrameworkState.STOPPED) {
LOG.info("[EventContainer] CuratorFrameworkState:{}", CuratorFrameworkState.STOPPED.name());
} else {
byte[] bytes = curator.getData().forPath(path);
if (bytes != null && bytes.length != 0) {
packet = JsonUtil.fromJson(new String(bytes, Charset.forName("UTF-8")), clazz);
}
}
return packet;
}
示例2: logout
import org.apache.curator.framework.CuratorFramework; //导入方法依赖的package包/类
/**
* 关闭注册
*/
@Override
public synchronized void logout() {
CuratorFramework client = (CuratorFramework) regCenter.getRawClient();
if (client.getState() == CuratorFrameworkState.STARTED) {
// 移除注册节点
regCenter.remove(nodePath.getWorkerIdPath());
// 关闭连接
regCenter.close();
}
}
示例3: deserialize
import org.apache.curator.framework.CuratorFramework; //导入方法依赖的package包/类
protected <T> T deserialize(String path, Class<T> clazz) throws Exception {
T packet = null;
CuratorFramework curator = CuratorContainer.getInstance().getCurator();
if (curator.getState() == CuratorFrameworkState.STOPPED) {
LOG.info("[control-event] CuratorFrameworkState:{}", CuratorFrameworkState.STOPPED.name());
} else {
byte[] bytes = curator.getData().forPath(path);
if (bytes != null && bytes.length != 0) {
packet = JsonUtil.fromJson(new String(bytes, Charset.forName("UTF-8")), clazz);
}
}
return packet;
}
示例4: saveZk
import org.apache.curator.framework.CuratorFramework; //导入方法依赖的package包/类
protected void saveZk(String node, String packet) {
try {
CuratorFramework curator = CuratorContainer.getInstance().getCurator();
if (curator.getState() == CuratorFrameworkState.STOPPED) {
LOG.info("[control-event] CuratorFrameworkState:{}", CuratorFrameworkState.STOPPED.name());
} else {
curator.setData().forPath(node, packet.getBytes());
}
} catch (Exception e) {
LOG.error("[control-event] 报错znode: " + node + ",数据包:" + packet + "失败!", e);
}
}
示例5: saveZk
import org.apache.curator.framework.CuratorFramework; //导入方法依赖的package包/类
protected void saveZk(String node, String packet) {
try {
CuratorFramework curator = CuratorContainer.getInstance().getCurator();
if (curator.getState() == CuratorFrameworkState.STOPPED) {
LOG.info("[EventContainer] CuratorFrameworkState:{}", CuratorFrameworkState.STOPPED.name());
} else {
curator.setData().forPath(node, packet.getBytes());
}
} catch (Exception e) {
LOG.error("[control-event] 报错znode: " + node + ",数据包:" + packet + "失败!", e);
}
}