/
IgniteTcBotModule.java
122 lines (104 loc) · 4.6 KB
/
IgniteTcBotModule.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ignite.ci.di;
import com.google.common.base.Preconditions;
import com.google.inject.AbstractModule;
import com.google.inject.Injector;
import com.google.inject.internal.SingletonScope;
import com.google.inject.matcher.Matchers;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import javax.inject.Provider;
import org.apache.ignite.Ignite;
import org.apache.ignite.ci.db.Ignite1Init;
import org.apache.ignite.ci.di.cache.GuavaCachedModule;
import org.apache.ignite.tcbot.persistence.scheduler.SchedulerModule;
import org.apache.ignite.githubignited.GitHubIgnitedModule;
import org.apache.ignite.jiraignited.JiraIgnitedModule;
import org.apache.ignite.ci.observer.BuildObserver;
import org.apache.ignite.ci.observer.ObserverTask;
import org.apache.ignite.ci.tcbot.TcBotBusinessServicesModule;
import org.apache.ignite.ci.tcbot.issue.IssueDetector;
import org.apache.ignite.tcbot.common.exeption.ServicesStartingException;
import org.apache.ignite.tcbot.persistence.TcBotPersistenceModule;
import org.apache.ignite.tcignited.TeamcityIgnitedModule;
import org.apache.ignite.tcbot.common.exeption.ExceptionUtil;
import org.apache.ignite.tcbot.engine.pool.TcUpdatePool;
import org.apache.ignite.ci.web.model.hist.VisasHistoryStorage;
import org.apache.ignite.tcbot.common.interceptor.AutoProfiling;
import org.apache.ignite.tcbot.common.interceptor.MonitoredTask;
/**
*
*/
public class IgniteTcBotModule extends AbstractModule {
/** Ignite future. */
private Future<Ignite> igniteFut;
/** {@inheritDoc} */
@Override protected void configure() {
install(new GuavaCachedModule());
configProfiling();
configTaskMonitor();
bind(Ignite.class).toProvider((Provider<Ignite>)() -> {
Preconditions.checkNotNull(igniteFut, "Ignite future is not yet initialized");
try {
return igniteFut.get(10, TimeUnit.SECONDS);
}
catch (TimeoutException e) {
throw new ServicesStartingException(e);
}
catch (Exception e) {
e.printStackTrace();
throw ExceptionUtil.propagateException(e);
}
});
bind(TcUpdatePool.class).in(new SingletonScope());
bind(IssueDetector.class).in(new SingletonScope());
bind(ObserverTask.class).in(new SingletonScope());
bind(BuildObserver.class).in(new SingletonScope());
bind(VisasHistoryStorage.class).in(new SingletonScope());
install(new TcBotPersistenceModule());
install(new TeamcityIgnitedModule());
install(new JiraIgnitedModule());
install(new GitHubIgnitedModule());
install(new SchedulerModule());
install(new TcBotBusinessServicesModule());
}
private void configProfiling() {
AutoProfilingInterceptor profilingInterceptor = new AutoProfilingInterceptor();
bindInterceptor(Matchers.any(),
Matchers.annotatedWith(AutoProfiling.class),
profilingInterceptor);
bind(AutoProfilingInterceptor.class).toInstance(profilingInterceptor);
}
private void configTaskMonitor() {
MonitoredTaskInterceptor profilingInterceptor = new MonitoredTaskInterceptor();
bindInterceptor(Matchers.any(),
Matchers.annotatedWith(MonitoredTask.class),
profilingInterceptor);
bind(MonitoredTaskInterceptor.class).toInstance(profilingInterceptor);
}
public void setIgniteFut(Future<Ignite> igniteFut) {
this.igniteFut = igniteFut;
}
public Injector startIgniteInit(Injector injector) {
final Ignite1Init instance = injector.getInstance(Ignite1Init.class);
final Future<Ignite> submit = instance.getIgniteFuture();
setIgniteFut(submit);
return injector;
}
}