Skip to content

Commit 0b3e3cb

Browse files
committed
ZOOKEEPER-4968: Add interfaces to cover ZooKeeper client operations
Changes: 1. Add new interface `Zookeeper` in `o.a.z.client`. 2. Add `ZooKeeper::builder` to construct instance of `ZooKeeper`. 3. Add `ZooKeeperAdaptor` to proxy interface methods to `o.a.z.ZooKeeper` instance to keep abi compatibility.
1 parent bbcdbab commit 0b3e3cb

File tree

7 files changed

+1675
-11
lines changed

7 files changed

+1675
-11
lines changed

zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeper.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,8 +1282,6 @@ public int getSessionTimeout() {
12821282
/**
12831283
* Add the specified scheme:auth information to this connection.
12841284
*
1285-
* This method is NOT thread safe
1286-
*
12871285
* @param scheme
12881286
* @param auth
12891287
*/

zookeeper-server/src/main/java/org/apache/zookeeper/client/ZooKeeper.java

Lines changed: 1122 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 365 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,365 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.zookeeper.client;
20+
21+
import java.io.IOException;
22+
import java.util.List;
23+
import org.apache.zookeeper.AddWatchMode;
24+
import org.apache.zookeeper.AsyncCallback;
25+
import org.apache.zookeeper.CreateMode;
26+
import org.apache.zookeeper.KeeperException;
27+
import org.apache.zookeeper.Op;
28+
import org.apache.zookeeper.OpResult;
29+
import org.apache.zookeeper.Transaction;
30+
import org.apache.zookeeper.Watcher;
31+
import org.apache.zookeeper.data.ACL;
32+
import org.apache.zookeeper.data.ClientInfo;
33+
import org.apache.zookeeper.data.Stat;
34+
35+
/**
36+
* Adaptor to bridge {@link org.apache.zookeeper.ZooKeeper} to implement {@link ZooKeeper} while not introducing
37+
* abi compatibility issue.
38+
*/
39+
class ZooKeeperAdaptor implements ZooKeeper {
40+
private final org.apache.zookeeper.ZooKeeper zk;
41+
42+
ZooKeeperAdaptor(org.apache.zookeeper.ZooKeeper zk) {
43+
this.zk = zk;
44+
}
45+
46+
@Override
47+
public long getSessionId() {
48+
return zk.getSessionId();
49+
}
50+
51+
@Override
52+
public byte[] getSessionPasswd() {
53+
return zk.getSessionPasswd();
54+
}
55+
56+
@Override
57+
public int getSessionTimeout() {
58+
return zk.getSessionTimeout();
59+
}
60+
61+
@Override
62+
public ZKClientConfig getClientConfig() {
63+
return zk.getClientConfig();
64+
}
65+
66+
@Override
67+
public void register(Watcher watcher) {
68+
zk.register(watcher);
69+
}
70+
71+
@Override
72+
public void updateServerList(String connectString) throws IOException {
73+
zk.updateServerList(connectString);
74+
}
75+
76+
@Override
77+
public Stat exists(String path, boolean watch) throws KeeperException, InterruptedException {
78+
return zk.exists(path, watch);
79+
}
80+
81+
@Override
82+
public Stat exists(String path, Watcher watcher) throws KeeperException, InterruptedException {
83+
return zk.exists(path, watcher);
84+
}
85+
86+
@Override
87+
public void exists(String path, boolean watch, AsyncCallback.StatCallback cb, Object ctx) {
88+
zk.exists(path, watch, cb, ctx);
89+
}
90+
91+
@Override
92+
public void exists(String path, Watcher watcher, AsyncCallback.StatCallback cb, Object ctx) {
93+
zk.exists(path, watcher, cb, ctx);
94+
}
95+
96+
@Override
97+
public String create(String path, byte[] data, List<ACL> acl, CreateMode createMode) throws KeeperException, InterruptedException {
98+
return zk.create(path, data, acl, createMode);
99+
}
100+
101+
@Override
102+
public String create(String path, byte[] data, List<ACL> acl, CreateMode createMode, Stat stat) throws KeeperException, InterruptedException {
103+
return zk.create(path, data, acl, createMode, stat);
104+
}
105+
106+
@Override
107+
public String create(String path, byte[] data, List<ACL> acl, CreateMode createMode, Stat stat, long ttl) throws KeeperException, InterruptedException {
108+
return zk.create(path, data, acl, createMode, stat, ttl);
109+
}
110+
111+
@Override
112+
public void addAuthInfo(String scheme, byte[] auth) {
113+
zk.addAuthInfo(scheme, auth);
114+
}
115+
116+
@Override
117+
public void create(String path, byte[] data, List<ACL> acl, CreateMode createMode, AsyncCallback.StringCallback cb, Object ctx) {
118+
zk.create(path, data, acl, createMode, cb, ctx);
119+
}
120+
121+
@Override
122+
public void create(String path, byte[] data, List<ACL> acl, CreateMode createMode, AsyncCallback.Create2Callback cb, Object ctx) {
123+
zk.create(path, data, acl, createMode, cb, ctx);
124+
}
125+
126+
@Override
127+
public void create(String path, byte[] data, List<ACL> acl, CreateMode createMode, AsyncCallback.Create2Callback cb, Object ctx, long ttl) {
128+
zk.create(path, data, acl, createMode, cb, ctx, ttl);
129+
}
130+
131+
@Override
132+
public void delete(String path, int version) throws InterruptedException, KeeperException {
133+
zk.delete(path, version);
134+
}
135+
136+
@Override
137+
public void delete(String path, int version, AsyncCallback.VoidCallback cb, Object ctx) {
138+
zk.delete(path, version, cb, ctx);
139+
}
140+
141+
@Override
142+
public List<OpResult> multi(Iterable<Op> ops) throws InterruptedException, KeeperException {
143+
return zk.multi(ops);
144+
}
145+
146+
@Override
147+
public void multi(Iterable<Op> ops, AsyncCallback.MultiCallback cb, Object ctx) {
148+
zk.multi(ops, cb, ctx);
149+
}
150+
151+
@Override
152+
public byte[] getData(String path, boolean watch, Stat stat) throws KeeperException, InterruptedException {
153+
return zk.getData(path, watch, stat);
154+
}
155+
156+
@Override
157+
public byte[] getData(String path, Watcher watcher, Stat stat) throws KeeperException, InterruptedException {
158+
return zk.getData(path, watcher, stat);
159+
}
160+
161+
@Override
162+
public void getData(String path, boolean watch, AsyncCallback.DataCallback cb, Object ctx) {
163+
zk.getData(path, watch, cb, ctx);
164+
}
165+
166+
@Override
167+
public void getData(String path, Watcher watcher, AsyncCallback.DataCallback cb, Object ctx) {
168+
zk.getData(path, watcher, cb, ctx);
169+
}
170+
171+
@Override
172+
public byte[] getConfig(boolean watch, Stat stat) throws KeeperException, InterruptedException {
173+
return zk.getConfig(watch, stat);
174+
}
175+
176+
@Override
177+
public byte[] getConfig(Watcher watcher, Stat stat) throws KeeperException, InterruptedException {
178+
return zk.getConfig(watcher, stat);
179+
}
180+
181+
@Override
182+
public void getConfig(boolean watch, AsyncCallback.DataCallback cb, Object ctx) {
183+
zk.getConfig(watch, cb, ctx);
184+
}
185+
186+
@Override
187+
public void getConfig(Watcher watcher, AsyncCallback.DataCallback cb, Object ctx) {
188+
zk.getConfig(watcher, cb, ctx);
189+
}
190+
191+
@Override
192+
public Stat setData(String path, byte[] data, int version) throws KeeperException, InterruptedException {
193+
return zk.setData(path, data, version);
194+
}
195+
196+
@Override
197+
public void setData(String path, byte[] data, int version, AsyncCallback.StatCallback cb, Object ctx) {
198+
zk.setData(path, data, version, cb, ctx);
199+
}
200+
201+
@Override
202+
public List<ACL> getACL(String path, Stat stat) throws KeeperException, InterruptedException {
203+
return zk.getACL(path, stat);
204+
}
205+
206+
@Override
207+
public void getACL(String path, Stat stat, AsyncCallback.ACLCallback cb, Object ctx) {
208+
zk.getACL(path, stat, cb, ctx);
209+
}
210+
211+
@Override
212+
public Stat setACL(String path, List<ACL> acl, int aclVersion) throws KeeperException, InterruptedException {
213+
return zk.setACL(path, acl, aclVersion);
214+
}
215+
216+
@Override
217+
public void setACL(String path, List<ACL> acl, int version, AsyncCallback.StatCallback cb, Object ctx) {
218+
zk.setACL(path, acl, version, cb, ctx);
219+
}
220+
221+
@Override
222+
public List<String> getChildren(String path, boolean watch) throws KeeperException, InterruptedException {
223+
return zk.getChildren(path, watch);
224+
}
225+
226+
@Override
227+
public List<String> getChildren(String path, Watcher watcher) throws KeeperException, InterruptedException {
228+
return zk.getChildren(path, watcher);
229+
}
230+
231+
@Override
232+
public List<String> getChildren(String path, boolean watch, Stat stat) throws KeeperException, InterruptedException {
233+
return zk.getChildren(path, watch, stat);
234+
}
235+
236+
@Override
237+
public List<String> getChildren(String path, Watcher watcher, Stat stat) throws KeeperException, InterruptedException {
238+
return zk.getChildren(path, watcher, stat);
239+
}
240+
241+
@Override
242+
public void getChildren(String path, boolean watch, AsyncCallback.ChildrenCallback cb, Object ctx) {
243+
zk.getChildren(path, watch, cb, ctx);
244+
}
245+
246+
@Override
247+
public void getChildren(String path, boolean watch, AsyncCallback.Children2Callback cb, Object ctx) {
248+
zk.getChildren(path, watch, cb, ctx);
249+
}
250+
251+
@Override
252+
public void getChildren(String path, Watcher watcher, AsyncCallback.ChildrenCallback cb, Object ctx) {
253+
zk.getChildren(path, watcher, cb, ctx);
254+
}
255+
256+
@Override
257+
public void getChildren(String path, Watcher watcher, AsyncCallback.Children2Callback cb, Object ctx) {
258+
zk.getChildren(path, watcher, cb, ctx);
259+
}
260+
261+
@Override
262+
public int getAllChildrenNumber(String path) throws KeeperException, InterruptedException {
263+
return zk.getAllChildrenNumber(path);
264+
}
265+
266+
@Override
267+
public void getAllChildrenNumber(String path, AsyncCallback.AllChildrenNumberCallback cb, Object ctx) {
268+
zk.getAllChildrenNumber(path, cb, ctx);
269+
}
270+
271+
@Override
272+
public List<String> getEphemerals() throws KeeperException, InterruptedException {
273+
return zk.getEphemerals();
274+
}
275+
276+
@Override
277+
public List<String> getEphemerals(String prefixPath) throws KeeperException, InterruptedException {
278+
return zk.getEphemerals(prefixPath);
279+
}
280+
281+
@Override
282+
public void getEphemerals(AsyncCallback.EphemeralsCallback cb, Object ctx) {
283+
zk.getEphemerals(cb, ctx);
284+
}
285+
286+
@Override
287+
public void getEphemerals(String prefixPath, AsyncCallback.EphemeralsCallback cb, Object ctx) {
288+
zk.getEphemerals(prefixPath, cb, ctx);
289+
}
290+
291+
@Override
292+
public void sync(String path) throws KeeperException, InterruptedException {
293+
zk.sync(path);
294+
}
295+
296+
@Override
297+
public void sync(String path, AsyncCallback.VoidCallback cb, Object ctx) {
298+
zk.sync(path, cb, ctx);
299+
}
300+
301+
@Override
302+
public void removeWatches(String path, Watcher watcher, Watcher.WatcherType watcherType, boolean local) throws InterruptedException, KeeperException {
303+
zk.removeWatches(path, watcher, watcherType, local);
304+
}
305+
306+
@Override
307+
public void removeWatches(String path, Watcher watcher, Watcher.WatcherType watcherType, boolean local, AsyncCallback.VoidCallback cb, Object ctx) {
308+
zk.removeWatches(path, watcher, watcherType, local, cb, ctx);
309+
}
310+
311+
@Override
312+
public void removeAllWatches(String path, Watcher.WatcherType watcherType, boolean local) throws InterruptedException, KeeperException {
313+
zk.removeAllWatches(path, watcherType, local);
314+
}
315+
316+
@Override
317+
public void removeAllWatches(String path, Watcher.WatcherType watcherType, boolean local, AsyncCallback.VoidCallback cb, Object ctx) {
318+
zk.removeAllWatches(path, watcherType, local, cb, ctx);
319+
}
320+
321+
@Override
322+
public void addWatch(String basePath, Watcher watcher, AddWatchMode mode) throws KeeperException, InterruptedException {
323+
zk.addWatch(basePath, watcher, mode);
324+
}
325+
326+
@Override
327+
public void addWatch(String basePath, AddWatchMode mode) throws KeeperException, InterruptedException {
328+
zk.addWatch(basePath, mode);
329+
}
330+
331+
@Override
332+
public void addWatch(String basePath, Watcher watcher, AddWatchMode mode, AsyncCallback.VoidCallback cb, Object ctx) {
333+
zk.addWatch(basePath, watcher, mode, cb, ctx);
334+
}
335+
336+
@Override
337+
public void addWatch(String basePath, AddWatchMode mode, AsyncCallback.VoidCallback cb, Object ctx) {
338+
zk.addWatch(basePath, mode, cb, ctx);
339+
}
340+
341+
@Override
342+
public Transaction transaction() {
343+
return zk.transaction();
344+
}
345+
346+
@Override
347+
public List<ClientInfo> whoAmI() throws InterruptedException {
348+
return zk.whoAmI();
349+
}
350+
351+
@Override
352+
public void close() throws InterruptedException {
353+
zk.close();
354+
}
355+
356+
@Override
357+
public boolean close(int waitForShutdownTimeoutMs) throws InterruptedException {
358+
return zk.close(waitForShutdownTimeoutMs);
359+
}
360+
361+
@Override
362+
public String toString() {
363+
return zk.toString();
364+
}
365+
}

0 commit comments

Comments
 (0)