X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fmd-sal%2Fcds-access-client%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Faccess%2Fclient%2FInversibleLockException.java;fp=opendaylight%2Fmd-sal%2Fcds-access-client%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Faccess%2Fclient%2FInversibleLockException.java;h=7ec18a265d20b412de826575fbc4c1c7670e4016;hb=320a4e5cd2d9d80468a3f82798744f2035488218;hp=0000000000000000000000000000000000000000;hpb=5fd8e6506248cc34da72281a1662612f6c2b2f9a;p=controller.git diff --git a/opendaylight/md-sal/cds-access-client/src/main/java/org/opendaylight/controller/cluster/access/client/InversibleLockException.java b/opendaylight/md-sal/cds-access-client/src/main/java/org/opendaylight/controller/cluster/access/client/InversibleLockException.java new file mode 100644 index 0000000000..7ec18a265d --- /dev/null +++ b/opendaylight/md-sal/cds-access-client/src/main/java/org/opendaylight/controller/cluster/access/client/InversibleLockException.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.cluster.access.client; + +import com.google.common.annotations.Beta; +import com.google.common.base.Preconditions; +import java.util.concurrent.CountDownLatch; + +/** + * Exception thrown from {@link InversibleLock#optimisticRead()} and can be used to wait for the racing write + * to complete using {@link #awaitResolution()}. + * + * @author Robert Varga + */ +@Beta +public final class InversibleLockException extends RuntimeException { + private static final long serialVersionUID = 1L; + + private final transient CountDownLatch latch; + + InversibleLockException(final CountDownLatch latch) { + this.latch = Preconditions.checkNotNull(latch); + } + + public void awaitResolution() { + // latch can be null after deserialization + if (latch != null) { + try { + latch.await(); + } catch (InterruptedException e) { + throw new IllegalStateException("Interrupted while waiting for latch " + latch, e); + } + } + } +}