Remove yang-test
[controller.git] / opendaylight / config / config-manager / src / main / java / org / opendaylight / controller / config / manager / impl / TransactionStatus.java
1 /*
2  * Copyright (c) 2013 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.config.manager.impl;
9
10 import javax.annotation.concurrent.GuardedBy;
11
12 public class TransactionStatus {
13     @GuardedBy("this")
14     private boolean secondPhaseCommitStarted = false;
15     // switches to true during abort or commit failure
16     @GuardedBy("this")
17     private boolean aborted;
18     // switches to true during second phase commit
19     @GuardedBy("this")
20     private boolean committed;
21
22     public synchronized boolean isSecondPhaseCommitStarted() {
23         return secondPhaseCommitStarted;
24     }
25
26     synchronized void setSecondPhaseCommitStarted() {
27         this.secondPhaseCommitStarted = true;
28     }
29
30     public synchronized boolean isAborted() {
31         return aborted;
32     }
33
34     synchronized void setAborted() {
35         this.aborted = true;
36     }
37
38     public synchronized boolean isCommitted() {
39         return committed;
40     }
41
42     synchronized void setCommitted() {
43         this.committed = true;
44     }
45
46     public synchronized boolean isAbortedOrCommitted() {
47         return aborted || committed;
48     }
49
50     public synchronized void checkNotCommitStarted() {
51         if (secondPhaseCommitStarted) {
52             throw new IllegalStateException("Commit was triggered");
53         }
54     }
55
56     public synchronized void checkCommitStarted() {
57         if (!secondPhaseCommitStarted) {
58             throw new IllegalStateException("Commit was not triggered");
59         }
60     }
61
62     public synchronized void checkNotAborted() {
63         if (aborted) {
64             throw new IllegalStateException("Configuration was aborted");
65         }
66     }
67
68     public synchronized void checkNotCommitted() {
69         if (committed) {
70             throw new IllegalStateException(
71                     "Cannot use this method after second phase commit");
72         }
73     }
74
75     public synchronized void checkCommitted() {
76         if (!committed) {
77             throw new IllegalStateException(
78                     "Cannot use this method before second phase commit");
79         }
80     }
81 }