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.transaction;
19  
20  import com.google.common.base.Preconditions;
21  import com.google.inject.AbstractModule;
22  import com.google.inject.Provider;
23  import com.google.inject.Provides;
24  import org.apache.omid.committable.CommitTable;
25  import org.apache.omid.committable.hbase.HBaseCommitTable;
26  import org.apache.omid.metrics.MetricsRegistry;
27  import org.apache.omid.metrics.NullMetricsProvider;
28  import org.apache.omid.timestamp.storage.HBaseTimestampStorage;
29  import org.apache.omid.timestamp.storage.TimestampStorage;
30  import org.apache.omid.tso.BatchPoolModule;
31  import org.apache.omid.tso.DisruptorModule;
32  import org.apache.omid.tso.RuntimeExceptionPanicker;
33  import org.apache.omid.tso.NetworkInterfaceUtils;
34  import org.apache.omid.tso.Panicker;
35  import org.apache.omid.tso.PausableTimestampOracle;
36  import org.apache.omid.tso.PersistenceProcessorHandler;
37  import org.apache.omid.tso.TSOChannelHandler;
38  import org.apache.omid.tso.TSOServerConfig;
39  import org.apache.omid.tso.TSOStateManager;
40  import org.apache.omid.tso.TSOStateManagerImpl;
41  import org.apache.omid.tso.TimestampOracle;
42  
43  import org.apache.hadoop.conf.Configuration;
44  
45  import javax.inject.Named;
46  import javax.inject.Singleton;
47  
48  import java.net.SocketException;
49  import java.net.UnknownHostException;
50  
51  import static org.apache.omid.tso.TSOServer.TSO_HOST_AND_PORT_KEY;
52  
53  class TestTSOModule extends AbstractModule {
54  
55      private final Configuration hBaseConfig;
56      private final TSOServerConfig config;
57  
58      TestTSOModule(Configuration hBaseConfig, TSOServerConfig config) {
59          Preconditions.checkArgument(config.getNumConcurrentCTWriters() >= 2, "# of Commit Table writers must be >= 2");
60          this.hBaseConfig = hBaseConfig;
61          this.config = config;
62      }
63  
64      @Override
65      protected void configure() {
66  
67          bind(TSOChannelHandler.class).in(Singleton.class);
68  
69          bind(TSOStateManager.class).to(TSOStateManagerImpl.class).in(Singleton.class);
70  
71          bind(CommitTable.class).to(HBaseCommitTable.class).in(Singleton.class);
72          bind(TimestampStorage.class).to(HBaseTimestampStorage.class).in(Singleton.class);
73          bind(TimestampOracle.class).to(PausableTimestampOracle.class).in(Singleton.class);
74          bind(Panicker.class).to(RuntimeExceptionPanicker.class).in(Singleton.class);
75  
76          install(new BatchPoolModule(config));
77  
78          // Disruptor setup
79          install(new DisruptorModule());
80  
81          // LeaseManagement setup
82          install(config.getLeaseModule());
83      }
84  
85      @Provides
86      Configuration provideHBaseConfig() {
87          return hBaseConfig;
88      }
89  
90      @Provides
91      TSOServerConfig provideTSOServerConfig() {
92          return config;
93      }
94  
95      @Provides
96      @Singleton
97      MetricsRegistry provideMetricsRegistry() {
98          return new NullMetricsProvider();
99      }
100 
101     @Provides
102     @Named(TSO_HOST_AND_PORT_KEY)
103     String provideTSOHostAndPort() throws SocketException, UnknownHostException {
104         return NetworkInterfaceUtils.getTSOHostAndPort(config);
105     }
106 
107     @Provides
108     PersistenceProcessorHandler[] getPersistenceProcessorHandler(Provider<PersistenceProcessorHandler> provider) {
109         PersistenceProcessorHandler[] persistenceProcessorHandlers = new PersistenceProcessorHandler[config.getNumConcurrentCTWriters()];
110         for (int i = 0; i < persistenceProcessorHandlers.length; i++) {
111             persistenceProcessorHandlers[i] = provider.get();
112         }
113         return persistenceProcessorHandlers;
114     }
115 
116 }