原来有两张表,一张是公司的,一张的产品的,项目中用来查询,不需要增删改。现在增删改交给另一项目去维护,由他们变更时同步数据到zk,我们去取。很明显,这里需要一个监听器,每次他项目发起数据变更时,我方必须能实时获取。

  先看测试场景:

  第一步先打开zk服务端,第二步打开zk客户端,第三步准备好要修改的数据并执行上面这个类,第四步通过zk客户端修改数据,观察控制台日志输出。具体输出日志如下:

  zk服务端:

D:\Dev\zookeeper-3.4.\bin>call "D:\Dev\Java\jdk1.8.0_102"\bin\java "-Dzookeeper.log.dir=D:\Dev\zookeeper-3.4.10\bin\.." "-Dzookeeper.root.logger=INFO,CONSOLE" -cp "D:\Dev\zookeeper-3.4.10\bin\..\build\classes;D:\Dev\zookeeper-3.4.10\bin\..\build\lib\*;D:\Dev\zookeeper-3.4.10\bin\..\*;D:\Dev\zookeeper-3.4.10\bin\..\lib\*;D:\Dev\zookeeper-3.4.10\bin\..\conf" org.apache.zookeeper.server.quorum.QuorumPeerMain "D:\Dev\zookeeper-3.4.10\bin\..\conf\zoo.cfg"
-- ::, [myid:] - INFO [main:QuorumPeerConfig@] - Reading configuration from: D:\Dev\zookeeper-3.4.\bin\..\conf\zoo.cfg
-- ::, [myid:] - INFO [main:DatadirCleanupManager@] - autopurge.snapRetainCount set to
-- ::, [myid:] - INFO [main:DatadirCleanupManager@] - autopurge.purgeInterval set to
-- ::, [myid:] - INFO [main:DatadirCleanupManager@] - Purge task is not scheduled.
-- ::, [myid:] - WARN [main:QuorumPeerMain@] - Either no config or no quorum defined in config, running in standalone mode
-- ::, [myid:] - INFO [main:QuorumPeerConfig@] - Reading configuration from: D:\Dev\zookeeper-3.4.\bin\..\conf\zoo.cfg
-- ::, [myid:] - INFO [main:ZooKeeperServerMain@] - Starting server
-- ::, [myid:] - INFO [main:Environment@] - Server environment:zookeeper.version=3.4.-39d3a4f269333c922ed3db283be479f9deacaa0f, built on // : GMT
-- ::, [myid:] - INFO [main:Environment@] - Server environment:host.name=windows10.microdone.cn
-- ::, [myid:] - INFO [main:Environment@] - Server environment:java.version=1.8.0_102
-- ::, [myid:] - INFO [main:Environment@] - Server environment:java.vendor=Oracle Corporation
-- ::, [myid:] - INFO [main:Environment@] - Server environment:java.home=D:\Dev\Java\jdk1..0_102\jre
-- ::, [myid:] - INFO [main:Environment@] - Server environment:java.class.path=D:\Dev\zookeeper-3.4.\bin\..\build\classes;D:\Dev\zookeeper-3.4.\bin\..\build\lib\*;D:\Dev\zookeeper-3.4.\bin\..\zookeeper-3.4..jar;D:\Dev\zookeeper-3.4.\bin\..\lib\jline-0.9..jar;D:\Dev\zookeeper-3.4.\bin\..\lib\log4j-1.2..jar;D:\Dev\zookeeper-3.4.\bin\..\lib\netty-3.10..Final.jar;D:\Dev\zookeeper-3.4.\bin\..\lib\slf4j-api-1.6..jar;D:\Dev\zookeeper-3.4.\bin\..\lib\slf4j-log4j12-1.6..jar;D:\Dev\zookeeper-3.4.\bin\..\conf
-- ::, [myid:] - INFO [main:Environment@] - Server environment:java.library.path=D:\Dev\Java\jdk1..0_102\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.\;C:\Windows\CCM;D:\Utility\TortoiseSVN\bin;D:\Utility\PuTTY\;D:\Dev\Java\jdk1..0_102\bin;D:\Dev\apache-maven-3.3.\bin;D:\Dev\apache-tomcat-9.0..M26\bin;D:\Dev\oracle\product\11.2.\dbhome_1\bin;C:\ProgramData\Oracle\Java\javapath;D:\Dev\oracle\instantclient_12_2;D:\Dev\nodejs\;C:\Program Files\MySQL\MySQL Utilities 1.6\;D:\Dev\Git\cmd;C:\WINDOWS\System32\OpenSSH\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\\Tools\Binn\;C:\Users\wulf\AppData\Local\Microsoft\WindowsApps;C:\Users\wulf\AppData\Roaming\npm;;D:\Utility\Fiddler;%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;.
-- ::, [myid:] - INFO [main:Environment@] - Server environment:java.io.tmpdir=C:\Users\wulf\AppData\Local\Temp\
-- ::, [myid:] - INFO [main:Environment@] - Server environment:java.compiler=<NA>
-- ::, [myid:] - INFO [main:Environment@] - Server environment:os.name=Windows
-- ::, [myid:] - INFO [main:Environment@] - Server environment:os.arch=amd64
-- ::, [myid:] - INFO [main:Environment@] - Server environment:os.version=10.0
-- ::, [myid:] - INFO [main:Environment@] - Server environment:user.name=wulf
-- ::, [myid:] - INFO [main:Environment@] - Server environment:user.home=C:\Users\wulf
-- ::, [myid:] - INFO [main:Environment@] - Server environment:user.dir=D:\Dev\zookeeper-3.4.\bin
-- ::, [myid:] - INFO [main:ZooKeeperServer@] - tickTime set to
-- ::, [myid:] - INFO [main:ZooKeeperServer@] - minSessionTimeout set to -
-- ::, [myid:] - INFO [main:ZooKeeperServer@] - maxSessionTimeout set to -
-- ::, [myid:] - INFO [main:NIOServerCnxnFactory@] - binding to port 0.0.0.0/0.0.0.0:
-- ::, [myid:] - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0::NIOServerCnxnFactory@] - Accepted socket connection from /::::::::
-- ::, [myid:] - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0::ZooKeeperServer@] - Client attempting to establish new session at /::::::::
-- ::, [myid:] - INFO [SyncThread::FileTxnLog@] - Creating new log file: log.6d
-- ::, [myid:] - INFO [SyncThread::ZooKeeperServer@] - Established session 0x165cd0f7f5b0000 with negotiated timeout for client /::::::::
-- ::, [myid:] - INFO [SessionTracker:ZooKeeperServer@] - Expiring session 0x165cd07fcca0000, timeout of 30000ms exceeded
-- ::, [myid:] - INFO [ProcessThread(sid: cport:)::PrepRequestProcessor@] - Processed session termination for sessionid: 0x165cd07fcca0000
-- ::, [myid:] - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0::NIOServerCnxnFactory@] - Accepted socket connection from /127.0.0.1:
-- ::, [myid:] - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0::ZooKeeperServer@] - Client attempting to establish new session at /127.0.0.1:
-- ::, [myid:] - INFO [SyncThread::ZooKeeperServer@] - Established session 0x165cd0f7f5b0001 with negotiated timeout for client /127.0.0.1:
-- ::, [myid:] - WARN [NIOServerCxn.Factory:0.0.0.0/0.0.0.0::NIOServerCnxn@] - Exception causing close of session 0x165cd0f7f5b0000 due to java.io.IOException: 远程主机强迫关闭了一个现有的连接。
-- ::, [myid:] - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0::NIOServerCnxn@] - Closed socket connection for client /:::::::: which had sessionid 0x165cd0f7f5b0000
-- ::, [myid:] - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0::NIOServerCnxnFactory@] - Accepted socket connection from /::::::::
-- ::, [myid:] - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0::ZooKeeperServer@] - Client attempting to establish new session at /::::::::
-- ::, [myid:] - INFO [SyncThread::ZooKeeperServer@] - Established session 0x165cd0f7f5b0002 with negotiated timeout for client /::::::::
-- ::, [myid:] - INFO [SessionTracker:ZooKeeperServer@] - Expiring session 0x165cd0f7f5b0000, timeout of 30000ms exceeded
-- ::, [myid:] - INFO [ProcessThread(sid: cport:)::PrepRequestProcessor@] - Processed session termination for sessionid: 0x165cd0f7f5b0000
-- ::, [myid:] - WARN [NIOServerCxn.Factory:0.0.0.0/0.0.0.0::NIOServerCnxn@] - Exception causing close of session 0x165cd0f7f5b0001 due to java.io.IOException: 远程主机强迫关闭了一个现有的连接。
-- ::, [myid:] - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0::NIOServerCnxn@] - Closed socket connection for client /127.0.0.1: which had sessionid 0x165cd0f7f5b0001
-- ::, [myid:] - INFO [SessionTracker:ZooKeeperServer@] - Expiring session 0x165cd0f7f5b0001, timeout of 4000ms exceeded
-- ::, [myid:] - INFO [ProcessThread(sid: cport:)::PrepRequestProcessor@] - Processed session termination for sessionid: 0x165cd0f7f5b0001

  zk客户端:

