1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.omid.tso;
19
20 import com.google.inject.AbstractModule;
21 import com.google.inject.name.Names;
22 import com.lmax.disruptor.BlockingWaitStrategy;
23 import com.lmax.disruptor.BusySpinWaitStrategy;
24 import com.lmax.disruptor.WaitStrategy;
25 import com.lmax.disruptor.YieldingWaitStrategy;
26
27 import javax.inject.Singleton;
28
29 public class DisruptorModule extends AbstractModule {
30
31 private final TSOServerConfig config;
32
33 public DisruptorModule(TSOServerConfig config) {
34 this.config = config;
35 }
36
37 @Override
38 protected void configure() {
39 switch (config.getWaitStrategyEnum()) {
40
41 case LOW_CPU:
42 bind(WaitStrategy.class).annotatedWith(Names.named("PersistenceStrategy")).to(BlockingWaitStrategy.class);
43 bind(WaitStrategy.class).annotatedWith(Names.named("ReplyStrategy")).to(BlockingWaitStrategy.class);
44 bind(WaitStrategy.class).annotatedWith(Names.named("RetryStrategy")).to(BlockingWaitStrategy.class);
45 break;
46
47 case HIGH_THROUGHPUT:
48 default:
49 bind(WaitStrategy.class).annotatedWith(Names.named("PersistenceStrategy")).to(BusySpinWaitStrategy.class);
50 bind(WaitStrategy.class).annotatedWith(Names.named("ReplyStrategy")).to(BusySpinWaitStrategy.class);
51 bind(WaitStrategy.class).annotatedWith(Names.named("RetryStrategy")).to(YieldingWaitStrategy.class);
52 break;
53 }
54
55 if (config.getLowLatency()) {
56 bind(RequestProcessor.class).to(RequestProcessorSkipCT.class).in(Singleton.class);
57 bind(PersistenceProcessor.class).to(PersitenceProcessorNullImpl.class).in(Singleton.class);
58 } else {
59 bind(PersistenceProcessor.class).to(PersistenceProcessorImpl.class).in(Singleton.class);
60 bind(RequestProcessor.class).to(RequestProcessorPersistCT.class).in(Singleton.class);
61 }
62
63 bind(ReplyProcessor.class).to(ReplyProcessorImpl.class).in(Singleton.class);
64 bind(RetryProcessor.class).to(RetryProcessorImpl.class).in(Singleton.class);
65
66 }
67
68 }