Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.store.service; |
| 17 | |
| 18 | import java.util.List; |
| 19 | |
| 20 | /** |
| 21 | * An immutable transaction object. |
| 22 | */ |
| 23 | public interface Transaction { |
| 24 | |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 25 | enum State { |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 26 | /** |
| 27 | * Indicates a new transaction that is about to be prepared. All transactions |
| 28 | * start their life in this state. |
| 29 | */ |
| 30 | PREPARING, |
| 31 | |
| 32 | /** |
| 33 | * Indicates a transaction that is successfully prepared i.e. all participants voted to commit |
| 34 | */ |
| 35 | PREPARED, |
| 36 | |
| 37 | /** |
| 38 | * Indicates a transaction that is about to be committed. |
| 39 | */ |
| 40 | COMMITTING, |
| 41 | |
| 42 | /** |
| 43 | * Indicates a transaction that has successfully committed. |
| 44 | */ |
| 45 | COMMITTED, |
| 46 | |
| 47 | /** |
| 48 | * Indicates a transaction that is about to be rolled back. |
| 49 | */ |
| 50 | ROLLINGBACK, |
| 51 | |
| 52 | /** |
| 53 | * Indicates a transaction that has been rolled back and all locks are released. |
| 54 | */ |
| 55 | ROLLEDBACK |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Returns the transaction Id. |
| 60 | * |
| 61 | * @return transaction id |
| 62 | */ |
| 63 | long id(); |
| 64 | |
| 65 | /** |
| 66 | * Returns the list of updates that are part of this transaction. |
| 67 | * |
| 68 | * @return list of database updates |
| 69 | */ |
| 70 | List<DatabaseUpdate> updates(); |
| 71 | |
| 72 | /** |
| 73 | * Returns the current state of this transaction. |
| 74 | * |
| 75 | * @return transaction state |
| 76 | */ |
| 77 | State state(); |
| 78 | |
| 79 | /** |
| 80 | * Returns true if this transaction has completed execution. |
| 81 | * |
| 82 | * @return true is yes, false otherwise |
| 83 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 84 | default boolean isDone() { |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 85 | return state() == State.COMMITTED || state() == State.ROLLEDBACK; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Returns a new transaction that is created by transitioning this one to the specified state. |
| 90 | * |
| 91 | * @param newState destination state |
| 92 | * @return a new transaction instance similar to the current one but its state set to specified state |
| 93 | */ |
| 94 | Transaction transition(State newState); |
| 95 | |
| 96 | /** |
| 97 | * Returns the system time when the transaction was last updated. |
| 98 | * |
| 99 | * @return last update time |
| 100 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 101 | long lastUpdated(); |
| 102 | } |