Connecting to localhost:
-- ::, [myid:] - INFO [main:Environment@] - Client environment:zookeeper.version=3.4.-39d3a4f269333c922ed3db283be479f9deacaa0f, built on // : GMT
-- ::, [myid:] - INFO [main:Environment@] - Client environment:host.name=windows10.microdone.cn
-- ::, [myid:] - INFO [main:Environment@] - Client environment:java.version=1.8.0_102
-- ::, [myid:] - INFO [main:Environment@] - Client environment:java.vendor=Oracle Corporation
-- ::, [myid:] - INFO [main:Environment@] - Client environment:java.home=D:\Dev\Java\jdk1..0_102\jre
-- ::, [myid:] - INFO [main:Environment@] - Client environment:java.class.path=D:\Dev\zookeeper-3.4.\bin\..\build\classes;D:\Dev\zookeeper-3.4.\bin\..\build\lib\*;D:\Dev\zookeeper-3.4.\bin\..\zookeeper-3.4..jar;D:\Dev\zookeeper-3.4.\bin\..\lib\jline-0.9..jar;D:\Dev\zookeeper-3.4.\bin\..\lib\log4j-1.2..jar;D:\Dev\zookeeper-3.4.\bin\..\lib\netty-3.10..Final.jar;D:\Dev\zookeeper-3.4.\bin\..\lib\slf4j-api-1.6..jar;D:\Dev\zookeeper-3.4.\bin\..\lib\slf4j-log4j12-1.6..jar;D:\Dev\zookeeper-3.4.\bin\..\conf
-- ::, [myid:] - INFO [main:Environment@] - Client environment:java.library.path=D:\Dev\Java\jdk1..0_102\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.\;C:\Windows\CCM;D:\Utility\TortoiseSVN\bin;D:\Utility\PuTTY\;D:\Dev\Java\jdk1..0_102\bin;D:\Dev\apache-maven-3.3.\bin;D:\Dev\apache-tomcat-9.0..M26\bin;D:\Dev\oracle\product\11.2.\dbhome_1\bin;C:\ProgramData\Oracle\Java\javapath;D:\Dev\oracle\instantclient_12_2;D:\Dev\nodejs\;C:\Program Files\MySQL\MySQL Utilities 1.6\;D:\Dev\Git\cmd;C:\WINDOWS\System32\OpenSSH\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\\Tools\Binn\;C:\Users\wulf\AppData\Local\Microsoft\WindowsApps;C:\Users\wulf\AppData\Roaming\npm;;D:\Utility\Fiddler;%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;.
-- ::, [myid:] - INFO [main:Environment@] - Client environment:java.io.tmpdir=C:\Users\wulf\AppData\Local\Temp\
-- ::, [myid:] - INFO [main:Environment@] - Client environment:java.compiler=<NA>
-- ::, [myid:] - INFO [main:Environment@] - Client environment:os.name=Windows
-- ::, [myid:] - INFO [main:Environment@] - Client environment:os.arch=amd64
-- ::, [myid:] - INFO [main:Environment@] - Client environment:os.version=10.0
-- ::, [myid:] - INFO [main:Environment@] - Client environment:user.name=wulf
-- ::, [myid:] - INFO [main:Environment@] - Client environment:user.home=C:\Users\wulf
-- ::, [myid:] - INFO [main:Environment@] - Client environment:user.dir=D:\Dev\zookeeper-3.4.\bin
-- ::, [myid:] - INFO [main:ZooKeeper@] - Initiating client connection, connectString=localhost: sessionTimeout= watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@799f7e29
Welcome to ZooKeeper!
-- ::, [myid:] - INFO [main-SendThread(::::::::):ClientCnxn$SendThread@] - Opening socket connection to server :::::::/::::::::. Will not attempt to authenticate using SASL (unknown error)
-- ::, [myid:] - INFO [main-SendThread(::::::::):ClientCnxn$SendThread@] - Socket connection established to :::::::/::::::::, initiating session
JLine support is enabled
-- ::, [myid:] - INFO [main-SendThread(::::::::):ClientCnxn$SendThread@] - Session establishment complete on server :::::::/::::::::, sessionid = 0x165cd0f7f5b0002, negotiated timeout = WATCHER:: WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:(CONNECTED) ] get /config/wlf/accessCompany/
{"mchId":"","mchName":"C鍏徃","mchType":"","spId":"AAA","key":"BBB","remark":""}
cZxid = 0x73
ctime = Wed Sep :: CST
mZxid = 0x73
mtime = Wed Sep :: CST
pZxid = 0x73
cversion =
dataVersion =
aclVersion =
ephemeralOwner = 0x0
dataLength =
numChildren =
[zk: localhost:(CONNECTED) ] set /config/wlf/accessCompany/ {"mchId":"","mchName":"wlf????","mchType":"","spId":"wlf","key":"wlf","remark":""}
cZxid = 0x73
ctime = Wed Sep :: CST
mZxid = 0x7c
mtime = Wed Sep :: CST
pZxid = 0x73
cversion =
dataVersion =
aclVersion =
ephemeralOwner = 0x0
dataLength =
numChildren =
[zk: localhost:(CONNECTED) ]

  可以看到我们改的是/config/wlf/accessCompany/333333的mchName、mchType、spId和key的值。

  控制台输出:

