@@ -349,7 +349,7 @@ private ZcInterruptedException(InterruptedException e) {
349
349
* @return children list, or null if node has no children or does not exist
350
350
*/
351
351
public List <String > getChildren (final String zPath ) {
352
- Preconditions .checkState (!closed );
352
+ Preconditions .checkState (!closed , "Operation not allowed: ZooCache is already closed." );
353
353
ensureWatched (zPath );
354
354
ZooRunnable <List <String >> zr = new ZooRunnable <>() {
355
355
@@ -409,7 +409,7 @@ public byte[] get(final String zPath) {
409
409
* @return path data, or null if non-existent
410
410
*/
411
411
public byte [] get (final String zPath , final ZcStat status ) {
412
- Preconditions .checkState (!closed );
412
+ Preconditions .checkState (!closed , "Operation not allowed: ZooCache is already closed." );
413
413
ensureWatched (zPath );
414
414
ZooRunnable <byte []> zr = new ZooRunnable <>() {
415
415
@@ -474,7 +474,7 @@ public byte[] run() throws KeeperException, InterruptedException {
474
474
* @param cachedStat cached statistic, that is or will be cached
475
475
*/
476
476
protected void copyStats (ZcStat userStat , ZcStat cachedStat ) {
477
- Preconditions .checkState (!closed );
477
+ Preconditions .checkState (!closed , "Operation not allowed: ZooCache is already closed." );
478
478
if (userStat != null && cachedStat != null ) {
479
479
userStat .set (cachedStat );
480
480
}
@@ -484,13 +484,18 @@ protected void copyStats(ZcStat userStat, ZcStat cachedStat) {
484
484
* Clears this cache.
485
485
*/
486
486
protected void clear () {
487
- Preconditions .checkState (!closed );
487
+ if (closed ) {
488
+ return ;
489
+ }
488
490
nodeCache .clear ();
489
491
updateCount .incrementAndGet ();
490
492
log .trace ("{} cleared all from cache" , cacheId );
491
493
}
492
494
493
495
public void close () {
496
+ if (closed ) {
497
+ return ;
498
+ }
494
499
clear ();
495
500
closed = true ;
496
501
}
@@ -500,7 +505,7 @@ public void close() {
500
505
* count is the same, then it means cache did not change.
501
506
*/
502
507
public long getUpdateCount () {
503
- Preconditions .checkState (!closed );
508
+ Preconditions .checkState (!closed , "Operation not allowed: ZooCache is already closed." );
504
509
return updateCount .get ();
505
510
}
506
511
@@ -534,7 +539,7 @@ public boolean childrenCached(String zPath) {
534
539
* Removes all paths in the cache match the predicate.
535
540
*/
536
541
public void clear (Predicate <String > pathPredicate ) {
537
- Preconditions .checkState (!closed );
542
+ Preconditions .checkState (!closed , "Operation not allowed: ZooCache is already closed." );
538
543
Predicate <String > pathPredicateWrapper = path -> {
539
544
boolean testResult = pathPredicate .test (path );
540
545
if (testResult ) {
0 commit comments