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
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      MonitoringContext getMonCtx() {
75  
76          return monCtx;
77  
78      }
79  
80      Type getType() {
81  
82          return type;
83  
84      }
85  
86      Channel getChannel() {
87  
88          return channel;
89  
90      }
91  
92      long getStartTimestamp() {
93  
94          return startTimestamp;
95  
96      }
97  
98      long getCommitTimestamp() {
99  
100         return commitTimestamp;
101 
102     }
103 
104     @Override
105     public String toString() {
106         return Objects.toStringHelper(this)
107                 .add("type", type)
108                 .add("ST", startTimestamp)
109                 .add("CT", commitTimestamp)
110                 .toString();
111     }
112 
113 }