ERROR StatusLogger Unable to locate appender "httpClient-log" for logger config "org.asynchttpclient"
[-- ::] DEBUG ZKUtils: - start connect zk, zk server:127.0.0.1:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/E:/Users/wulf/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.8/log4j-slf4j-impl-2.8.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/E:/Users/wulf/.m2/repository/org/slf4j/slf4j-log4j12/1.7./slf4j-log4j12-1.7..jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
[-- ::] INFO ZooKeeper: - Client environment:zookeeper.version=3.4.-2d71af4dbe22557fda74f9a9b4309b15a7487f03, built on // : GMT
[-- ::] INFO ZooKeeper: - Client environment:host.name=windows10.microdone.cn
[-- ::] INFO ZooKeeper: - Client environment:java.version=1.8.0_102
[-- ::] INFO ZooKeeper: - Client environment:java.vendor=Oracle Corporation
[-- ::] INFO ZooKeeper: - Client environment:java.home=D:\Dev\Java\jdk1..0_102\jre
[-- ::] INFO ZooKeeper: - Client environment:java.class.path=E:\workspace\Wireless-Router\test-pilling\target\classes;E:\Users\wulf\.m2\repository\org\springframework\spring-core\4.3..RELEASE\spring-core-4.3..RELEASE.jar;E:\Users\wulf\.m2\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;E:\Users\wulf\.m2\repository\org\springframework\spring-context-support\4.3..RELEASE\spring-context-support-4.3..RELEASE.jar;E:\Users\wulf\.m2\repository\org\springframework\spring-beans\4.3..RELEASE\spring-beans-4.3..RELEASE.jar;E:\Users\wulf\.m2\repository\org\springframework\spring-context\4.3..RELEASE\spring-context-4.3..RELEASE.jar;E:\Users\wulf\.m2\repository\org\springframework\spring-aop\4.3..RELEASE\spring-aop-4.3..RELEASE.jar;E:\Users\wulf\.m2\repository\org\springframework\spring-expression\4.3..RELEASE\spring-expression-4.3..RELEASE.jar;E:\Users\wulf\.m2\repository\org\springframework\spring-web\4.3..RELEASE\spring-web-4.3..RELEASE.jar;E:\Users\wulf\.m2\repository\org\springframework\spring-webmvc\4.3..RELEASE\spring-webmvc-4.3..RELEASE.jar;E:\Users\wulf\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.8.\jackson-annotations-2.8..jar;E:\Users\wulf\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.8.\jackson-core-2.8..jar;E:\Users\wulf\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.8.\jackson-databind-2.8..jar;E:\Users\wulf\.m2\repository\org\apache\logging\log4j\log4j-api\2.8\log4j-api-2.8.jar;E:\Users\wulf\.m2\repository\org\apache\logging\log4j\log4j-core\2.8\log4j-core-2.8.jar;E:\Users\wulf\.m2\repository\org\apache\logging\log4j\log4j-slf4j-impl\2.8\log4j-slf4j-impl-2.8.jar;E:\Users\wulf\.m2\repository\org\apache\logging\log4j\log4j-web\2.8\log4j-web-2.8.jar;E:\Users\wulf\.m2\repository\org\slf4j\slf4j-api\1.7.\slf4j-api-1.7..jar;E:\Users\wulf\.m2\repository\org\apache\velocity\velocity\1.7\velocity-1.7.jar;E:\Users\wulf\.m2\repository\commons-collections\commons-collections\3.2.\commons-collections-3.2..jar;E:\Users\wulf\.m2\repository\org\apache\velocity\velocity-tools\2.0\velocity-tools-2.0.jar;E:\Users\wulf\.m2\repository\commons-beanutils\commons-beanutils\1.7.\commons-beanutils-1.7..jar;E:\Users\wulf\.m2\repository\commons-digester\commons-digester\1.8\commons-digester-1.8.jar;E:\Users\wulf\.m2\repository\commons-chain\commons-chain\1.1\commons-chain-1.1.jar;E:\Users\wulf\.m2\repository\commons-validator\commons-validator\1.3.\commons-validator-1.3..jar;E:\Users\wulf\.m2\repository\dom4j\dom4j\1.1\dom4j-1.1.jar;E:\Users\wulf\.m2\repository\oro\oro\2.0.\oro-2.0..jar;E:\Users\wulf\.m2\repository\sslext\sslext\1.2-\sslext-1.2-.jar;E:\Users\wulf\.m2\repository\org\apache\struts\struts-core\1.3.\struts-core-1.3..jar;E:\Users\wulf\.m2\repository\antlr\antlr\2.7.\antlr-2.7..jar;E:\Users\wulf\.m2\repository\org\apache\struts\struts-taglib\1.3.\struts-taglib-1.3..jar;E:\Users\wulf\.m2\repository\org\apache\struts\struts-tiles\1.3.\struts-tiles-1.3..jar;E:\Users\wulf\.m2\repository\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;E:\Users\wulf\.m2\repository\org\apache\zookeeper\zookeeper\3.4.\zookeeper-3.4..jar;E:\Users\wulf\.m2\repository\org\slf4j\slf4j-log4j12\1.7.\slf4j-log4j12-1.7..jar;E:\Users\wulf\.m2\repository\log4j\log4j\1.2.\log4j-1.2..jar;E:\Users\wulf\.m2\repository\jline\jline\0.9.\jline-0.9..jar;E:\Users\wulf\.m2\repository\org\apache\yetus\audience-annotations\0.5.\audience-annotations-0.5..jar;E:\Users\wulf\.m2\repository\io\netty\netty\3.10..Final\netty-3.10..Final.jar;E:\Users\wulf\.m2\repository\javax\servlet\javax.servlet-api\3.1.\javax.servlet-api-3.1..jar;E:\Users\wulf\.m2\repository\org\springframework\spring-test\4.3..RELEASE\spring-test-4.3..RELEASE.jar
[-- ::] INFO ZooKeeper: - Client environment:java.library.path=D:\Dev\Java\jdk1..0_102\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;D:/Dev/Java/jdk1..0_102/bin/../jre/bin/server;D:/Dev/Java/jdk1..0_102/bin/../jre/bin;D:/Dev/Java/jdk1..0_102/bin/../jre/lib/amd64;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.\;C:\Windows\CCM;D:\Utility\TortoiseSVN\bin;D:\Utility\PuTTY\;D:\Dev\Java\jdk1..0_102\bin;D:\Dev\apache-maven-3.3.\bin;D:\Dev\apache-tomcat-9.0..M26\bin;D:\Dev\oracle\product\11.2.\dbhome_1\bin;C:\ProgramData\Oracle\Java\javapath;D:\Dev\oracle\instantclient_12_2;D:\Dev\nodejs\;C:\Program Files\MySQL\MySQL Utilities 1.6\;D:\Dev\Git\cmd;C:\WINDOWS\System32\OpenSSH\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\\Tools\Binn\;C:\Users\wulf\AppData\Local\Microsoft\WindowsApps;C:\Users\wulf\AppData\Roaming\npm;;D:\Utility\Fiddler;%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;D:\Dev\eclipse;;.
[-- ::] INFO ZooKeeper: - Client environment:java.io.tmpdir=C:\Users\wulf\AppData\Local\Temp\
[-- ::] INFO ZooKeeper: - Client environment:java.compiler=<NA>
[-- ::] INFO ZooKeeper: - Client environment:os.name=Windows
[-- ::] INFO ZooKeeper: - Client environment:os.arch=amd64
[-- ::] INFO ZooKeeper: - Client environment:os.version=10.0
[-- ::] INFO ZooKeeper: - Client environment:user.name=wulf
[-- ::] INFO ZooKeeper: - Client environment:user.home=C:\Users\wulf
[-- ::] INFO ZooKeeper: - Client environment:user.dir=E:\workspace\Wireless-Router\test-pilling
[-- ::] INFO ZooKeeper: - Initiating client connection, connectString=127.0.0.1: sessionTimeout= watcher=com.wulinfeng.test.testpilling.util.ZKUtils$@52e6fdee
[-- ::] DEBUG ClientCnxn: - zookeeper.disableAutoWatchReset is false
[-- ::] INFO ClientCnxn: - Opening socket connection to server 127.0.0.1/127.0.0.1:. Will not attempt to authenticate using SASL (unknown error)
[-- ::] INFO ClientCnxn: - Socket connection established to 127.0.0.1/127.0.0.1:, initiating session
[-- ::] DEBUG ClientCnxn: - Session establishment request sent on 127.0.0.1/127.0.0.1:
[-- ::] INFO ClientCnxn: - Session establishment complete on server 127.0.0.1/127.0.0.1:, sessionid = 0x165cd0f7f5b0001, negotiated timeout =
[-- ::] INFO ZKUtils: - enter handleServiceAccessCompany...
[-- ::] INFO ZKUtils: - enter handelServiceAccessProduct...
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,,- request:: '/config/wlf,F response::
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,, request:: '/config,F response:: s{7,7,1536670545037,1536670545037,0,5,0,0,0,1,108}
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,,- request:: '/config/wlf,F response::
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,, request:: '/config/wlf,,v{s{31,s{'world,'anyone}}},0 response:: '/config/wlf
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,, request:: '/config/wlf/accessCompany,,v{s{31,s{'world,'anyone}}},0 response:: '/config/wlf/accessCompany
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,, request:: '/config/wlf,F response:: s{112,112,1536743702334,1536743702334,0,1,0,0,0,1,113}
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,,- request:: '/config/wlf/accessProduct,F response::
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,, request:: '/config/wlf/accessProduct,,v{s{31,s{'world,'anyone}}},0 response:: '/config/wlf/accessProduct
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,, request:: '/config/wlf/accessProduct,T response:: v{}
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,, request:: '/config/wlf/accessCompany,T response:: v{}
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,, request:: '/,F response:: v{'zk,'zookeeper,'config}
[-- ::] DEBUG ZKUtils: - zk server: [ 127.0.0.1: ]
zk path: [/] zk
zookeeper
config [-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,,- request:: '/config/wlf/accessCompany/333333,F response::
[-- ::] DEBUG ClientCnxn: - Got notification sessionid:0x165cd0f7f5b0001
[-- ::] DEBUG ClientCnxn: - Got WatchedEvent state:SyncConnected type:NodeChildrenChanged path:/config/wlf/accessCompany for sessionid 0x165cd0f7f5b0001
[-- ::] INFO ZKUtils: - enter handleServiceAccessCompany...
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,, request:: '/config/wlf/accessCompany/333333,#7b226d63684964223a22333333333333222c226d63684e616d65223a2243ffffffe5ffffff85ffffffacffffffe5ffffff8fffffffb8222c226d636854797065223a2231222c2273704964223a22414141222c226b6579223a22424242222c2272656d61726b223a22227d,v{s{31,s{'world,'anyone}}},0 response:: '/config/wlf/accessCompany/
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,, request:: '/config/wlf/accessCompany,T response:: v{'}
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,,- request:: '/config/wlf/accessCompany/111111,F response::
[-- ::] DEBUG ClientCnxn: - Got notification sessionid:0x165cd0f7f5b0001
[-- ::] DEBUG ClientCnxn: - Got WatchedEvent state:SyncConnected type:NodeChildrenChanged path:/config/wlf/accessCompany for sessionid 0x165cd0f7f5b0001
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,, request:: '/config/wlf/accessCompany/111111,#7b226d63684964223a22313131313131222c226d63684e616d65223a2241ffffffe5ffffff85ffffffacffffffe5ffffff8fffffffb8222c226d636854797065223a2231222c2273704964223a22414141222c226b6579223a22424242222c2272656d61726b223a22227d,v{s{31,s{'world,'anyone}}},0 response:: '/config/wlf/accessCompany/
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,,- request:: '/config/wlf/accessCompany/222222,F response::
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,, request:: '/config/wlf/accessCompany/222222,#7b226d63684964223a22323232323232222c226d63684e616d65223a2242ffffffe5ffffff85ffffffacffffffe5ffffff8fffffffb8222c226d636854797065223a2231222c2273704964223a22414141222c226b6579223a22424242222c2272656d61726b223a22227d,v{s{31,s{'world,'anyone}}},0 response:: '/config/wlf/accessCompany/
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,, request:: '/config/wlf/accessCompany/333333,T response:: #7b226d63684964223a22333333333333222c226d63684e616d65223a2243ffffffe5ffffff85ffffffacffffffe5ffffff8fffffffb8222c226d636854797065223a2231222c2273704964223a22414141222c226b6579223a22424242222c2272656d61726b223a22227d,s{115,115,1536743702395,1536743702395,0,0,0,0,89,0,115}
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,,- request:: '/config/wlf/accessProduct/1111111,F response::
[-- ::] DEBUG ClientCnxn: - Got notification sessionid:0x165cd0f7f5b0001
[-- ::] DEBUG ClientCnxn: - Got WatchedEvent state:SyncConnected type:NodeChildrenChanged path:/config/wlf/accessProduct for sessionid 0x165cd0f7f5b0001
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,, request:: '/config/wlf/accessProduct/1111111,#7b2270726f647563744964223a2231313131313131222c226d63684964223a22313131313131222c2270726f6475637454797065223a2232222c227370536572766963654964223a22222c2263616d706169676e4964223a22222c227469636b65744964223a2231313131313131222c22737461727454696d65223a22323031382d30342d323020383a30303a3030222c22656e6454696d65223a22323031382d30362d33302032333a35393a3539222c22697342616c616e6365223a2230227d,v{s{31,s{'world,'anyone}}},0 response:: '/config/wlf/accessProduct/
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,,- request:: '/config/wlf/accessProduct/333333333,F response::
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,, request:: '/config/wlf/accessProduct/333333333,#7b2270726f647563744964223a22333333333333333333222c226d63684964223a22313131313131222c2270726f6475637454797065223a2231222c227370536572766963654964223a22222c2263616d706169676e4964223a22222c227469636b65744964223a22222c22737461727454696d65223a22323031382d30382d30332030303a30303a3030222c22656e6454696d65223a22323031392d30382d30322032333a35393a3539222c22697342616c616e6365223a2231227d,v{s{31,s{'world,'anyone}}},0 response:: '/config/wlf/accessProduct/
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,,- request:: '/config/wlf/accessProduct/2222222,F response::
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,, request:: '/config/wlf/accessProduct/2222222,#7b2270726f647563744964223a2232323232323232222c226d63684964223a22323232323232222c2270726f6475637454797065223a2231222c227370536572766963654964223a22222c2263616d706169676e4964223a22222c227469636b65744964223a22222c22737461727454696d65223a22323031382d30342d32302031323a32363a3434222c22656e6454696d65223a22323031382d30362d32302031323a32363a3434222c22697342616c616e6365223a2230227d,v{s{31,s{'world,'anyone}}},0 response:: '/config/wlf/accessProduct/
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,,- request:: '/config/wlf/accessProduct/4444444444,F response::
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,, request:: '/config/wlf/accessProduct/4444444444,#7b2270726f647563744964223a2234343434343434343434222c226d63684964223a22323232323232222c2270726f6475637454797065223a2231222c227370536572766963654964223a22222c2263616d706169676e4964223a22222c227469636b65744964223a22222c22737461727454696d65223a22323031382d30382d30332030303a30303a3030222c22656e6454696d65223a22323031382d31322d33312032333a35393a3539222c22697342616c616e6365223a2230227d,v{s{31,s{'world,'anyone}}},0 response:: '/config/wlf/accessProduct/
[-- ::] DEBUG ZKUtils: - newServiceAccessCompanyMap:{"":{"mchId":"","mchName":"C公司","mchType":"","spId":"AAA","key":"BBB","remark":""}}
[-- ::] INFO ZKUtils: - enter handelServiceAccessProduct...
[-- ::] INFO ZKUtils: - enter handleServiceAccessCompany...
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,, request:: '/config/wlf/accessCompany,T response:: v{','333333,'}
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,, request:: '/config/wlf/accessCompany/222222,T response:: #7b226d63684964223a22323232323232222c226d63684e616d65223a2242ffffffe5ffffff85ffffffacffffffe5ffffff8fffffffb8222c226d636854797065223a2231222c2273704964223a22414141222c226b6579223a22424242222c2272656d61726b223a22227d,s{117,117,1536743702412,1536743702412,0,0,0,0,89,0,117}
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,, request:: '/config/wlf/accessCompany/333333,T response:: #7b226d63684964223a22333333333333222c226d63684e616d65223a2243ffffffe5ffffff85ffffffacffffffe5ffffff8fffffffb8222c226d636854797065223a2231222c2273704964223a22414141222c226b6579223a22424242222c2272656d61726b223a22227d,s{115,115,1536743702395,1536743702395,0,0,0,0,89,0,115}
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,, request:: '/config/wlf/accessCompany/111111,T response:: #7b226d63684964223a22313131313131222c226d63684e616d65223a2241ffffffe5ffffff85ffffffacffffffe5ffffff8fffffffb8222c226d636854797065223a2231222c2273704964223a22414141222c226b6579223a22424242222c2272656d61726b223a22227d,s{116,116,1536743702405,1536743702405,0,0,0,0,89,0,116}
[-- ::] DEBUG ZKUtils: - newServiceAccessCompanyMap:{"":{"mchId":"","mchName":"C公司","mchType":"","spId":"AAA","key":"BBB","remark":""},"":{"mchId":"","mchName":"B公司","mchType":"","spId":"AAA","key":"BBB","remark":""},"":{"mchId":"","mchName":"A公司","mchType":"","spId":"AAA","key":"BBB","remark":""}}
[-- ::] INFO ZKUtils: - enter handelServiceAccessProduct...
[-- ::] INFO ZKUtils: - enter handleServiceAccessCompany...
[-- ::] INFO ZKUtils: - enter handelServiceAccessProduct...
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,, request:: '/config/wlf/accessProduct,T response:: v{','333333333,','4444444444}
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,, request:: '/config/wlf/accessProduct/1111111,T response:: #7b2270726f647563744964223a2231313131313131222c226d63684964223a22313131313131222c2270726f6475637454797065223a2232222c227370536572766963654964223a22222c2263616d706169676e4964223a22222c227469636b65744964223a2231313131313131222c22737461727454696d65223a22323031382d30342d323020383a30303a3030222c22656e6454696d65223a22323031382d30362d33302032333a35393a3539222c22697342616c616e6365223a2230227d,s{118,118,1536743702422,1536743702422,0,0,0,0,193,0,118}
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,, request:: '/config/wlf/accessProduct/333333333,T response:: #7b2270726f647563744964223a22333333333333333333222c226d63684964223a22313131313131222c2270726f6475637454797065223a2231222c227370536572766963654964223a22222c2263616d706169676e4964223a22222c227469636b65744964223a22222c22737461727454696d65223a22323031382d30382d30332030303a30303a3030222c22656e6454696d65223a22323031392d30382d30322032333a35393a3539222c22697342616c616e6365223a2231227d,s{119,119,1536743702429,1536743702429,0,0,0,0,189,0,119}
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,, request:: '/config/wlf/accessProduct/2222222,T response:: #7b2270726f647563744964223a2232323232323232222c226d63684964223a22323232323232222c2270726f6475637454797065223a2231222c227370536572766963654964223a22222c2263616d706169676e4964223a22222c227469636b65744964223a22222c22737461727454696d65223a22323031382d30342d32302031323a32363a3434222c22656e6454696d65223a22323031382d30362d32302031323a32363a3434222c22697342616c616e6365223a2230227d,s{120,120,1536743702435,1536743702435,0,0,0,0,187,0,120}
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,, request:: '/config/wlf/accessProduct/4444444444,T response:: #7b2270726f647563744964223a2234343434343434343434222c226d63684964223a22323232323232222c2270726f6475637454797065223a2231222c227370536572766963654964223a22222c2263616d706169676e4964223a22222c227469636b65744964223a22222c22737461727454696d65223a22323031382d30382d30332030303a30303a3030222c22656e6454696d65223a22323031382d31322d33312032333a35393a3539222c22697342616c616e6365223a2230227d,s{121,121,1536743702439,1536743702439,0,0,0,0,190,0,121}
[-- ::] DEBUG ZKUtils: - newServiceAccessProductMap:{"":{"productId":"","mchId":"","productType":"","spServiceId":"","campaignId":"","ticketId":"","startTime":"2018-04-20 8:00:00","endTime":"2018-06-30 23:59:59","isBalance":""},"":{"productId":"","mchId":"","productType":"","spServiceId":"","campaignId":"","ticketId":"","startTime":"2018-08-03 00:00:00","endTime":"2019-08-02 23:59:59","isBalance":""},"":{"productId":"","mchId":"","productType":"","spServiceId":"","campaignId":"","ticketId":"","startTime":"2018-04-20 12:26:44","endTime":"2018-06-20 12:26:44","isBalance":""},"":{"productId":"","mchId":"","productType":"","spServiceId":"","campaignId":"","ticketId":"","startTime":"2018-08-03 00:00:00","endTime":"2018-12-31 23:59:59","isBalance":""}}
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 2ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 2ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 2ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 2ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 2ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 2ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 2ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 0ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 3ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 2ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 0ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 0ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 2ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got notification sessionid:0x165cd0f7f5b0001
[-- ::] DEBUG ClientCnxn: - Got WatchedEvent state:SyncConnected type:NodeDataChanged path:/config/wlf/accessCompany/ for sessionid 0x165cd0f7f5b0001
[-- ::] INFO ZKUtils: - enter handleServiceAccessCompany...
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,, request:: '/config/wlf/accessCompany,T response:: v{','333333,'}
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,, request:: '/config/wlf/accessCompany/222222,T response:: #7b226d63684964223a22323232323232222c226d63684e616d65223a2242ffffffe5ffffff85ffffffacffffffe5ffffff8fffffffb8222c226d636854797065223a2231222c2273704964223a22414141222c226b6579223a22424242222c2272656d61726b223a22227d,s{117,117,1536743702412,1536743702412,0,0,0,0,89,0,117}
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,, request:: '/config/wlf/accessCompany/333333,T response:: #7b226d63684964223a22333333333333222c226d63684e616d65223a22776c663f3f3f3f222c226d636854797065223a2232222c2273704964223a22776c66222c226b6579223a22776c66222c2272656d61726b223a22227d,s{115,124,1536743702395,1536743848084,1,0,0,0,89,0,115}
[-- ::] DEBUG ClientCnxn: - Reading reply sessionid:0x165cd0f7f5b0001, packet:: clientPath:null serverPath:null finished:false header:: , replyHeader:: ,, request:: '/config/wlf/accessCompany/111111,T response:: #7b226d63684964223a22313131313131222c226d63684e616d65223a2241ffffffe5ffffff85ffffffacffffffe5ffffff8fffffffb8222c226d636854797065223a2231222c2273704964223a22414141222c226b6579223a22424242222c2272656d61726b223a22227d,s{116,116,1536743702405,1536743702405,0,0,0,0,89,0,116}
[-- ::] DEBUG ZKUtils: - newServiceAccessCompanyMap:{"":{"mchId":"","mchName":"wlf????","mchType":"","spId":"wlf","key":"wlf","remark":""},"":{"mchId":"","mchName":"B公司","mchType":"","spId":"AAA","key":"BBB","remark":""},"":{"mchId":"","mchName":"A公司","mchType":"","spId":"AAA","key":"BBB","remark":""}}
[-- ::] INFO ZKUtils: - enter handelServiceAccessProduct...
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms
[-- ::] DEBUG ClientCnxn: - Got ping response for sessionid: 0x165cd0f7f5b0001 after 1ms

  上面最后打印的newServiceAccessCompanyMap就是监听到变更后同步过来的最新数据。

  最后看代码实现:

