zoukankan      html  css  js  c++  java
  • Zookeeper入门

     1 package cn.fansunion.zookeeper;
     2 import org.apache.zookeeper.CreateMode;
     3 import org.apache.zookeeper.ZooDefs.Ids;
     4 import org.apache.zookeeper.ZooKeeper;
     5   
     6 public class ZooKeeperTest {
     7   
     8     private static final int TIME_OUT = 3000;
     9     private static final String HOST = "localhost:2181";
    10     public static void main(String[] args) throws Exception{
    11  
    12  
    13         ZooKeeper zookeeper = new ZooKeeper(HOST, TIME_OUT, null);
    14         System.out.println("=========创建节点===========");
    15         if(zookeeper.exists("/test", false) == null)
    16         {
    17             zookeeper.create("/test", "znode1".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    18         }
    19         System.out.println("=============查看节点是否安装成功===============");
    20         System.out.println(new String(zookeeper.getData("/test", false, null)));
    21          
    22         System.out.println("=========修改节点的数据==========");
    23         String data = "zNode2";
    24         zookeeper.setData("/test", data.getBytes(), -1);
    25          
    26         System.out.println("========查看修改的节点是否成功=========");
    27         System.out.println(new String(zookeeper.getData("/test", false, null)));
    28          
    29         System.out.println("=======删除节点==========");
    30         zookeeper.delete("/test", -1);
    31          
    32         System.out.println("==========查看节点是否被删除============");
    33         System.out.println("节点状态:" + zookeeper.exists("/test", false));
    34          
    35         zookeeper.close();
    36     } 
    37 }
  • 相关阅读:
    Spring实现声明式事务
    Spring整合MyBatis
    Spring AOP
    代理模式
    Bean的作用域
    Spring的配置
    HQL题目记录以及解题思路--持续更新
    数仓学习之路一:数仓理论
    DBeaver连接Hive遇到的坑
    MySQL常见面试题
  • 原文地址:https://www.cnblogs.com/lnas01/p/5919430.html
Copyright © 2011-2022 走看看