Skip to content

Commit c0b40d1

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 8b13615 commit c0b40d1

File tree

7 files changed

+1669
-23
lines changed

7 files changed

+1669
-23
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
@@ -1242,8 +1242,6 @@ public int getSessionTimeout() {
12421242
/**
12431243
* Add the specified scheme:auth information to this connection.
12441244
*
1245-
* This method is NOT thread safe
1246-
*
12471245
* @param scheme
12481246
* @param auth
12491247
*/

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: 361 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,361 @@
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+
class ZooKeeperAdaptor implements ZooKeeper {
36+
private final org.apache.zookeeper.ZooKeeper zk;
37+
38+
ZooKeeperAdaptor(org.apache.zookeeper.ZooKeeper zk) {
39+
this.zk = zk;
40+
}
41+
42+
@Override
43+
public long getSessionId() {
44+
return zk.getSessionId();
45+
}
46+
47+
@Override
48+
public byte[] getSessionPasswd() {
49+
return zk.getSessionPasswd();
50+
}
51+
52+
@Override
53+
public int getSessionTimeout() {
54+
return zk.getSessionTimeout();
55+
}
56+
57+
@Override
58+
public ZKClientConfig getClientConfig() {
59+
return zk.getClientConfig();
60+
}
61+
62+
@Override
63+
public void register(Watcher watcher) {
64+
zk.register(watcher);
65+
}
66+
67+
@Override
68+
public void updateServerList(String connectString) throws IOException {
69+
zk.updateServerList(connectString);
70+
}
71+
72+
@Override
73+
public Stat exists(String path, boolean watch) throws KeeperException, InterruptedException {
74+
return zk.exists(path, watch);
75+
}
76+
77+
@Override
78+
public Stat exists(String path, Watcher watcher) throws KeeperException, InterruptedException {
79+
return zk.exists(path, watcher);
80+
}
81+
82+
@Override
83+
public void exists(String path, boolean watch, AsyncCallback.StatCallback cb, Object ctx) {
84+
zk.exists(path, watch, cb, ctx);
85+
}
86+
87+
@Override
88+
public void exists(String path, Watcher watcher, AsyncCallback.StatCallback cb, Object ctx) {
89+
zk.exists(path, watcher, cb, ctx);
90+
}
91+
92+
@Override
93+
public String create(String path, byte[] data, List<ACL> acl, CreateMode createMode) throws KeeperException, InterruptedException {
94+
return zk.create(path, data, acl, createMode);
95+
}
96+
97+
@Override
98+
public String create(String path, byte[] data, List<ACL> acl, CreateMode createMode, Stat stat) throws KeeperException, InterruptedException {
99+
return zk.create(path, data, acl, createMode, stat);
100+
}
101+
102+
@Override
103+
public String create(String path, byte[] data, List<ACL> acl, CreateMode createMode, Stat stat, long ttl) throws KeeperException, InterruptedException {
104+
return zk.create(path, data, acl, createMode, stat, ttl);
105+
}
106+
107+
@Override
108+
public void addAuthInfo(String scheme, byte[] auth) {
109+
zk.addAuthInfo(scheme, auth);
110+
}
111+
112+
@Override
113+
public void create(String path, byte[] data, List<ACL> acl, CreateMode createMode, AsyncCallback.StringCallback cb, Object ctx) {
114+
zk.create(path, data, acl, createMode, cb, ctx);
115+
}
116+
117+
@Override
118+
public void create(String path, byte[] data, List<ACL> acl, CreateMode createMode, AsyncCallback.Create2Callback cb, Object ctx) {
119+
zk.create(path, data, acl, createMode, cb, ctx);
120+
}
121+
122+
@Override
123+
public void create(String path, byte[] data, List<ACL> acl, CreateMode createMode, AsyncCallback.Create2Callback cb, Object ctx, long ttl) {
124+
zk.create(path, data, acl, createMode, cb, ctx, ttl);
125+
}
126+
127+
@Override
128+
public void delete(String path, int version) throws InterruptedException, KeeperException {
129+
zk.delete(path, version);
130+
}
131+
132+
@Override
133+
public void delete(String path, int version, AsyncCallback.VoidCallback cb, Object ctx) {
134+
zk.delete(path, version, cb, ctx);
135+
}
136+
137+
@Override
138+
public List<OpResult> multi(Iterable<Op> ops) throws InterruptedException, KeeperException {
139+
return zk.multi(ops);
140+
}
141+
142+
@Override
143+
public void multi(Iterable<Op> ops, AsyncCallback.MultiCallback cb, Object ctx) {
144+
zk.multi(ops, cb, ctx);
145+
}
146+
147+
@Override
148+
public byte[] getData(String path, boolean watch, Stat stat) throws KeeperException, InterruptedException {
149+
return zk.getData(path, watch, stat);
150+
}
151+
152+
@Override
153+
public byte[] getData(String path, Watcher watcher, Stat stat) throws KeeperException, InterruptedException {
154+
return zk.getData(path, watcher, stat);
155+
}
156+
157+
@Override
158+
public void getData(String path, boolean watch, AsyncCallback.DataCallback cb, Object ctx) {
159+
zk.getData(path, watch, cb, ctx);
160+
}
161+
162+
@Override
163+
public void getData(String path, Watcher watcher, AsyncCallback.DataCallback cb, Object ctx) {
164+
zk.getData(path, watcher, cb, ctx);
165+
}
166+
167+
@Override
168+
public byte[] getConfig(boolean watch, Stat stat) throws KeeperException, InterruptedException {
169+
return zk.getConfig(watch, stat);
170+
}
171+
172+
@Override
173+
public byte[] getConfig(Watcher watcher, Stat stat) throws KeeperException, InterruptedException {
174+
return zk.getConfig(watcher, stat);
175+
}
176+
177+
@Override
178+
public void getConfig(boolean watch, AsyncCallback.DataCallback cb, Object ctx) {
179+
zk.getConfig(watch, cb, ctx);
180+
}
181+
182+
@Override
183+
public void getConfig(Watcher watcher, AsyncCallback.DataCallback cb, Object ctx) {
184+
zk.getConfig(watcher, cb, ctx);
185+
}
186+
187+
@Override
188+
public Stat setData(String path, byte[] data, int version) throws KeeperException, InterruptedException {
189+
return zk.setData(path, data, version);
190+
}
191+
192+
@Override
193+
public void setData(String path, byte[] data, int version, AsyncCallback.StatCallback cb, Object ctx) {
194+
zk.setData(path, data, version, cb, ctx);
195+
}
196+
197+
@Override
198+
public List<ACL> getACL(String path, Stat stat) throws KeeperException, InterruptedException {
199+
return zk.getACL(path, stat);
200+
}
201+
202+
@Override
203+
public void getACL(String path, Stat stat, AsyncCallback.ACLCallback cb, Object ctx) {
204+
zk.getACL(path, stat, cb, ctx);
205+
}
206+
207+
@Override
208+
public Stat setACL(String path, List<ACL> acl, int aclVersion) throws KeeperException, InterruptedException {
209+
return zk.setACL(path, acl, aclVersion);
210+
}
211+
212+
@Override
213+
public void setACL(String path, List<ACL> acl, int version, AsyncCallback.StatCallback cb, Object ctx) {
214+
zk.setACL(path, acl, version, cb, ctx);
215+
}
216+
217+
@Override
218+
public List<String> getChildren(String path, boolean watch) throws KeeperException, InterruptedException {
219+
return zk.getChildren(path, watch);
220+
}
221+
222+
@Override
223+
public List<String> getChildren(String path, Watcher watcher) throws KeeperException, InterruptedException {
224+
return zk.getChildren(path, watcher);
225+
}
226+
227+
@Override
228+
public List<String> getChildren(String path, boolean watch, Stat stat) throws KeeperException, InterruptedException {
229+
return zk.getChildren(path, watch, stat);
230+
}
231+
232+
@Override
233+
public List<String> getChildren(String path, Watcher watcher, Stat stat) throws KeeperException, InterruptedException {
234+
return zk.getChildren(path, watcher, stat);
235+
}
236+
237+
@Override
238+
public void getChildren(String path, boolean watch, AsyncCallback.ChildrenCallback cb, Object ctx) {
239+
zk.getChildren(path, watch, cb, ctx);
240+
}
241+
242+
@Override
243+
public void getChildren(String path, boolean watch, AsyncCallback.Children2Callback cb, Object ctx) {
244+
zk.getChildren(path, watch, cb, ctx);
245+
}
246+
247+
@Override
248+
public void getChildren(String path, Watcher watcher, AsyncCallback.ChildrenCallback cb, Object ctx) {
249+
zk.getChildren(path, watcher, cb, ctx);
250+
}
251+
252+
@Override
253+
public void getChildren(String path, Watcher watcher, AsyncCallback.Children2Callback cb, Object ctx) {
254+
zk.getChildren(path, watcher, cb, ctx);
255+
}
256+
257+
@Override
258+
public int getAllChildrenNumber(String path) throws KeeperException, InterruptedException {
259+
return zk.getAllChildrenNumber(path);
260+
}
261+
262+
@Override
263+
public void getAllChildrenNumber(String path, AsyncCallback.AllChildrenNumberCallback cb, Object ctx) {
264+
zk.getAllChildrenNumber(path, cb, ctx);
265+
}
266+
267+
@Override
268+
public List<String> getEphemerals() throws KeeperException, InterruptedException {
269+
return zk.getEphemerals();
270+
}
271+
272+
@Override
273+
public List<String> getEphemerals(String prefixPath) throws KeeperException, InterruptedException {
274+
return zk.getEphemerals(prefixPath);
275+
}
276+
277+
@Override
278+
public void getEphemerals(AsyncCallback.EphemeralsCallback cb, Object ctx) {
279+
zk.getEphemerals(cb, ctx);
280+
}
281+
282+
@Override
283+
public void getEphemerals(String prefixPath, AsyncCallback.EphemeralsCallback cb, Object ctx) {
284+
zk.getEphemerals(prefixPath, cb, ctx);
285+
}
286+
287+
@Override
288+
public void sync(String path) throws KeeperException, InterruptedException {
289+
zk.sync(path);
290+
}
291+
292+
@Override
293+
public void sync(String path, AsyncCallback.VoidCallback cb, Object ctx) {
294+
zk.sync(path, cb, ctx);
295+
}
296+
297+
@Override
298+
public void removeWatches(String path, Watcher watcher, Watcher.WatcherType watcherType, boolean local) throws InterruptedException, KeeperException {
299+
zk.removeWatches(path, watcher, watcherType, local);
300+
}
301+
302+
@Override
303+
public void removeWatches(String path, Watcher watcher, Watcher.WatcherType watcherType, boolean local, AsyncCallback.VoidCallback cb, Object ctx) {
304+
zk.removeWatches(path, watcher, watcherType, local, cb, ctx);
305+
}
306+
307+
@Override
308+
public void removeAllWatches(String path, Watcher.WatcherType watcherType, boolean local) throws InterruptedException, KeeperException {
309+
zk.removeAllWatches(path, watcherType, local);
310+
}
311+
312+
@Override
313+
public void removeAllWatches(String path, Watcher.WatcherType watcherType, boolean local, AsyncCallback.VoidCallback cb, Object ctx) {
314+
zk.removeAllWatches(path, watcherType, local, cb, ctx);
315+
}
316+
317+
@Override
318+
public void addWatch(String basePath, Watcher watcher, AddWatchMode mode) throws KeeperException, InterruptedException {
319+
zk.addWatch(basePath, watcher, mode);
320+
}
321+
322+
@Override
323+
public void addWatch(String basePath, AddWatchMode mode) throws KeeperException, InterruptedException {
324+
zk.addWatch(basePath, mode);
325+
}
326+
327+
@Override
328+
public void addWatch(String basePath, Watcher watcher, AddWatchMode mode, AsyncCallback.VoidCallback cb, Object ctx) {
329+
zk.addWatch(basePath, watcher, mode, cb, ctx);
330+
}
331+
332+
@Override
333+
public void addWatch(String basePath, AddWatchMode mode, AsyncCallback.VoidCallback cb, Object ctx) {
334+
zk.addWatch(basePath, mode, cb, ctx);
335+
}
336+
337+
@Override
338+
public Transaction transaction() {
339+
return zk.transaction();
340+
}
341+
342+
@Override
343+
public List<ClientInfo> whoAmI() throws InterruptedException {
344+
return zk.whoAmI();
345+
}
346+
347+
@Override
348+
public void close() throws InterruptedException {
349+
zk.close();
350+
}
351+
352+
@Override
353+
public boolean close(int waitForShutdownTimeoutMs) throws InterruptedException {
354+
return zk.close(waitForShutdownTimeoutMs);
355+
}
356+
357+
@Override
358+
public String toString() {
359+
return zk.toString();
360+
}
361+
}

0 commit comments

Comments
 (0)