1 package org.apache.helix;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.util.List;
23
24 import org.I0Itec.zkclient.DataUpdater;
25 import org.I0Itec.zkclient.IZkChildListener;
26 import org.I0Itec.zkclient.IZkDataListener;
27 import org.apache.zookeeper.CreateMode;
28 import org.apache.zookeeper.data.Stat;
29
30 public interface BaseDataAccessor<T>
31 {
32 /**
33 * This will always attempt to create the znode, if it exists it will return false. Will
34 * create parents if they do not exist. For performance reasons, it may try to create
35 * child first and only if it fails it will try to create parent
36 *
37 * @param path
38 * @param record
39 * @return
40 */
41 boolean create(String path, T record, int options);
42
43 /**
44 * This will always attempt to set the data on existing node. If the znode does not
45 * exist it will create it.
46 *
47 * @param path
48 * @param record
49 * @param options Set the type of ZNode see the valid values in {@link AccessOption}
50 * @return
51 */
52 boolean set(String path, T record, int options);
53
54 /**
55 * This will attempt to merge with existing data by calling znrecord.merge and if it
56 * does not exist it will create it znode
57 *
58 * @param path
59 * @param record
60 * @param options Set the type of ZNode see the valid values in {@link AccessOption}
61 * @return
62 */
63 boolean update(String path, DataUpdater<T> updater, int options);
64
65 /**
66 * This will remove znode and all it's child nodes if any
67 *
68 * @param path
69 * @param options Set the type of ZNode see the valid values in {@link AccessOption}
70 * @return
71 */
72 boolean remove(String path, int options);
73
74 /**
75 * Use it when creating children under a parent node. This will use async api for better
76 * performance. If the child already exists it will return false.
77 *
78 * @param parentPath
79 * @param record
80 * @param options Set the type of ZNode see the valid values in {@link AccessOption}
81 * @return
82 */
83 boolean[] createChildren(List<String> paths, List<T> records, int options);
84
85 /**
86 * can set multiple children under a parent node. This will use async api for better
87 * performance. If this child does not exist it will create it.
88 *
89 * @param parentPath
90 * @param record
91 * @param options Set the type of ZNode see the valid values in {@link AccessOption}
92 */
93 boolean[] setChildren(List<String> paths, List<T> records, int options);
94
95 /**
96 * Can update multiple nodes using async api for better performance. If a child does not
97 * exist it will create it.
98 *
99 * @param parentPath
100 * @param record
101 * @param options Set the type of ZNode see the valid values in {@link AccessOption}
102 * @return
103 */
104 boolean[] updateChildren(List<String> paths, List<DataUpdater<T>> updaters, int options);
105
106 /**
107 * remove multiple paths using async api. will remove any child nodes if any
108 *
109 * @param paths
110 * @param options Set the type of ZNode see the valid values in {@link AccessOption}
111 * @return
112 */
113 boolean[] remove(List<String> paths, int options);
114
115 /**
116 * Get the {@link T} corresponding to the path
117 *
118 * @param path
119 * @param options Set the type of ZNode see the valid values in {@link AccessOption}
120 * @return
121 */
122 T get(String path, Stat stat, int options);
123
124 /**
125 * Get List of {@link T} corresponding to the paths using async api
126 *
127 * @param paths
128 * @param options Set the type of ZNode see the valid values in {@link AccessOption}
129 * @return
130 */
131 List<T> get(List<String> paths, List<Stat> stats, int options);
132
133 /**
134 * Get the children under a parent path using async api
135 *
136 * @param path
137 * @param options Set the type of ZNode see the valid values in {@link AccessOption}
138 * @return
139 */
140 List<T> getChildren(String parentPath, List<Stat> stats, int options);
141
142 /**
143 * Returns the child names given a parent path
144 *
145 * @param type
146 * @param keys
147 * @param options Set the type of ZNode see the valid values in {@link AccessOption}
148 * @return
149 */
150 List<String> getChildNames(String parentPath, int options);
151
152 /**
153 * checks if the path exists in zk
154 *
155 * @param path
156 * @param options Set the type of ZNode see the valid values in {@link AccessOption}
157 * @return
158 */
159 boolean exists(String path, int options);
160
161 /**
162 * checks if the all the paths exists
163 *
164 * @param paths
165 * @param options Set the type of ZNode see the valid values in {@link AccessOption}
166 * @return
167 */
168 boolean[] exists(List<String> paths, int options);
169
170 /**
171 * Get the stats of all the paths
172 *
173 * @param paths
174 * @param options Set the type of ZNode see the valid values in {@link AccessOption}
175 * @return
176 */
177 Stat[] getStats(List<String> paths, int options);
178
179 /**
180 * Get the stats of all the paths
181 *
182 * @param paths
183 * @param options Set the type of ZNode see the valid values in {@link AccessOption}
184 * @return
185 */
186 Stat getStat(String path, int options);
187
188 /**
189 * Subscribe data listener to path
190 *
191 * @param path
192 * @param listener
193 * @return
194 */
195 void subscribeDataChanges(String path, IZkDataListener listener);
196
197 /**
198 * Unsubscribe data listener to path
199 *
200 * @param path
201 * @param listener
202 */
203 void unsubscribeDataChanges(String path, IZkDataListener listener);
204
205 /**
206 * Subscribe child listener to path
207 *
208 * @param path
209 * @param listener
210 * @return
211 */
212 List<String> subscribeChildChanges(String path, IZkChildListener listener);
213
214 /**
215 * Unsubscribe child listener to path
216 *
217 * @param path
218 * @param listener
219 */
220 void unsubscribeChildChanges(String path, IZkChildListener listener);
221
222 /**
223 * reset the cache if any, when session expiry happens
224 */
225 void reset();
226 }