Skip to content

Commit a8241f9

Browse files
Artem LabazinArtem Labazin
authored andcommitted
Remove lookup static cache
1 parent b48e94a commit a8241f9

File tree

10 files changed

+24
-62
lines changed

10 files changed

+24
-62
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1111

1212
- Add more unit and integration tests.
1313

14+
## [0.4.2](https://github.com/appulse-projects/epmd-java/releases/tag/0.4.2) - 2018-03-05
15+
16+
Removed lookup cache, which was full of bugs
17+
18+
### Removed
19+
20+
- Lookup cache of node infos.
21+
1422
## [0.4.1](https://github.com/appulse-projects/epmd-java/releases/tag/0.4.1) - 2018-02-16
1523

1624
Minor bug fixes

client/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Include the dependency to your project's pom.xml file:
1414
<dependency>
1515
<groupId>io.appulse.epmd.java</groupId>
1616
<artifactId>client</artifactId>
17-
<version>0.4.1</version>
17+
<version>0.4.2</version>
1818
</dependency>
1919
...
2020
</dependencies>
@@ -23,7 +23,7 @@ Include the dependency to your project's pom.xml file:
2323
or Gradle:
2424

2525
```groovy
26-
compile 'io.appulse.epmd.java:client:0.4.1'
26+
compile 'io.appulse.epmd.java:client:0.4.2'
2727
```
2828

2929
### Create client

client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ limitations under the License.
2525
<parent>
2626
<groupId>io.appulse</groupId>
2727
<artifactId>epmd-java</artifactId>
28-
<version>0.4.1</version>
28+
<version>0.4.2</version>
2929
</parent>
3030

3131
<groupId>io.appulse.epmd.java</groupId>

client/src/main/java/io/appulse/epmd/java/client/EpmdClient.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,6 @@ public void close () {
165165
log.debug("EPMD client was closed");
166166
}
167167

168-
public void clearCaches () {
169-
lookupService.clearCache();
170-
}
171-
172168
@Override
173169
protected void finalize () throws Throwable {
174170
close();

client/src/main/java/io/appulse/epmd/java/client/LookupService.java

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,14 @@
2020
import static lombok.AccessLevel.PRIVATE;
2121

2222
import java.net.InetAddress;
23-
import java.util.Map;
2423
import java.util.Optional;
25-
import java.util.concurrent.ConcurrentHashMap;
26-
import java.util.function.BiFunction;
2724

2825
import io.appulse.epmd.java.core.model.request.GetNodeInfo;
2926
import io.appulse.epmd.java.core.model.response.NodeInfo;
3027

3128
import lombok.NonNull;
3229
import lombok.RequiredArgsConstructor;
3330
import lombok.SneakyThrows;
34-
import lombok.Value;
3531
import lombok.experimental.FieldDefaults;
3632
import lombok.extern.slf4j.Slf4j;
3733
import lombok.val;
@@ -46,30 +42,6 @@
4642
@FieldDefaults(level = PRIVATE, makeFinal = true)
4743
class LookupService {
4844

49-
private static final Map<NodeDescriptor, NodeInfo> CACHE;
50-
51-
private static final BiFunction<NodeDescriptor, NodeInfo, NodeInfo> COMPUTE;
52-
53-
static {
54-
CACHE = new ConcurrentHashMap<>();
55-
56-
COMPUTE = (key, value) -> {
57-
if (value != null) {
58-
log.debug("Used cached value {}", value);
59-
return value;
60-
}
61-
62-
val request = new GetNodeInfo(key.getNode());
63-
try (val connection = new Connection(key.getAddress(), key.getPort())) {
64-
val response = connection.send(request, NodeInfo.class);
65-
log.debug("Lookup result is {}", response);
66-
return response.isOk()
67-
? response
68-
: null;
69-
}
70-
};
71-
}
72-
7345
@NonNull
7446
InetAddress defaultAddress;
7547

@@ -100,25 +72,12 @@ public Optional<NodeInfo> lookup (@NonNull String node, @NonNull InetAddress add
10072

10173
log.debug("Looking up node '{}' at '{}:{}'", shortName, address, port);
10274

103-
val descriptor = new NodeDescriptor(shortName, address, port);
104-
val nodeInfo = CACHE.compute(descriptor, COMPUTE);
105-
return ofNullable(nodeInfo);
106-
}
107-
108-
void clearCache () {
109-
CACHE.clear();
110-
}
111-
112-
@Value
113-
private static class NodeDescriptor {
114-
115-
@NonNull
116-
String node;
117-
118-
@NonNull
119-
InetAddress address;
120-
121-
@NonNull
122-
Integer port;
75+
val request = new GetNodeInfo(shortName);
76+
try (val connection = new Connection(address, port)) {
77+
val response = connection.send(request, NodeInfo.class);
78+
log.debug("Lookup result is {}", response);
79+
return ofNullable(response)
80+
.filter(NodeInfo::isOk);
81+
}
12382
}
12483
}

client/src/test/java/io/appulse/epmd/java/client/LocalEpmdClientTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ public void before () {
6666
@After
6767
public void after () {
6868
if (client != null) {
69-
client.clearCaches();
7069
client.close();
7170
client = null;
7271
}

core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ limitations under the License.
2525
<parent>
2626
<groupId>io.appulse</groupId>
2727
<artifactId>epmd-java</artifactId>
28-
<version>0.4.1</version>
28+
<version>0.4.2</version>
2929
</parent>
3030

3131
<groupId>io.appulse.epmd.java</groupId>

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ limitations under the License.
2424

2525
<groupId>io.appulse</groupId>
2626
<artifactId>epmd-java</artifactId>
27-
<version>0.4.1</version>
27+
<version>0.4.2</version>
2828
<packaging>pom</packaging>
2929

3030
<modules>
@@ -68,7 +68,7 @@ limitations under the License.
6868
<url>https://github.com/appulse-projects/epmd-java</url>
6969
<connection>scm:git:https://github.com/appulse-projects/epmd-java.git</connection>
7070
<developerConnection>scm:git:https://github.com/appulse-projects/epmd-java.git</developerConnection>
71-
<tag>0.4.1</tag>
71+
<tag>0.4.2</tag>
7272
</scm>
7373

7474
<distributionManagement>

server/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Include the dependency to your project's pom.xml file:
1818
<dependency>
1919
<groupId>io.appulse.epmd.java</groupId>
2020
<artifactId>server</artifactId>
21-
<version>0.4.1</version>
21+
<version>0.4.2</version>
2222
</dependency>
2323
...
2424
</dependencies>
@@ -27,5 +27,5 @@ Include the dependency to your project's pom.xml file:
2727
or Gradle:
2828

2929
```groovy
30-
compile 'io.appulse.epmd.java:server:0.4.1'
30+
compile 'io.appulse.epmd.java:server:0.4.2'
3131
```

server/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ limitations under the License.
2525
<parent>
2626
<groupId>io.appulse</groupId>
2727
<artifactId>epmd-java</artifactId>
28-
<version>0.4.1</version>
28+
<version>0.4.2</version>
2929
</parent>
3030

3131
<groupId>io.appulse.epmd.java</groupId>

0 commit comments

Comments
 (0)