@@ -118,12 +118,12 @@ public String putIfAbsent(String key, String value) {
118
118
createNode (key , value );
119
119
return null ;
120
120
}
121
- catch (KeeperException .NodeExistsException e ) {
121
+ catch (KeeperException .NodeExistsException ex ) {
122
122
// so the data actually exists, we can read it
123
123
return get (key );
124
124
}
125
- catch (Exception e ) {
126
- throw new ZookeeperMetadataStoreException ("Error while trying to set '" + key + "':" , e );
125
+ catch (Exception ex ) {
126
+ throw new ZookeeperMetadataStoreException ("Error while trying to set '" + key + "':" , ex );
127
127
}
128
128
}
129
129
}
@@ -142,13 +142,13 @@ public boolean replace(String key, String oldValue, String newValue) {
142
142
}
143
143
return true ;
144
144
}
145
- catch (KeeperException .NoNodeException | KeeperException .BadVersionException e ) {
145
+ catch (KeeperException .NoNodeException | KeeperException .BadVersionException ex ) {
146
146
// ignore, the node doesn't exist there's nothing to replace
147
147
return false ;
148
148
}
149
149
// ignore
150
- catch (Exception e ) {
151
- throw new ZookeeperMetadataStoreException ("Cannot replace value" , e );
150
+ catch (Exception ex ) {
151
+ throw new ZookeeperMetadataStoreException ("Cannot replace value" , ex );
152
152
}
153
153
}
154
154
}
@@ -183,8 +183,8 @@ public void put(String key, String value) {
183
183
updateNode (key , value , -1 );
184
184
}
185
185
}
186
- catch (Exception e ) {
187
- throw new ZookeeperMetadataStoreException ("Error while setting value for key '" + key + "':" , e );
186
+ catch (Exception ex ) {
187
+ throw new ZookeeperMetadataStoreException ("Error while setting value for key '" + key + "':" , ex );
188
188
}
189
189
}
190
190
}
@@ -198,17 +198,17 @@ public String get(String key) {
198
198
.map (currentData -> {
199
199
// our version is more recent than the cache
200
200
if (this .updateMap .containsKey (key ) &&
201
- this .updateMap .get (key ).getVersion () >= currentData .getStat ().getVersion ()) {
201
+ this .updateMap .get (key ).version () >= currentData .getStat ().getVersion ()) {
202
202
203
- return this .updateMap .get (key ).getValue ();
203
+ return this .updateMap .get (key ).value ();
204
204
}
205
205
return IntegrationUtils .bytesToString (currentData .getData (), this .encoding );
206
206
})
207
207
.orElseGet (() -> {
208
208
if (this .updateMap .containsKey (key )) {
209
209
// we have saved the value, but the cache hasn't updated yet
210
210
// if the value had changed via replication, we would have been notified by the listener
211
- return this .updateMap .get (key ).getValue ();
211
+ return this .updateMap .get (key ).value ();
212
212
}
213
213
else {
214
214
// the value just doesn't exist
@@ -229,12 +229,12 @@ public String remove(String key) {
229
229
this .updateMap .put (key , new LocalChildData (null , Integer .MAX_VALUE ));
230
230
return IntegrationUtils .bytesToString (bytes , this .encoding );
231
231
}
232
- catch (KeeperException .NoNodeException e ) {
232
+ catch (KeeperException .NoNodeException ex ) {
233
233
// ignore - the node doesn't exist
234
234
return null ;
235
235
}
236
- catch (Exception e ) {
237
- throw new ZookeeperMetadataStoreException ("Exception while deleting key '" + key + "'" , e );
236
+ catch (Exception ex ) {
237
+ throw new ZookeeperMetadataStoreException ("Exception while deleting key '" + key + "'" , ex );
238
238
}
239
239
}
240
240
}
@@ -254,7 +254,6 @@ public String getPath(String key) {
254
254
return "" .equals (key ) ? this .root : this .root + '/' + key ;
255
255
}
256
256
257
-
258
257
@ Override
259
258
public boolean isAutoStartup () {
260
259
return this .autoStartup ;
@@ -268,14 +267,14 @@ public synchronized void start() {
268
267
.creatingParentContainersIfNeeded ()
269
268
.forPath (this .root );
270
269
270
+ this .client .createContainers (this .root );
271
271
this .cache = CuratorCache .builder (this .client , this .root ).build ();
272
272
this .cache .listenable ().addListener (new MetadataStoreCacheListener ());
273
- this .client .createContainers (this .root );
274
273
this .cache .start ();
275
274
this .running = true ;
276
275
}
277
- catch (Exception e ) {
278
- throw new ZookeeperMetadataStoreException ("Exception while starting bean" , e );
276
+ catch (Exception ex ) {
277
+ throw new ZookeeperMetadataStoreException ("Exception while starting bean" , ex );
279
278
}
280
279
}
281
280
}
@@ -306,24 +305,7 @@ private String getKey(String path) {
306
305
}
307
306
308
307
309
- private static final class LocalChildData {
310
-
311
- private final String value ;
312
-
313
- private final int version ;
314
-
315
- LocalChildData (String value , int version ) {
316
- this .value = value ;
317
- this .version = version ;
318
- }
319
-
320
- private String getValue () {
321
- return this .value ;
322
- }
323
-
324
- private int getVersion () {
325
- return this .version ;
326
- }
308
+ private record LocalChildData (String value , int version ) {
327
309
328
310
}
329
311
@@ -343,7 +325,7 @@ public void event(Type type, ChildData oldData, ChildData newData) {
343
325
case NODE_CREATED :
344
326
if (ZookeeperMetadataStore .this .updateMap .containsKey (eventKey ) &&
345
327
data .getStat ().getVersion () >=
346
- ZookeeperMetadataStore .this .updateMap .get (eventKey ).getVersion ()) {
328
+ ZookeeperMetadataStore .this .updateMap .get (eventKey ).version ()) {
347
329
348
330
ZookeeperMetadataStore .this .updateMap .remove (eventPath );
349
331
}
@@ -352,7 +334,7 @@ public void event(Type type, ChildData oldData, ChildData newData) {
352
334
case NODE_CHANGED :
353
335
if (ZookeeperMetadataStore .this .updateMap .containsKey (eventKey ) &&
354
336
data .getStat ().getVersion () >=
355
- ZookeeperMetadataStore .this .updateMap .get (eventKey ).getVersion ()) {
337
+ ZookeeperMetadataStore .this .updateMap .get (eventKey ).version ()) {
356
338
357
339
ZookeeperMetadataStore .this .updateMap .remove (eventPath );
358
340
}
0 commit comments