Improve segmented journal actor metrics
[controller.git] / opendaylight / md-sal / cds-access-client / src / main / java / org / opendaylight / controller / cluster / access / client / InversibleLockException.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.cluster.access.client;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.Beta;
13 import java.util.concurrent.CountDownLatch;
14
15 /**
16  * Exception thrown from {@link InversibleLock#optimisticRead()} and can be used to wait for the racing write
17  * to complete using {@link #awaitResolution()}.
18  *
19  * @author Robert Varga
20  */
21 @Beta
22 public final class InversibleLockException extends RuntimeException {
23     private static final long serialVersionUID = 1L;
24
25     private final transient CountDownLatch latch;
26
27     InversibleLockException(final CountDownLatch latch) {
28         this.latch = requireNonNull(latch);
29     }
30
31     public void awaitResolution() {
32         // latch can be null after deserialization
33         if (latch != null) {
34             try {
35                 latch.await();
36             } catch (InterruptedException e) {
37                 throw new IllegalStateException("Interrupted while waiting for latch " + latch, e);
38             }
39         }
40     }
41 }