ZK

Zookeeper系列(二):Java API开发

喜夏-厌秋 提交于 2019-12-10 20:45:25
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> ZooKeeper还为客户端提供了Java API编程接口的方式。API接口主要是ZooKeeper类中的方法,下面列举几个常用的客户端操作的Java代码示例。 1、create 创建ZooKeeper路径节点,参数需提供路径名称和路径关联数据。对应create命令。 示例代码如下: ZooKeeper zk= new ZooKeeper("127.0.0.1",SESSION_TIME,this); zk.create("/test","Hello".getBytes(), null, CreateMode.PERSISTENT); 2、删除 删除路径,对应delete命令。 ZooKeeper zk= new ZooKeeper("127.0.0.1",SESSION_TIME,this); zk.delete("/test", -1); 3、getData 获取路径关联数据。对应get命令。 ZooKeeper zk= new ZooKeeper("127.0.0.1",SESSION_TIME,this); String data = zk.getData("/test", false,null); 4、setData 设置节点关联数据。对应set命令。 ZooKeeper zk= new

zk vs gwt zk too many requests

不打扰是莪最后的温柔 提交于 2019-12-10 19:39:24
问题 Hi I am trying to compare the performance of zk and gwt. In my comparision I cant write any javascript by myself if the framework itself converts some code into js its ok(like gwt) but I cant write js by myself On writing code in the above way for almost anything done on browser a request is sent to the server in ZK. Hence eventually if you compare the no of request sent by zk to server is too high as compared to gwt. i would like to ask the following. whose performance is better zk or gwt

ZK Disbale Div,Window,Layout Component?

淺唱寂寞╮ 提交于 2019-12-09 23:54:12
问题 I am using ZK Framework in my project i have plenty of other component inside a div or Window Component ,Can any one tell me how can i disable a Div or Window component in certain condition.As i checked there is no any disable attribute for these components. Any other way we can i disable a Div or Window otherwise i have to disable each component inside the Div or Window or Layout 回答1: Here a very easy way to disable all components that implement the Disable interface. @Wire("disable")

Zookeeper的选举机制原理及常用命令

