Skip to content

Commit 902d71c

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 902d71c

File tree

7 files changed

+1670
-23
lines changed

7 files changed

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

0 commit comments

Comments
 (0)