Clean up DOMRpcRouter registrations
[mdsal.git] / dom / mdsal-dom-spi / src / main / java / org / opendaylight / mdsal / 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.mdsal.dom.spi;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.util.concurrent.locks.Lock;
13 import org.eclipse.jdt.annotation.NonNullByDefault;
14 import org.opendaylight.yangtools.concepts.AbstractRegistration;
15
16 /**
17  * A stable read-only snapshot of a {@link AbstractRegistrationTree}.
18  *
19  * @author Robert Varga
20  */
21 @NonNullByDefault
22 public final class RegistrationTreeSnapshot<T> extends AbstractRegistration {
23     private final RegistrationTreeNode<T> node;
24     private final Lock lock;
25
26     RegistrationTreeSnapshot(final Lock lock, final RegistrationTreeNode<T> node) {
27         this.lock = requireNonNull(lock);
28         this.node = requireNonNull(node);
29     }
30
31     public RegistrationTreeNode<T> getRootNode() {
32         return node;
33     }
34
35     @Override
36     protected void removeRegistration() {
37         lock.unlock();
38     }
39 }