2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
10 import com.google.common.base.Preconditions;
11 import java.util.Arrays;
12 import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
15 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshotCursor;
17 abstract class AbstractCursor<T extends AbstractCursorAware> implements DataTreeSnapshotCursor {
18 @SuppressWarnings("rawtypes")
19 private static final AtomicIntegerFieldUpdater<AbstractCursor> CLOSED_UPDATER =
20 AtomicIntegerFieldUpdater.newUpdater(AbstractCursor.class, "closed");
21 private final YangInstanceIdentifier rootPath;
22 private final T parent;
23 private volatile int closed;
25 AbstractCursor(final T parent, final YangInstanceIdentifier rootPath) {
26 this.rootPath = Preconditions.checkNotNull(rootPath);
27 this.parent = Preconditions.checkNotNull(parent);
34 final YangInstanceIdentifier getRootPath() {
39 final void ensureNotClosed() {
40 Preconditions.checkState(closed == 0, "Modification cursor has been closed");
44 public final void enter(final PathArgument... path) {
45 enter(Arrays.asList(path));
49 public final void exit() {
54 public final void close() {
55 if (CLOSED_UPDATER.compareAndSet(this, 0, 1)) {
56 parent.closeCursor(this);