Exception for URI /restconf/operations/module_name:rpc ended with slash
[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 == true)
52             throw new IllegalStateException("Commit was triggered");
53     }
54
55     public synchronized void checkCommitStarted() {
56         if (secondPhaseCommitStarted == false)
57             throw new IllegalStateException("Commit was not triggered");
58     }
59
60     public synchronized void checkNotAborted() {
61         if (aborted == true)
62             throw new IllegalStateException("Configuration was aborted");
63     }
64
65     public synchronized void checkNotCommitted() {
66         if (committed == true) {
67             throw new IllegalStateException(
68                     "Cannot use this method after second phase commit");
69         }
70     }
71
72     public synchronized void checkCommitted() {
73         if (committed == false) {
74             throw new IllegalStateException(
75                     "Cannot use this method before second phase commit");
76         }
77     }
78 }