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 com.google.common.base.Objects;
21  import org.jboss.netty.channel.Channel;
22  
23  public final class PersistEvent {
24  
25      private MonitoringContext monCtx;
26  
27      enum Type {
28          TIMESTAMP, COMMIT, ABORT, COMMIT_RETRY, FENCE
29      }
30  
31      private Type type = null;
32      private Channel channel = null;
33  
34      private long startTimestamp = 0L;
35      private long commitTimestamp = 0L;
36  
37      void makePersistCommit(long startTimestamp, long commitTimestamp, Channel c, MonitoringContext monCtx) {
38  
39          this.type = Type.COMMIT;
40          this.startTimestamp = startTimestamp;
41          this.commitTimestamp = commitTimestamp;
42          this.channel = c;
43          this.monCtx = monCtx;
44  
45      }
46  
47      void makeCommitRetry(long startTimestamp, Channel c, MonitoringContext monCtx) {
48  
49          this.type = Type.COMMIT_RETRY;
50          this.startTimestamp = startTimestamp;
51          this.channel = c;
52          this.monCtx = monCtx;
53  
54      }
55  
56      void makePersistAbort(long startTimestamp, Channel c, MonitoringContext monCtx) {
57  
58          this.type = Type.ABORT;
59          this.startTimestamp = startTimestamp;
60          this.channel = c;
61          this.monCtx = monCtx;
62  
63      }
64  
65      void makePersistTimestamp(long startTimestamp, Channel c, MonitoringContext monCtx) {
66  
67          this.type = Type.TIMESTAMP;
68          this.startTimestamp = startTimestamp;
69          this.channel = c;
70          this.monCtx = monCtx;
71  
72      }
73  
74      void makePersistFence(long tableID, long fenceTimestamp, Channel c, MonitoringContext monCtx) {
75  
76          this.type = Type.FENCE;
77          this.startTimestamp = tableID;
78          this.commitTimestamp = fenceTimestamp;
79          this.channel = c;
80          this.monCtx = monCtx;
81  
82      }
83  
84      MonitoringContext getMonCtx() {
85  
86          return monCtx;
87  
88      }
89  
90      Type getType() {
91  
92          return type;
93  
94      }
95  
96      Channel getChannel() {
97  
98          return channel;
99  
100     }
101 
102     long getStartTimestamp() {
103 
104         return startTimestamp;
105 
106     }
107 
108     long getCommitTimestamp() {
109 
110         return commitTimestamp;
111 
112     }
113 
114     @Override
115     public String toString() {
116         return Objects.toStringHelper(this)
117                 .add("type", type)
118                 .add("ST", startTimestamp)
119                 .add("CT", commitTimestamp)
120                 .toString();
121     }
122 
123 }