Clean up Datastore addressing
[mdsal.git] / binding / mdsal-binding-util / src / main / java / org / opendaylight / mdsal / binding / util / WriteTrackingTypedWriteTransactionImpl.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.WriteTransaction;
11
12 /**
13  * Write typed transaction which keeps track of writes.
14  */
15 final class WriteTrackingTypedWriteTransactionImpl<D extends Datastore>
16         extends TypedWriteTransactionImpl<D, WriteTransaction> 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     WriteTrackingTypedWriteTransactionImpl(final D datastore, final WriteTransaction 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 }