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
29      }
30  
31      private Type type = null;
32      private Channel channel = null;
33  
34      private boolean isRetry = false;
35      private long startTimestamp = 0L;
36      private long commitTimestamp = 0L;
37      private long lowWatermark = 0L;
38  
39      void makePersistCommit(long startTimestamp, long commitTimestamp, 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  
47      }
48  
49      void makePersistAbort(long startTimestamp, boolean isRetry, Channel c, MonitoringContext monCtx) {
50  
51          this.type = Type.ABORT;
52          this.startTimestamp = startTimestamp;
53          this.isRetry = isRetry;
54          this.channel = c;
55          this.monCtx = monCtx;
56  
57      }
58  
59      void makePersistTimestamp(long startTimestamp, Channel c, MonitoringContext monCtx) {
60  
61          this.type = Type.TIMESTAMP;
62          this.startTimestamp = startTimestamp;
63          this.channel = c;
64          this.monCtx = monCtx;
65  
66      }
67  
68      MonitoringContext getMonCtx() {
69  
70          return monCtx;
71  
72      }
73  
74      Type getType() {
75  
76          return type;
77  
78      }
79  
80      Channel getChannel() {
81  
82          return channel;
83  
84      }
85  
86      boolean isRetry() {
87  
88          return isRetry;
89  
90      }
91  
92      long getStartTimestamp() {
93  
94          return startTimestamp;
95  
96      }
97  
98      long getCommitTimestamp() {
99  
100         return commitTimestamp;
101 
102     }
103 
104     long getLowWatermark() {
105 
106         return lowWatermark;
107 
108     }
109 
110     @Override
111     public String toString() {
112         return Objects.toStringHelper(this)
113                 .add("type", type)
114                 .add("isRetry", isRetry)
115                 .add("ST", startTimestamp)
116                 .add("CT", commitTimestamp)
117                 .add("LWM", lowWatermark)
118                 .toString();
119     }
120 
121 }