jetcd how watch directory?

337 views
Skip to first unread message

张东升

unread,
Jun 26, 2017, 12:38:31 AM6/26/17
to etcd-dev
jetcd  how watch directory? when put a key-value in this directory ?

ByteSequence SECURITY_CONFIG_PATH = ByteSequence.fromString("/security_config/bizkey/");
ByteSequence SECURITY_CONFIG_PATH_END = ByteSequence.fromString("/security_config/bizkey/1000");

etcdClient.getWatchClient().watch(SECURITY_CONFIG_PATH, WatchOption.newBuilder().withRange(SECURITY_CONFIG_PATH).build(), new Watch.WatchCallback() {
@Override
public void onWatch(Header header, List<WatchEvent> list) {
System.out.println("watcjh:");
for (WatchEvent event: list){
System.out.println("key:"+event.getKeyValue().getKey().toStringUtf8()+",value:"+event.getKeyValue().getValue().toStringUtf8());
}
}

@Override
public void onResuming() {

}
});

anthony...@coreos.com

unread,
Jun 26, 2017, 12:38:29 PM6/26/17
to etcd-dev
withRange(OptionsUtil.prefixEndOf(SECURITY_CONFIG_PATH))

WatchOption should probably have a withPrefix() option to be consistent with get/delete options, though.

张东升

unread,
Jun 26, 2017, 11:48:43 PM6/26/17
to etcd-dev
OptionsUtil.prefixEndOf is not a public method,so client can not use "OptionsUtil.prefixEndOf".

WatchOption can add withPrefix like GetOption:

public Builder withPrefix(ByteSequence prefix) {
      checkNotNull(prefix, "prefix should not be null");
      ByteSequence prefixEnd = OptionsUtil.prefixEndOf(prefix);
      this.withRange(prefixEnd);
      return this;

张东升

unread,
Jun 27, 2017, 1:22:52 AM6/27/17
to etcd-dev
I pullRequst the change to git for WatchOption add withPrefix
Reply all
Reply to author
Forward
0 new messages