1 /*
2 * Copyright 2020 TiKV Project Authors.
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 */
17
18 package org.tikv.txn;
19
20 public class TxnExpireTime {
21
22 private boolean initialized = false;
23 private long txnExpire = 0;
24
25 public TxnExpireTime() {}
26
27 public TxnExpireTime(boolean initialized, long txnExpire) {
28 this.initialized = initialized;
29 this.txnExpire = txnExpire;
30 }
31
32 public void update(long lockExpire) {
33 if (lockExpire < 0) {
34 lockExpire = 0;
35 }
36
37 if (!this.initialized) {
38 this.txnExpire = lockExpire;
39 this.initialized = true;
40 return;
41 }
42
43 if (lockExpire < this.txnExpire) {
44 this.txnExpire = lockExpire;
45 }
46 }
47
48 public long value() {
49 if (!this.initialized) {
50 return 0L;
51 } else {
52 return this.txnExpire;
53 }
54 }
55 }