|
1 | 1 | package org.zookeeper.app; |
2 | 2 |
|
| 3 | +import com.netflix.curator.framework.api.CuratorWatcher; |
3 | 4 | import org.apache.zookeeper.CreateMode; |
4 | | -import org.apache.zookeeper.KeeperException; |
5 | 5 | import org.apache.zookeeper.Watcher; |
6 | 6 | import org.apache.zookeeper.ZooDefs; |
7 | 7 | import org.apache.zookeeper.data.Stat; |
8 | | -import org.zookeeper.tdg.ConnectionWatcher; |
9 | | - |
10 | | -import java.io.UnsupportedEncodingException; |
| 8 | +import org.zookeeper.tdg.CuratorConnection; |
11 | 9 |
|
12 | 10 | /** |
13 | 11 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
25 | 23 | * See the License for the specific language governing permissions and |
26 | 24 | * limitations under the License. |
27 | 25 | */ |
28 | | -public class ActiveKeyValueStore extends ConnectionWatcher { |
| 26 | +public class ActiveKeyValueStore extends CuratorConnection { |
29 | 27 |
|
30 | 28 | public static final String CHARSET = "UTF-8"; |
31 | 29 |
|
32 | | - public void write(String path, String value) throws InterruptedException, KeeperException, UnsupportedEncodingException { |
33 | | - Stat stat = zk.exists(path, false); |
| 30 | + public void write(String path, String value) throws Exception { |
| 31 | + Stat stat = client.checkExists().forPath(path); |
34 | 32 | if (stat == null) |
35 | | - zk.create(path, value.getBytes(CHARSET), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); |
| 33 | + client.create() |
| 34 | + .withMode(CreateMode.PERSISTENT) |
| 35 | + .withACL(ZooDefs.Ids.OPEN_ACL_UNSAFE) |
| 36 | + .forPath(path, value.getBytes(CHARSET)); |
36 | 37 | else |
37 | | - zk.setData(path, value.getBytes(CHARSET), -1); |
| 38 | + client.setData().forPath(path, value.getBytes(CHARSET)); |
38 | 39 | } |
39 | 40 |
|
40 | | - public String read(String path, Watcher watcher) throws InterruptedException, KeeperException, UnsupportedEncodingException { |
41 | | - byte[] data = zk.getData(path,watcher,null); |
| 41 | + public String read(String path, CuratorWatcher watcher) throws Exception { |
| 42 | + byte[] data = client.getData().usingWatcher(watcher).forPath(path); |
42 | 43 | return new String(data,CHARSET); |
43 | 44 | } |
44 | 45 | } |
0 commit comments