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.client;
19  
20  import com.google.inject.Inject;
21  import com.google.inject.name.Named;
22  import org.apache.omid.YAMLUtils;
23  
24  /**
25   * Configuration for Omid client side
26   */
27  public class OmidClientConfiguration {
28  
29      private static final String DEFAULT_CONFIG_FILE_NAME = "omid-client-config.yml";
30  
31      public enum ConnType {DIRECT, HA}
32  
33      public enum PostCommitMode {SYNC, ASYNC}
34  
35      public enum ConflictDetectionLevel {CELL, ROW}
36  
37      // Basic connection related params
38  
39      private ConnType connectionType = ConnType.DIRECT;
40      private String connectionString;
41      private String zkCurrentTsoPath;
42      private String zkNamespace;
43      private int zkConnectionTimeoutInSecs;
44  
45      // Communication protocol related params
46  
47      private int requestMaxRetries;
48      private int requestTimeoutInMs;
49      private int reconnectionDelayInSecs;
50      private int retryDelayInMs;
51      private int executorThreads;
52  
53      // Transaction Manager related params
54  
55      private PostCommitMode postCommitMode = PostCommitMode.SYNC;
56      private ConflictDetectionLevel conflictAnalysisLevel = ConflictDetectionLevel.CELL;
57  
58      // ----------------------------------------------------------------------------------------------------------------
59      // Instantiation
60      // ----------------------------------------------------------------------------------------------------------------
61  
62      public OmidClientConfiguration() {
63          new YAMLUtils().loadSettings(DEFAULT_CONFIG_FILE_NAME, this);
64      }
65  
66      // ----------------------------------------------------------------------------------------------------------------
67      // Getters and setters for config params
68      // ----------------------------------------------------------------------------------------------------------------
69  
70      public ConnType getConnectionType() {
71          return connectionType;
72      }
73  
74      @Inject(optional = true)
75      @Named("omid.client.connectionType")
76      public void setConnectionType(ConnType connectionType) {
77          this.connectionType = connectionType;
78      }
79  
80      public String getConnectionString() {
81          return connectionString;
82      }
83  
84      @Inject(optional = true)
85      @Named("omid.client.connectionString")
86      public void setConnectionString(String connectionString) {
87          this.connectionString = connectionString;
88      }
89  
90      public int getZkConnectionTimeoutInSecs() {
91          return zkConnectionTimeoutInSecs;
92      }
93  
94      @Inject(optional = true)
95      @Named("omid.client.zkConnectionTimeoutInSecs")
96      public void setZkConnectionTimeoutInSecs(int zkConnectionTimeoutInSecs) {
97          this.zkConnectionTimeoutInSecs = zkConnectionTimeoutInSecs;
98      }
99  
100     public int getRequestMaxRetries() {
101         return requestMaxRetries;
102     }
103 
104     @Inject(optional = true)
105     @Named("omid.client.requestMaxRetries")
106     public void setRequestMaxRetries(int requestMaxRetries) {
107         this.requestMaxRetries = requestMaxRetries;
108     }
109 
110     public int getRequestTimeoutInMs() {
111         return requestTimeoutInMs;
112     }
113 
114     @Inject(optional = true)
115     @Named("omid.client.requestTimeoutInMs")
116     public void setRequestTimeoutInMs(int requestTimeoutInMs) {
117         this.requestTimeoutInMs = requestTimeoutInMs;
118     }
119 
120     public int getReconnectionDelayInSecs() {
121         return reconnectionDelayInSecs;
122     }
123 
124     @Inject(optional = true)
125     @Named("omid.client.reconnectionDelayInSecs")
126     public void setReconnectionDelayInSecs(int reconnectionDelayInSecs) {
127         this.reconnectionDelayInSecs = reconnectionDelayInSecs;
128     }
129 
130     public int getRetryDelayInMs() {
131         return retryDelayInMs;
132     }
133 
134     @Inject(optional = true)
135     @Named("omid.client.retryDelayInMs")
136     public void setRetryDelayInMs(int retryDelayInMs) {
137         this.retryDelayInMs = retryDelayInMs;
138     }
139 
140     public int getExecutorThreads() {
141         return executorThreads;
142     }
143 
144     @Inject(optional = true)
145     @Named("omid.client.executorThreads")
146     public void setExecutorThreads(int executorThreads) {
147         this.executorThreads = executorThreads;
148     }
149 
150     public String getZkCurrentTsoPath() {
151         return zkCurrentTsoPath;
152     }
153 
154     @Inject(optional = true)
155     @Named("omid.ha.zkCurrentTsoPath")
156     public void setZkCurrentTsoPath(String zkCurrentTsoPath) {
157         this.zkCurrentTsoPath = zkCurrentTsoPath;
158     }
159 
160     public String getZkNamespace() {
161         return zkNamespace;
162     }
163 
164     @Inject(optional = true)
165     @Named("omid.ha.zkNamespace")
166     public void setZkNamespace(String zkNamespace) {
167         this.zkNamespace = zkNamespace;
168     }
169 
170     public PostCommitMode getPostCommitMode() {
171         return postCommitMode;
172     }
173 
174     @Inject(optional = true)
175     @Named("omid.tm.postCommitMode")
176     public void setPostCommitMode(PostCommitMode postCommitMode) {
177         this.postCommitMode = postCommitMode;
178     }
179 
180     public ConflictDetectionLevel getConflictAnalysisLevel() {
181         return conflictAnalysisLevel;
182     }
183 
184     @Inject(optional = true)
185     @Named("omid.tm.conflictAnalysisLevel")
186     public void setConflictAnalysisLevel(ConflictDetectionLevel conflictAnalysisLevel) {
187         this.conflictAnalysisLevel = conflictAnalysisLevel;
188     }
189 }