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.timestamp.storage;
19
20 import com.google.inject.AbstractModule;
21 import com.google.inject.Provides;
22 import org.apache.curator.framework.CuratorFramework;
23 import org.apache.omid.zk.ZKUtils;
24
25 import javax.inject.Singleton;
26 import java.io.IOException;
27
28 //TODO:IK: move to common?
29 public class ZKModule extends AbstractModule {
30
31 private final String zkCluster;
32 private final String namespace;
33
34 public ZKModule(String zkCluster, String namespace) {
35 this.zkCluster = zkCluster;
36 this.namespace = namespace;
37 }
38
39 @Override
40 public void configure() {
41 }
42
43 @Provides
44 @Singleton
45 CuratorFramework provideInitializedZookeeperClient() throws IOException {
46 return ZKUtils.initZKClient(zkCluster, namespace, 10);
47 }
48
49 // ----------------------------------------------------------------------------------------------------------------
50 // NOTE: We need to implement equals() and hashCode() because the ZKModule is installed from several parent modules
51 // ----------------------------------------------------------------------------------------------------------------
52
53 @Override
54 public boolean equals(Object o) {
55
56 if (this == o) return true;
57 if (o == null || getClass() != o.getClass()) return false;
58
59 ZKModule zkModule = (ZKModule) o;
60
61 if (!zkCluster.equals(zkModule.zkCluster)) return false;
62 return namespace.equals(zkModule.namespace);
63
64 }
65
66 @Override
67 public int hashCode() {
68
69 int result = zkCluster.hashCode();
70 result = 31 * result + namespace.hashCode();
71 return result;
72
73 }
74
75 }