package com.wulinfeng.test.testpilling.util;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.KeeperException.Code;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.Watcher.Event.EventType;
import org.apache.zookeeper.ZooDefs.Ids;
import org.apache.zookeeper.ZooKeeper; import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.wulinfeng.test.testpilling.bean.ServiceAccessCompany;
import com.wulinfeng.test.testpilling.bean.ServiceAccessProduct; /**
* ZK工具类
*
* @author wulinfeng
* @version C10 2018年9月11日
* @since SDP V300R003C10
*/
public class ZKUtils
{
private static Logger LOGGER = LogManager.getLogger(ZKUtils.class); public static final int ZK_SESSION_TIMEOUT = PropertiesConfigUtil.getPropertyInt("zk.session.timeout", 3000); public static final String ZK_SERVER_URL = PropertiesConfigUtil.getProperty("zk.server.url", "127.0.0.1:2181"); private static ZooKeeper zk; private static final String ACCESS_PRODUCT_PATH =
PropertiesConfigUtil.getProperty("access.product.path", "/config/wlf/accessProduct");; private static final String ACCESS_COMPANY_PATH =
PropertiesConfigUtil.getProperty("access.company.path", "/config/wlf/accessCompany"); /**
* 存放接入方信息的map
*/
public static volatile Map<String, ServiceAccessCompany> serviceAccessCompanyMap; /**
* 存放产品信息的map
*/
public static volatile Map<String, ServiceAccessProduct> serviceAccessProductMap; private static final ObjectMapper MAPPER = new ObjectMapper(); public static void main(String[] args)
{
// 初始化
ZKUtils zk = new ZKUtils();
zk.init(); // 看看跟目录下有啥
LOGGER.debug(getZKServices("/")); // 导入测试数据
zk.importData(); // 主进程休眠5分钟,方便操作后台zk,看能否监听到操作
try
{
Thread.sleep(ZK_SESSION_TIMEOUT * 100);
}
catch (Exception e)
{
LOGGER.error("error :{} ", e);
}
} /**
* 初始化
*
* @author wulinfeng
*/
public void init()
{
// 忽略不存在的字段
MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
MAPPER.setSerializationInclusion(Include.NON_NULL);
LOGGER.debug(String.format("start connect zk, zk server:%s", ZK_SERVER_URL));
connect();
} /**
* 导入数据
*
* @author wulinfeng
*/
public void importData()
{
// 构造数据
Map<String, byte[]> companys = createCompany();
Map<String, byte[]> products = createProduct(); // 批量导入zk
try
{
if (companys != null && companys.size() > 0)
{
for (Map.Entry<String, byte[]> entry : companys.entrySet())
{
String key = ACCESS_COMPANY_PATH.concat("/").concat(entry.getKey());
if (null == zk.exists(key, false))
{
zk.create(key, entry.getValue(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
}
} if (products != null && products.size() > 0)
{
for (Map.Entry<String, byte[]> entry : products.entrySet())
{
String key = ACCESS_PRODUCT_PATH.concat("/").concat(entry.getKey());
if (null == zk.exists(key, false))
{
zk.create(key, entry.getValue(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
}
}
}
catch (KeeperException e)
{
Code code = e.code();
if (code != Code.NODEEXISTS)
{
LOGGER.error("ZKUtilss.importData has error, e:{}", e);
}
if (code == Code.SESSIONEXPIRED || code == Code.SESSIONMOVED)
{
connect();
}
}
catch (InterruptedException e)
{
LOGGER.error("ZKUtilss.importData has error, e:{}", e);
}
} /**
* 连接zk服务器
*
* @author wulinfeng
*/
public void connect()
{
try
{
synchronized (MAPPER)
{
try
{
if (null != zk)
{
LOGGER.error("zk retry connect...");
zk.close();
}
}
catch (InterruptedException e)
{
LOGGER.error("ZKUtils.connect has error, when zk close, e: {}", e);
}
// 连接zk并注册监听
zk = new ZooKeeper(ZK_SERVER_URL, ZK_SESSION_TIMEOUT, new Watcher()
{
// 监控所有被触发的事件
public void process(WatchedEvent event)
{
handel(event);
}
});
} // 监听的目录不存在,默认创建目录
createIfAbsent();
// 更新产品信息
updateServiceAccessProduct();
// 更新接入方信息
updateServiceAccessCompany();
}
catch (IOException e)
{
LOGGER.error("ZKUtils.connect has error, connect failed, zkServerUrl: {}, e: {}", ZK_SERVER_URL, e);
}
} /**
* 目录不存在则创建
*
* @author wulinfeng
*/
private void createIfAbsent()
{
createIfAbsent(ACCESS_COMPANY_PATH);
createIfAbsent(ACCESS_PRODUCT_PATH);
} /**
* 递归创建目录
*
* @param path
* @author fengjiangtao
*/
private void createIfAbsent(String path)
{
try
{
int index = path.lastIndexOf("/");
if (index < 0)
{
return;
}
else if (index == 0)
{
// 根目录
zk.create(path, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
else
{
String sonPath = path.substring(0, index);
if (null == zk.exists(sonPath, false))
{
createIfAbsent(sonPath);
zk.create(path, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
else if (null == zk.exists(path, false))
{
zk.create(path, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
}
}
catch (KeeperException e)
{
Code code = e.code();
if (code != Code.NODEEXISTS)
{
LOGGER.error("ZKUtilss.createIfAbsent has error, e:{}", e);
}
if (code == Code.SESSIONEXPIRED || code == Code.SESSIONMOVED)
{
connect();
}
}
catch (InterruptedException e)
{
LOGGER.error("ZKUtilss.createIfAbsent has error, e:{}", e);
}
} /**
* zk监听处理类
*
* @author wulinfeng
* @param event
*/
private void handel(WatchedEvent event)
{
handleServiceAccessCompany(event);
handelServiceAccessProduct(event);
} /**
* 把zk节点变化的数据同步到内存中
*
* @author wulinfeng
* @param event
*/
private void handelServiceAccessProduct(WatchedEvent event)
{
LOGGER.info("enter handelServiceAccessProduct...");
EventType type = event.getType();
if (event.getPath() != null && event.getPath().startsWith(ACCESS_PRODUCT_PATH)
&& (type == EventType.NodeChildrenChanged || type == EventType.NodeDataChanged))
{
updateServiceAccessProduct();
}
} /**
* 监听接入方事件
*
* @author wulinfeng
* @param event
*/
private void handleServiceAccessCompany(WatchedEvent event)
{
LOGGER.info("enter handleServiceAccessCompany...");
EventType type = event.getType();
if (event.getPath() != null && event.getPath().startsWith(ACCESS_COMPANY_PATH)
&& (type == EventType.NodeChildrenChanged || type == EventType.NodeDataChanged))
{
updateServiceAccessCompany();
}
} /**
* 更新产品
*
* @author wulinfeng
*/
private void updateServiceAccessProduct()
{
Map<String, ServiceAccessProduct> accessProductMap = getServiceAccessProduct();
if (accessProductMap != null && accessProductMap.size() > 0)
{
serviceAccessProductMap = accessProductMap;
}
} /**
* 获取产品数据
*
* @author wulinfeng
* @return
*/
private Map<String, ServiceAccessProduct> getServiceAccessProduct()
{
try
{
List<String> products = zk.getChildren(ACCESS_PRODUCT_PATH, true);
if (products != null && products.size() > 0)
{
Map<String, ServiceAccessProduct> newServiceAccessProductMap =
new HashMap<String, ServiceAccessProduct>(products.size());
for (String product : products)
{
if (StringUtils.isBlank(product))
{
continue;
}
String serviceConfigPath = ACCESS_PRODUCT_PATH.concat("/").concat(product);
ServiceAccessProduct newServiceAccessProduct =
getData(serviceConfigPath, ServiceAccessProduct.class); if (newServiceAccessProduct != null)
{
newServiceAccessProductMap.put(newServiceAccessProduct.getProductId(), newServiceAccessProduct);
}
}
if (newServiceAccessProductMap.size() > 0)
{
LOGGER.debug(String.format("newServiceAccessProductMap:%s", getJson(newServiceAccessProductMap)));
return newServiceAccessProductMap;
}
}
}
catch (KeeperException e)
{
Code code = e.code();
if (code != Code.NONODE)
{
LOGGER.error("ZKUtils.getServiceAccessProduct has error, e: {}", e);
}
if (code == Code.SESSIONEXPIRED || code == Code.SESSIONMOVED)
{
connect();
}
}
catch (InterruptedException e)
{
LOGGER.error("ZKUtils.getServiceAccessProduct has error, e: {}", e);
}
return null;
} /**
* 更新接入方
*
* @author wulinfeng
*/
private void updateServiceAccessCompany()
{
Map<String, ServiceAccessCompany> accessCompanyMap = getServiceAccessCompany();
if (accessCompanyMap != null && accessCompanyMap.size() > 0)
{
serviceAccessCompanyMap = accessCompanyMap;
}
} /**
* 获取接入方数据
*
* @author wulinfeng
* @return
*/
private Map<String, ServiceAccessCompany> getServiceAccessCompany()
{
try
{
List<String> mchids = zk.getChildren(ACCESS_COMPANY_PATH, true);
if (mchids != null && mchids.size() > 0)
{
Map<String, ServiceAccessCompany> newServiceAccessCompanyMap =
new HashMap<String, ServiceAccessCompany>(mchids.size());
for (String mchid : mchids)
{
if (StringUtils.isBlank(mchid))
{
continue;
}
String serviceConfigPath = ACCESS_COMPANY_PATH.concat("/").concat(mchid);
ServiceAccessCompany newServiceAccessCompany =
getData(serviceConfigPath, ServiceAccessCompany.class);
if (newServiceAccessCompany != null)
{
newServiceAccessCompanyMap.put(newServiceAccessCompany.getMchId(), newServiceAccessCompany);
}
}
if (newServiceAccessCompanyMap.size() > 0)
{
LOGGER.debug(String.format("newServiceAccessCompanyMap:%s", getJson(newServiceAccessCompanyMap)));
return newServiceAccessCompanyMap;
}
}
}
catch (KeeperException e)
{
Code code = e.code();
if (code != Code.NONODE)
{
LOGGER.error("ZKUtils.updateServiceAccessCompany has error, e: {}", e);
}
if (code == Code.SESSIONEXPIRED || code == Code.SESSIONMOVED)
{
connect();
}
}
catch (InterruptedException e)
{
LOGGER.error("ZKUtils.updateServiceAccessCompany has error, e: {}", e);
}
return null;
} /**
* 对象转json
*
* @author wulinfeng
* @param object
* @return
*/
private String getJson(Object object)
{
if (null == object)
{
return null;
}
try
{
return MAPPER.writeValueAsString(object);
}
catch (JsonProcessingException e)
{
LOGGER.error("ZKUtils.getJson has error, object: {}, e: {}", object, e);
}
return null;
} /**
* 创建zk节点
*
* @author wulinfeng
* @param path
* @param data
* @throws KeeperException
* @throws InterruptedException
*/
public static void create(String path, byte[] data)
throws KeeperException, InterruptedException
{
/**
* 此处采用的是CreateMode EPHEMERAL 表示The znode will be deleted upon the client's disconnect.
*/
zk.create(path, data, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
} /**
* 获取发布到zk上的服务
*
* @author wulinfeng
* @param path
* @return
* @throws KeeperException
* @throws InterruptedException
*/
public static String getZKServices(String path)
{
if (path == null)
{
return "zk path is null!";
}
StringBuilder childsStr = new StringBuilder("zk server: [ ");
childsStr.append(ZK_SERVER_URL);
childsStr.append(" ]\n");
childsStr.append("zk path: [");
childsStr.append(path);
childsStr.append("] \n\n");
try
{
List<String> list = zk.getChildren(path, false);
if (list.isEmpty())
{
childsStr.append("no zk service!");
}
else
{
for (String child : list)
{
childsStr.append(child);
childsStr.append("\n");
}
}
}
catch (KeeperException e)
{
Code code = e.code();
if (code != Code.NONODE)
{
LOGGER.error("ZKUtils.getServiceAccessProduct has error, e: {}", e);
}
}
catch (InterruptedException e)
{
LOGGER.error("ZKUtils.getServiceAccessProduct has error, e: {}", e);
}
return childsStr.toString();
} /**
* 获取zk节点下的数据
*
* @author wulinfeng
* @param znodePath
* @param clazz
* @return
*/
private <T> T getData(String znodePath, Class<T> clazz)
{
try
{
byte[] data = zk.getData(znodePath, true, null);
String jsonData = new String(data, "utf-8");
if (clazz == String.class)
{
return (T)jsonData;
}
if (jsonData != null)
{
return MAPPER.readValue(jsonData, clazz);
}
}
catch (KeeperException e)
{
Code code = e.code();
if (code != Code.NONODE)
{
LOGGER.error("ZKUtils.updateDate has error, class:{}, e:{}", clazz.getName(), e);
}
if (code == Code.SESSIONEXPIRED || code == Code.SESSIONMOVED)
{
connect();
}
}
catch (Exception e)
{
LOGGER.error("ZKUtils.updateDate has error, class:{}, e:{}", clazz.getName(), e);
} return null;
} /**
* 构造测试数据
*
* @author wulinfeng
* @return
*/
private Map<String, byte[]> createCompany()
{
Map<String, byte[]> companyMap = new HashMap<>(3);
ServiceAccessCompany sac = new ServiceAccessCompany(); sac.setMchId("111111");
sac.setMchName("A公司");
sac.setMchType("1");
sac.setSpId("AAA");
sac.setKey("BBB");
sac.setRemark("");
companyMap.put(sac.getMchId(), getJson(sac).getBytes()); sac.setMchId("222222");
sac.setMchName("B公司");
companyMap.put(sac.getMchId(), getJson(sac).getBytes()); sac.setMchId("333333");
sac.setMchName("C公司");
companyMap.put(sac.getMchId(), getJson(sac).getBytes()); return companyMap;
} /**
* 构造测试数据
*
* @author wulinfeng
* @return
*/
private Map<String, byte[]> createProduct()
{
Map<String, byte[]> productMap = new HashMap<>(4);
ServiceAccessProduct sap = new ServiceAccessProduct(); sap.setProductId("1111111");
sap.setProductType("2");
sap.setMchId("111111");
sap.setCampaignId("");
sap.setSpServiceId("");
sap.setTicketId("1111111");
sap.setIsBalance("0");
sap.setStartTime("2018-04-20 8:00:00");
sap.setEndTime("2018-06-30 23:59:59");
productMap.put(sap.getProductId(), getJson(sap).getBytes()); sap.setProductId("2222222");
sap.setProductType("1");
sap.setMchId("222222");
sap.setCampaignId("");
sap.setSpServiceId("");
sap.setTicketId("");
sap.setIsBalance("0");
sap.setStartTime("2018-04-20 12:26:44");
sap.setEndTime("2018-06-20 12:26:44");
productMap.put(sap.getProductId(), getJson(sap).getBytes()); sap.setProductId("333333333");
sap.setMchId("111111");
sap.setCampaignId("");
sap.setSpServiceId("");
sap.setIsBalance("1");
sap.setStartTime("2018-08-03 00:00:00");
sap.setEndTime("2019-08-02 23:59:59");
productMap.put(sap.getProductId(), getJson(sap).getBytes()); sap.setProductId("4444444444");
sap.setMchId("222222");
sap.setCampaignId("");
sap.setSpServiceId("");
sap.setIsBalance("0");
sap.setEndTime("2018-12-31 23:59:59");
productMap.put(sap.getProductId(), getJson(sap).getBytes()); return productMap;
}
}

zookeeper事件监听的更多相关文章

  1. Zookeeper Curator 事件监听 - 秒懂

    目录 写在前面 1.1. Curator 事件监听 1.1.1. Watcher 标准的事件处理器 1.1.2. NodeCache 节点缓存的监听 1.1.3. PathChildrenCache ...

  2. Zookeeper开源客户端Curator之事件监听详解

    Curator对Zookeeper典型场景之事件监听进行封装,提供了使用参考.这篇博文笔者带领大家了解一下Curator的实现方式. 引入依赖 对于Curator封装Zookeeper的典型场景使用都 ...

  3. Java中用得比较顺手的事件监听

    第一次听说监听是三年前,做一个webGIS的项目,当时对Listener的印象就是个"监视器",监视着界面的一举一动,一有动静就触发对应的响应. 一.概述 通过对界面的某一或某些操 ...

  4. 4.JAVA之GUI编程事件监听机制

    事件监听机制的特点: 1.事件源 2.事件 3.监听器 4.事件处理 事件源:就是awt包或者swing包中的那些图形用户界面组件.(如:按钮) 事件:每一个事件源都有自己特点有的对应事件和共性事件. ...

  5. Node.js 教程 05 - EventEmitter(事件监听/发射器 )

    目录: 前言 Node.js事件驱动介绍 Node.js事件 注册并发射自定义Node.js事件 EventEmitter介绍 EventEmitter常用的API error事件 继承EventEm ...

  6. .NET事件监听机制的局限与扩展

    .NET中把“事件”看作一个基本的编程概念,并提供了非常优美的语法支持,对比如下C#和Java代码可以看出两种语言设计思想之间的差异. // C#someButton.Click += OnSomeB ...

  7. 让 select 的 option 标签支持事件监听(如复制操作)

    这标题,让option支持事件监听,应该不难的呀,有什么好讲的? 其实还是有的,默认在浏览器代码是无法直接对option标签进行操作的,不仅包括JS事件监听,还是CSS样式设置 查了一些资料,姑且认为 ...

  8. [JS]笔记12之事件机制--事件冒泡和捕获--事件监听--阻止事件传播

    -->事件冒泡和捕获-->事件监听-->阻止事件传播 一.事件冒泡和捕获 1.概念:当给子元素和父元素定义了相同的事件,比如都定义了onclick事件,点击子元素时,父元素的oncl ...

  9. [No00006A]Js的addEventListener()及attachEvent()区别分析【js中的事件监听】

    1.添加时间监听: Chrom中: addEventListener的使用方式: target.addEventListener(type, listener, useCapture); target ...

随机推荐

  1. 安装Linux环境

    虚拟机:虚拟机(Virtual Machine),在计算机科学中的体系结构里,是指一种特殊的软件,他可以在计算机平台和终端用户之间建立一种环境,而终端用户则是基于这个软件所建立的环境来操作软件.在计算 ...

  2. POJ 2891 中国剩余定理的非互质形式

    中国剩余定理的非互质形式 任意n个表达式一对对处理,故只需处理两个表达式. x = a(mod m) x = b(mod n) km+a = b (mod n) km = (a-b)(mod n) 利 ...

  3. iptables详解(14):iptables小结之常用套路

    不知不觉,已经总结了13篇iptables文章,这些文章中有一些需要注意的地方. 此处,我们对前文中的一些注意点进行总结,我们可以理解为对"常用套路"的总结. 记住这些套路,能让我 ...

  4. 由浅入深了解EventBus:(一)

    概述 由greenrobot织贡献(该组织还贡献了greenDAO),一个Android事件发布/订阅轻量级框架; EventBus是一个消息总线,以观察者模式实现,用于简化程序的组件.线程通信,可以 ...

  5. Oracle recovery manager failed to restore

    解决办法: 1:清理过期失效的备份, 2:增加recovery_file_dest_size参数值即可: SQL> show parameter db_recover NAME          ...

  6. python中time()时间的相关问题

    Python中time模块详解(转) 在平常的代码中,我们常常需要与时间打交道.在Python中,与时间处理有关的模块就包括:time,datetime以及calendar.这篇文章,主要讲解time ...

  7. vue 插件(Sublime Text 3 常用插件以及安装方法)(转)

    使用Package Control组件安装 也可以安装package control组件,然后直接在线安装:按Ctrl+` 调出console粘贴以下代码到底部命令行并回车: { import url ...

  8. python_安装第三方库

    1.有一个专门可下载安装第三方库的网址: http://www.lfd.uci.edu/~gohlke/pythonlibs/   Ctrl+f 搜索要下载的第三方库,并下载 2.库文件都是以 whl ...

  9. Miscosoft Visual Studio项目guid取值

    There isn't an easy way to change the type of a project in Visual Studio project once it is created; ...

  10. linux自学(五)之开始centos学习,Xshell远程连接

    上一篇:linux自学(四)之开始centos学习,网络配置 前面操作都是在电脑中的虚拟机上操作的,比较麻烦,需要来回切换.下面我将使用远程连接工具Xshell进行操作,Xshell直接百度下载即可. ...