d3cbdad9591785196354b22481378063f6d46a6d
[controller.git] / opendaylight / md-sal / sal-dom-spi / src / main / java / org / opendaylight / controller / md / sal / dom / spi / RegistrationTreeSnapshot.java
1 /**
2  * Copyright (c) 2015 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.md.sal.dom.spi;
9
10 import com.google.common.base.Preconditions;
11 import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
12 import java.util.concurrent.locks.Lock;
13
14 /**
15  * A stable read-only snapshot of a {@link AbstractRegistrationTree}.
16  *
17  * @author Robert Varga
18  *
19  * @deprecated Use {@link org.opendaylight.mdsal.dom.spi.RegistrationTreeSnapshot} instead.
20  */
21 @Deprecated
22 public final class RegistrationTreeSnapshot<T> implements AutoCloseable {
23     @SuppressWarnings("rawtypes")
24     private static final AtomicIntegerFieldUpdater<RegistrationTreeSnapshot> CLOSED_UPDATER =
25             AtomicIntegerFieldUpdater.newUpdater(RegistrationTreeSnapshot.class, "closed");
26     private final RegistrationTreeNode<T> node;
27     private final Lock lock;
28
29     // Used via CLOSED_UPDATER
30     @SuppressWarnings("unused")
31     private volatile int closed = 0;
32
33     RegistrationTreeSnapshot(final Lock lock, final RegistrationTreeNode<T> node) {
34         this.lock = Preconditions.checkNotNull(lock);
35         this.node = Preconditions.checkNotNull(node);
36     }
37
38     public RegistrationTreeNode<T> getRootNode() {
39         return node;
40     }
41
42     @Override
43     public void close() {
44         if (CLOSED_UPDATER.compareAndSet(this, 0, 1)) {
45             lock.unlock();
46         }
47     }
48 }