Clean up Datastore addressing
[mdsal.git] / binding / mdsal-binding-util / src / main / java / org / opendaylight / mdsal / binding / util / WriteTrackingTypedReadWriteTransactionImpl.java
1 /*
2  * Copyright © 2018 Red Hat, Inc. and others.
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.binding.util;
9
10 import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
11
12 /**
13  * Read-write typed transaction which keeps track of writes.
14  */
15 final class WriteTrackingTypedReadWriteTransactionImpl<D extends Datastore> extends TypedReadWriteTransactionImpl<D>
16         implements WriteTrackingTransaction {
17
18     // This is volatile to ensure we get the latest value; transactions aren't supposed to be used in multiple threads,
19     // but the cost here is tiny (one read penalty at the end of a transaction) so we play it safe
20     private volatile boolean written;
21
22     WriteTrackingTypedReadWriteTransactionImpl(final D datastore, final ReadWriteTransaction realTx) {
23         super(datastore, realTx);
24     }
25
26     @Override
27     public boolean isWritten() {
28         return written;
29     }
30
31     @Override
32     void postOperation() {
33         written = true;
34     }
35 }