forked from Restream/reindexer-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataSourceConfiguration.java
More file actions
204 lines (173 loc) · 6.08 KB
/
Copy pathDataSourceConfiguration.java
File metadata and controls
204 lines (173 loc) · 6.08 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
* Copyright 2020 Restream
*
* Licensed 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 ru.rt.restream.reindexer.binding.cproto;
import org.apache.commons.lang3.mutable.MutableInt;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.net.ssl.SSLSocketFactory;
/**
* A {@link DataSource} configuration.
*/
public class DataSourceConfiguration {
/**
* A list of reindexer database urls of the form protocol://host:port/database_name.
*/
private final List<String> urls;
/**
* A permission to use database urls from #replicationstats which are not in the list of urls.
*/
private final boolean allowUnlistedDataSource;
/**
* An {@link SSLSocketFactory} to connect to Reindexer using cprotos (SSL/TLS) protocol.
*/
private final SSLSocketFactory sslSocketFactory;
/**
* An index of the current active data source.
*/
private final MutableInt active;
private DataSourceConfiguration(Builder builder) {
urls = builder.urls;
allowUnlistedDataSource = builder.allowUnlistedDataSource;
active = builder.active;
sslSocketFactory = builder.sslSocketFactory;
}
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return new Builder(this);
}
/**
* Return a list of reindexer database urls of the form protocol://host:port/database_name.
*
* @return a list of reindexer database urls of the form protocol://host:port/database_name
*/
public List<String> getUrls() {
return urls;
}
public boolean isAllowUnlistedDataSource() {
return allowUnlistedDataSource;
}
/**
* Returns an {@link SSLSocketFactory} to connect to Reindexer using cprotos (SSL/TLS) protocol.
*
* @return the {@link SSLSocketFactory} to use
*/
public SSLSocketFactory getSslSocketFactory() {
return sslSocketFactory;
}
/**
* Returns the index of the current active data source.
*
* @return the index of the current active data source
*/
public int getActive() {
return active.getValue();
}
/**
* Sets the index of the current active data source.
*
* @param value the index of the current active data source
*/
public void setActive(int value) {
active.setValue(value);
}
/**
* Builder for a {@link DataSource} configuration.
*/
public static class Builder {
/**
* A list of reindexer database urls database url of the form protocol://host:port/database_name.
*/
private List<String> urls = new ArrayList<>();
/**
* A permission to use database urls from #replicationstats which are not in the list of urls.
*/
private boolean allowUnlistedDataSource = true;
/**
* An {@link SSLSocketFactory} to connect to Reindexer using cprotos (SSL/TLS) protocol.
*/
private SSLSocketFactory sslSocketFactory;
/**
* An index of the current active data source.
*/
private MutableInt active = new MutableInt(-1);
/**
* Private constructor with default values for use in the method builder() only.
*/
private Builder() {
}
/**
* Private constructor for use in the method toBuilder() only.
*
* @param configuration parent {@link DataSourceConfiguration}
*/
private Builder(DataSourceConfiguration configuration) {
urls = configuration.urls;
allowUnlistedDataSource = configuration.allowUnlistedDataSource;
active = configuration.active;
}
/**
* Configure reindexer database url.
*
* @param url a database url of the form protocol://host:port/database_name
* @return the {@link Builder} for further customizations
*/
public Builder url(String url) {
urls.add(Objects.requireNonNull(url));
return this;
}
/**
* Configure reindexer database urls.
*
* @param urls a list of database url of the form protocol://host:port/database_name
* @return the {@link Builder} for further customizations
*/
public Builder urls(List<String> urls) {
this.urls = Objects.requireNonNull(urls);
return this;
}
/**
* Allows usage of the database urls from #replicationstats which are not in the list of urls.
*
* @param allowUnlistedDataSource enable permission to use unlisted urls
* @return the {@link Builder} for further customizations
*/
public Builder allowUnlistedDataSource(boolean allowUnlistedDataSource) {
this.allowUnlistedDataSource = allowUnlistedDataSource;
return this;
}
/**
* Configure an {@link SSLSocketFactory} to connect to Reindexer using cprotos (TLS) protocol.
*
* @param sslSocketFactory the {@link SSLSocketFactory} to use
* @return the {@link Builder} for further customizations
*/
public Builder sslSocketFactory(SSLSocketFactory sslSocketFactory) {
this.sslSocketFactory = sslSocketFactory;
return this;
}
/**
* Build and return a {@link DataSource} configuration.
*
* @return a {@link DataSourceConfiguration}
*/
public DataSourceConfiguration build() {
return new DataSourceConfiguration(this);
}
}
}