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