Skip to content

Commit 0d089ad

Browse files
author
Artem Eroshenko
committed
Merge pull request #4 from innokenty/master
Simplify embedding into other applications
2 parents 09058e3 + 2a64733 commit 0d089ad

File tree

5 files changed

+26
-16
lines changed

5 files changed

+26
-16
lines changed
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ru.qatools.gridrouter.config;
22

3+
import java.util.ArrayList;
34
import java.util.List;
45

56
/**
@@ -10,15 +11,15 @@ public interface WithCopy {
1011

1112
List<Host> getHosts();
1213

14+
String getName();
15+
1316
/**
1417
* Creates a copy for the {@link Region} object, which is almost deep:
1518
* the hosts itself are not copied although the list is new.
1619
*
1720
* @return a copy of the object
1821
*/
1922
default Region copy() {
20-
Region result = new Region();
21-
result.getHosts().addAll(getHosts());
22-
return result;
23+
return new Region(new ArrayList<>(getHosts()), getName());
2324
}
2425
}

config/src/test/java/ru/qatools/gridrouter/config/RandomHostSelectionStrategyTest.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public void testRandomness() {
2727
int entriesCount = 5000000;
2828
int keysCount = 10;
2929

30-
Host host1 = newHost("host_1", keysCount - 1);
30+
Host host1 = new Host("host_1", 4444, keysCount - 1);
3131

3232
List<Host> hosts = new ArrayList<>(keysCount);
3333
hosts.add(host1);
@@ -54,14 +54,7 @@ public void testRandomness() {
5454
}
5555

5656
private static Host newHost() {
57-
return newHost(UUID.randomUUID().toString(), 1);
58-
}
59-
60-
private static Host newHost(String name, int count) {
61-
Host host = new Host();
62-
host.setName(name);
63-
host.setCount(count);
64-
return host;
57+
return new Host(UUID.randomUUID().toString(), 4444, 1);
6558
}
6659

6760
private static Matcher<Integer> isAround(int count) {

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,19 @@
112112
<verbose>true</verbose>
113113
<args>
114114
<arg>-Xinheritance</arg>
115+
<arg>-Xvalue-constructor</arg>
115116
</args>
116117
<plugins>
117118
<plugin>
118119
<groupId>org.jvnet.jaxb2_commons</groupId>
119120
<artifactId>jaxb2-basics</artifactId>
120121
<version>0.9.4</version>
121122
</plugin>
123+
<plugin>
124+
<groupId>org.jvnet.jaxb2_commons</groupId>
125+
<artifactId>jaxb2-value-constructor</artifactId>
126+
<version>3.0</version>
127+
</plugin>
122128
</plugins>
123129
</configuration>
124130
</plugin>

proxy/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313

1414
<build>
1515
<plugins>
16+
<plugin>
17+
<groupId>org.apache.maven.plugins</groupId>
18+
<artifactId>maven-war-plugin</artifactId>
19+
<configuration>
20+
<attachClasses>true</attachClasses>
21+
</configuration>
22+
</plugin>
1623
<plugin>
1724
<groupId>org.jvnet.jaxb2.maven2</groupId>
1825
<artifactId>maven-jaxb2-plugin</artifactId>

proxy/src/main/java/ru/qatools/gridrouter/ConfigRepository.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,16 @@ public void beanChanged(Path filename, Browsers browsers) {
6565
} else {
6666
LOGGER.info("Loading quota configuration file [{}]", filename);
6767
String user = FilenameUtils.getBaseName(filename.toString());
68-
userBrowsers.put(user, browsers);
69-
routes.putAll(browsers.getRoutesMap());
70-
LOGGER.info("Loaded quota configuration for [{}] from [{}]: \n\n{}",
71-
user, filename, browsers.toXml());
68+
updateQuota(user, browsers);
7269
}
7370
}
7471

72+
public void updateQuota(String user, Browsers browsers) {
73+
userBrowsers.put(user, browsers);
74+
routes.putAll(browsers.getRoutesMap());
75+
LOGGER.info("Loaded quota configuration for [{}]: \n\n{}", user, browsers.toXml());
76+
}
77+
7578
public Map<String, String> getRoutes() {
7679
return routes;
7780
}

0 commit comments

Comments
 (0)