当前位置: 首页 > news >正文

建个私人网站怎么做室内设计多少钱

建个私人网站怎么做,室内设计多少钱,方正集团网站是谁做的,昆明公司网站制作API ZooKeeper官方提供了Java API#xff0c;可以通过Java代码来连接zookeeper服务进行操作。可以连接、创建节点、获取节点数据、监听节点变化等操作#xff0c;具体有以下几个重要的类#xff1a; ZooKeeper#xff1a;ZooKeeper类是Java API的核心类#xff0c;用于与…API ZooKeeper官方提供了Java API可以通过Java代码来连接zookeeper服务进行操作。可以连接、创建节点、获取节点数据、监听节点变化等操作具体有以下几个重要的类 ZooKeeperZooKeeper类是Java API的核心类用于与ZooKeeper服务器建立连接并提供了一系列方法来操作ZooKeeper的节点。WatcherWatcher是ZooKeeper的一个回调接口当节点发生变化时会调用相应的方法进行通知。CreateModeCreateMode枚举类定义了节点的类型包括永久节点、临时节点、顺序节点和临时顺序节点。StatStat类表示节点的元数据信息比如修改版本、数据长度、子节点数量等。 添加依赖 dependencygroupIdorg.apache.zookeeper/groupIdartifactIdzookeeper/artifactIdversion3.7.2/version /dependency操作例子 String host localhost:2181; //建立连接 zooKeeper new ZooKeeper(host, 2000, null); String path /test; Watcher watcher new Watcher() {Overridepublic void process(WatchedEvent watchedEvent) {System.out.println(Node changed: watchedEvent.getPath());System.out.println(watchedEvent);} }; //获取节点状态 如果不存在返回null Stat stat zooKeeper.exists(path, false); if(null ! stat){System.out.println(stat.getCzxid()-stat.getAversion()); }//创建节点 包含版本、时间、数据长度等信息 zooKeeper.create(path,123.getBytes(),ZooDefs.Ids.OPEN_ACL_UNSAFE,CreateMode.PERSISTENT); //添加watcher zooKeeper.addWatch(path, watcher, AddWatchMode.PERSISTENT);//获取节点数据 byte[] data zooKeeper.getData(path, false, null); System.out.println(new String(data));zooKeeper.create(path/1,child1.getBytes(),ZooDefs.Ids.OPEN_ACL_UNSAFE,CreateMode.PERSISTENT); //获取子节点 ListString children zooKeeper.getChildren(path, false); System.out.println(childs size:children.size()); //删除子节点 zooKeeper.delete(path/1,-1); zooKeeper.close();zkClient zkClient封装了zookeeper的官方api简化了一些繁琐的操作并提供了一些额外的功能提高了开发效. 添加依赖 dependencygroupIdcom.101tec/groupIdartifactIdzkclient/artifactIdversion0.11/version /dependencyzkclient对节点数据的操作进行了序列化 这里先准备一个string类型的序列化类。需要实现ZkSerializer接口 public class ZkStringSerializer implements ZkSerializer {Overridepublic byte[] serialize(Object o) throws ZkMarshallingError {return String.valueOf(o).getBytes();}Overridepublic Object deserialize(byte[] bytes) throws ZkMarshallingError {return new String(bytes);} }基本操作 ZkClient zkClient new ZkClient(localhost:2181); //自定义序列化 否则报错 zkClient.setZkSerializer(new ZkStringSerializer()); String path /test; //判断节点是否存在 boolean exist zkClient.exists(path); System.out.println(exist); if(!exist){//创建节点zkClient.create(path,123, CreateMode.PERSISTENT); } //读取节点数据 System.out.println((String) zkClient.readData(path)); zkClient.writeData(path,456);//设置节点数据 System.out.println((String) zkClient.readData(path)); zkClient.delete(path);//删除节点zkClient.close();节点变化事件 String path /test; /*** 节点变化事件* 只监听节点增减不监听数据变化事件*/ zkClient.subscribeChildChanges(path, new IZkChildListener() {Overridepublic void handleChildChange(String parentPath, ListString children) throws Exception {System.out.println(节点parentPath发生变化);System.out.println(children);} }); //节点操作观察handleChildChange接收到对应事件 Thread.sleep(2000); zkClient.createPersistent(path); Thread.sleep(2000); zkClient.createPersistent(path/child1); Thread.sleep(2000); zkClient.writeData(path/child1,123); Thread.sleep(2000); zkClient.delete(path/child1); Thread.sleep(2000); zkClient.delete(path); Thread.sleep(100000);节点数据变化事件 String path /test;/*** 节点变化事件,只检测当前节点感知不到其子节点* 节点被删除或节点数据变化*/zkClient.subscribeDataChanges(path, new IZkDataListener() {Overridepublic void handleDataChange(String s, Object o) throws Exception {System.out.println(节点s数据变为:o);}Overridepublic void handleDataDeleted(String s) throws Exception {System.out.println(节点s删除);}});Thread.sleep(2000);zkClient.createPersistent(path);Thread.sleep(2000);zkClient.createPersistent(path/child1);Thread.sleep(2000);zkClient.delete(path/child1);Thread.sleep(2000);zkClient.writeData(path,123);Thread.sleep(2000);zkClient.delete(path);Thread.sleep(100000); }Curator curator是另一个java连接zookeeper类库。功能更加强大。提供了连接重试、分布式锁、选举、队列等多种实际场景的用例。这里先简单搞个使用例子。 添加依赖 dependencygroupIdorg.apache.curator/groupIdartifactIdcurator-framework/artifactIdversion5.1.0/version /dependencycurator-framework是基础的依赖一些特定的使用方式需要添加不同的依赖有curator-recipes、curator-x-discovery、curator-x-async等。 基本操作 //创建连接 CuratorFramework client CuratorFrameworkFactory.newClient(localhost:2181, new ExponentialBackoffRetry(1000, 3)); client.start(); String path /test; client.checkExists().forPath(path);//判断是否存在 client.create().forPath(path, 123.getBytes());//创建节点 byte[] data client.getData().forPath(path);//获取数据 System.out.println(new String(data)); client.setData().forPath(path, 456.getBytes());//设置数据 client.delete().forPath(path);//删除节点client.close();节点监听 CuratorFramework client CuratorFrameworkFactory.newClient(localhost:2181, new ExponentialBackoffRetry(1000, 3)); client.start(); String path /test; NodeCache nodeCache new NodeCache(client,path); //添加监听 nodeCache.getListenable().addListener(new NodeCacheListener() {Overridepublic void nodeChanged() throws Exception {ChildData data nodeCache.getCurrentData();if (data ! null) {System.out.println(Node changed: data.getPath() , value: new String(data.getData()));} else {System.out.println(Node deleted: nodeCache.getPath());}} }); nodeCache.start(); client.create().forPath(path); client.setData().forPath(path, 123.getBytes()); client.delete().forPath(path); client.close();这里NodeCache被标识Deprecated也不知道被什么方式代替了后面再研究。先简单使用。
http://www.dnsts.com.cn/news/85225.html