两盒软妹~` 提交于 2019-12-09 20:28:24
三个核心选举原则: (1)Zookeeper集群中只有超过半数以上的服务器启动,集群才能正常工作; (2)在集群正常工作之前,myid小的服务器给myid大的服务器投票,直到集群正常工作,选出Leader; (3)选出Leader之后,之前的服务器状态由Looking改变为Following,以后的服务器都是Follower。 下面以一个简单的例子来说明整个选举的过程: 假设有五台服务器组成的Zookeeper集群,它们的id从1-5,同时它们都是最新启动的,也就是没有历史数据,在存放数据量这一点上,都是一样的。 假设这些服务器从id1-5,依序启动: 因为一共5台服务器,只有超过半数以上,即最少启动3台服务器,集群才能正常工作。 (1)服务器1启动,发起一次选举。 服务器1投自己一票。此时服务器1票数一票,不够半数以上(3票),选举无法完成; 服务器1状态保持为LOOKING; (2)服务器2启动,再发起一次选举。 服务器1和2分别投自己一票,此时服务器1发现服务器2的id比自己大,更改选票投给服务器2; 此时服务器1票数0票,服务器2票数2票,不够半数以上(3票),选举无法完成; 服务器1,2状态保持LOOKING; (3)服务器3启动,发起一次选举。 与上面过程一样,服务器1和2先投自己一票,然后因为服务器3id最大,两者更改选票投给为服务器3; 此次投票结果:服务器1为0票

simpleRpc解析-服务端

佐手、 提交于 2019-12-09 20:19:05
本文主要是对勇哥的simpleRpc进行了简单的剖析,用来学习rpc,加深对rpc的理解! 源码地址: http://git.oschina.net/huangyong/rpc 勇哥博客:https://my.oschina.net/huangyong/blog/361751 rpc(Remote Procedure Call)主要是将远程服务调用包装成为本地服务调用,使用起来比较直观。以前,项目中有使用过将定时任务模块剥离出来,单独部署,定时任务模块使用rmi调用主系统的服务,使用起来和rpc应该是类似。 首先是down下源码,部署在本地IDE,具体过程参见gitee介绍吧! 下面是eclipse的工程截图: 先试用下: 1:启动本地zk,使用默认配置(工程中的默认配置就是ZK的默认配置,基本不用改) 2:启动rpc-sample-server工程的RpcBootstrap.java 启动日志: start server connect zookeeper create address node: /registry/com.xxx.rpc.sample.api.HelloService-sample.hello2/address-0000000003 register service: com.xxx.rpc.sample.api.HelloService-sample

添加zookeeper到服务,并设置开机启动

╄→尐↘猪︶ㄣ 提交于 2019-12-09 10:40:50
一、先安装jdk jdk 路径为/usr/local/java 二、再安装zookeeper zk路径为/use/local/zookeeper 三、创建zookeeper脚本 cd /etc/rc.d/init.d/ vim zookeeper # 添加如下脚本 #!/bin/bash ZK_PATH=/usr/local/zookeeper export JAVA_HOME=/usr/local/java case $1 in start) sh $ZK_PATH/bin/zkServer.sh start;; stop) sh $ZK_PATH/bin/zkServer.sh stop;; status) sh $ZK_PATH/bin/zkServer.sh status;; restart) sh $ZK_PATH/bin/zkServer.sh restart;; *) echo "require start|stop|status|restart" ;; esac 保存 #将脚本注册为service chkconfig --add zookeeper # 查看 chkconfig --list 四、zk 操作 #启动 service zookeeper start #停止 service zookeeper stop #重新启动 service zookeeper

How to get browsed file path in java

こ雲淡風輕ζ 提交于 2019-12-08 13:56:01
问题 I want to get a browsed files path. i tried like it Object objUploadEvent = ctx.getTriggerEvent(); if (objUploadEvent != null && (objUploadEvent instanceof UploadEvent)) { upEvent = (UploadEvent) objUploadEvent; } if (upEvent != null) { Media media = upEvent.getMedia(); File file=new File(media.getName()); this.path = file.getAbsolutePath(); } But getAbsolutePath is giving path from eclipse. say if my file is in c://doc/abc then it should give path as c://doc/abc/myfile.txt Thanks 回答1: If you

使用Docker启动Kafka-Manager

只愿长相守 提交于 2019-12-07 23:26:00
Docker安装Kafka-Manager(docker-compose.yml) 前置条件 请先安装Docker 创建docker-compose.yml # Docker compose to have Zookeeper, Kafka, and Kafka Manager running for development. # Provided by @chris-zen zookeeper: image: confluent/zookeeper ports: - "2181:2181" kafka: image: wurstmeister/kafka:0.9.0.0-1 ports: - "9092:9092" links: - zookeeper:zk environment: - KAFKA_ADVERTISED_HOST_NAME - KAFKA_ADVERTISED_PORT=9092 - KAFKA_DELETE_TOPIC_ENABLE=true - KAFKA_LOG_RETENTION_HOURS=1 - KAFKA_MESSAGE_MAX_BYTES=10000000 - KAFKA_REPLICA_FETCH_MAX_BYTES=10000000 - KAFKA_GROUP_MAX_SESSION_TIMEOUT_MS=60000 - KAFKA_NUM

ZooKeeper分布式锁简单实践

拟墨画扇 提交于 2019-12-07 17:39:08
ZooKeeper分布式锁的实现原理 在分布式解决方案中,Zookeeper是一个分布式协调工具。当多个JVM客户端,同时在ZooKeeper上创建相同的一个临时节点,因为临时节点路径是保证唯一,只要谁能够创建节点成功,谁就能够获取到锁。没有创建成功节点,就会进行等待,当释放锁的时候,采用事件通知给客户端重新获取锁资源。如果请求超时直接返回给客户端超时,重新请求即可。 代码实现 为了更好的展现效果,我这里设置每个线程请求需要1s,请求超时时间为30s。 首先我们先写一个测试类,模拟多线程多客户端请求的情况: public class ZkLockTest implements Runnable { private ZkLock zkLock = new ZkDistributedLock(); public void run() { try { if (zkLock.getLock((long)30000,null)) { System.out.println("线程:" + Thread.currentThread().getName() + ",抢购成功:" + System.currentTimeMillis()); } else { System.out.println("线程:" + Thread.currentThread().getName() + "

Is it possible use @NotifyChange instead of BindUtils.postNotifyChange?

旧街凉风 提交于 2019-12-07 16:36:07
问题 I have one confusion use between @NotifyChange and BindUtils.postNotifyChange ,Why use this two event .Before i read this question In ZK Can we PostNotifyChange more than one variables . But i cant understand this question why use this more than one variable. Here's an example: @Command @NotifyChange({ "folderInfoList", "isDisabled", "selectedFolderInfo" }) public void refreshFolderInfo() { logger.debug("Refresh Icon selected"); if (isDirty()) { Messagebox.show(pageResourceBundle.getText("JS