View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.omid.tso;
19  
20  import org.apache.phoenix.thirdparty.com.google.common.base.MoreObjects;
21  import org.apache.phoenix.thirdparty.com.google.common.base.Optional;
22  import org.jboss.netty.channel.Channel;
23  
24  public final class PersistEvent {
25  
26      private MonitoringContext monCtx;
27  
28      enum Type {
29          TIMESTAMP, COMMIT, ABORT, COMMIT_RETRY, FENCE
30      }
31  
32      private Type type = null;
33      private Channel channel = null;
34  
35      private long startTimestamp = 0L;
36      private long commitTimestamp = 0L;
37      private Optional<Long> newLowWatermark;
38  
39      void makePersistCommit(long startTimestamp, long commitTimestamp, Optional<Long> newLowWatermark, Channel c, MonitoringContext monCtx) {
40  
41          this.type = Type.COMMIT;
42          this.startTimestamp = startTimestamp;
43          this.commitTimestamp = commitTimestamp;
44          this.channel = c;
45          this.monCtx = monCtx;
46          this.newLowWatermark = newLowWatermark;
47      }
48  
49      void makeCommitRetry(long startTimestamp, Channel c, MonitoringContext monCtx) {
50  
51          this.type = Type.COMMIT_RETRY;
52          this.startTimestamp = startTimestamp;
53          this.channel = c;
54          this.monCtx = monCtx;
55  
56      }
57  
58      void makePersistAbort(long startTimestamp, Channel c, MonitoringContext monCtx) {
59  
60          this.type = Type.ABORT;
61          this.startTimestamp = startTimestamp;
62          this.channel = c;
63          this.monCtx = monCtx;
64  
65      }
66  
67      void makePersistTimestamp(long startTimestamp, Channel c, MonitoringContext monCtx) {
68  
69          this.type = Type.TIMESTAMP;
70          this.startTimestamp = startTimestamp;
71          this.channel = c;
72          this.monCtx = monCtx;
73  
74      }
75  
76      void makePersistFence(long tableID, long fenceTimestamp, Channel c, MonitoringContext monCtx) {
77  
78          this.type = Type.FENCE;
79          this.startTimestamp = tableID;
80          this.commitTimestamp = fenceTimestamp;
81          this.channel = c;
82          this.monCtx = monCtx;
83  
84      }
85  
86      MonitoringContext getMonCtx() {
87  
88          return monCtx;
89  
90      }
91  
92      Type getType() {
93  
94          return type;
95  
96      }
97  
98      Channel getChannel() {
99  
100         return channel;
101 
102     }
103 
104     long getStartTimestamp() {
105 
106         return startTimestamp;
107 
108     }
109 
110     long getCommitTimestamp() {
111 
112         return commitTimestamp;
113 
114     }
115 
116     public Optional<Long> getNewLowWatermark() {
117         return newLowWatermark;
118     }
119 
120     @Override
121     public String toString() {
122         return MoreObjects.toStringHelper(this)
123                 .add("type", type)
124                 .add("ST", startTimestamp)
125                 .add("CT", commitTimestamp)
126                 .toString();
127     }
128 
129 }