相关文章:

  • 医院网站怎么做那个外贸网站做的最好
  • 简历制作网站哪个好如何做网站广告图片
  • 建设网站的群wordpress pwshell
  • 上海金融网站制作网站制作公司好西安网站建设招标
  • 北京网站优化推广分析零基础做地方门户网站
  • 外贸网站推广方式dw建设网站的代码模板
  • 公司网站设计与实现的项目建议书网站建设员工分工
  • 国外搜索引擎网站辽宁建设工程信息网新平台
  • 广州网站网站建设页面设计尺寸
  • 企业网站建设经验分享忒低网站长怎么做
  • 川畅科技搜搜 网站设计那个视频网站好
  • 广州seo网站多少钱百度软件下载安装
  • 自动化系统网站建设首选公司做设计用的素材下载网站
  • 制作查询网站有没有建筑学做区位分析的网站
  • 网站改域名如何做百度优化最强大的wordpress
  • 做网站被捉定西市建设局网站
  • 福安市网站建设寻找哈尔滨网站建设
  • 山东省住房和城乡建设厅注册中心网站网页开发的基本流程是什么
  • 家装公司建设网站淄博网站建设公司三农
  • ireal 网站建设seo引擎优化是什
  • 兰州专业网站建设报价小程序怎么进入公众号
  • 长春网络营销网站网站设计规划报告
  • 宣讲网站建设网站 被黑
  • 鹤山做网站公司中国国音电商平台官网
  • 杭州智能模板建站河南做网站公司排名
  • 网站虚拟主机有什么用网页设计基础实训计划
  • 外贸营销型网站建设多少钱微信公众号登录平台官网
  • 网站关停怎么做河南网站推广优化公司哪家好
  • 超值高端网站设计wordpress建站 产品详情页
  • 哪里有网站制作建设wordpress美化底部