Skip to content

Commit

Permalink
Remove lookup static cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Artem Labazin authored and Artem Labazin committed Mar 5, 2018
1 parent b48e94a commit a8241f9
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 62 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

- Add more unit and integration tests.

## [0.4.2](https://github.com/appulse-projects/epmd-java/releases/tag/0.4.2) - 2018-03-05

Removed lookup cache, which was full of bugs

### Removed

- Lookup cache of node infos.

## [0.4.1](https://github.com/appulse-projects/epmd-java/releases/tag/0.4.1) - 2018-02-16

Minor bug fixes
Expand Down
4 changes: 2 additions & 2 deletions client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Include the dependency to your project's pom.xml file:
<dependency>
<groupId>io.appulse.epmd.java</groupId>
<artifactId>client</artifactId>
<version>0.4.1</version>
<version>0.4.2</version>
</dependency>
...
</dependencies>
Expand All @@ -23,7 +23,7 @@ Include the dependency to your project's pom.xml file:
or Gradle:

```groovy
compile 'io.appulse.epmd.java:client:0.4.1'
compile 'io.appulse.epmd.java:client:0.4.2'
```

### Create client
Expand Down
2 changes: 1 addition & 1 deletion client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ limitations under the License.
<parent>
<groupId>io.appulse</groupId>
<artifactId>epmd-java</artifactId>
<version>0.4.1</version>
<version>0.4.2</version>
</parent>

<groupId>io.appulse.epmd.java</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,6 @@ public void close () {
log.debug("EPMD client was closed");
}

public void clearCaches () {
lookupService.clearCache();
}

@Override
protected void finalize () throws Throwable {
close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,14 @@
import static lombok.AccessLevel.PRIVATE;

import java.net.InetAddress;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.BiFunction;

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

import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.Value;
import lombok.experimental.FieldDefaults;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
Expand All @@ -46,30 +42,6 @@
@FieldDefaults(level = PRIVATE, makeFinal = true)
class LookupService {

private static final Map<NodeDescriptor, NodeInfo> CACHE;

private static final BiFunction<NodeDescriptor, NodeInfo, NodeInfo> COMPUTE;

static {
CACHE = new ConcurrentHashMap<>();

COMPUTE = (key, value) -> {
if (value != null) {
log.debug("Used cached value {}", value);
return value;
}

val request = new GetNodeInfo(key.getNode());
try (val connection = new Connection(key.getAddress(), key.getPort())) {
val response = connection.send(request, NodeInfo.class);
log.debug("Lookup result is {}", response);
return response.isOk()
? response
: null;
}
};
}

@NonNull
InetAddress defaultAddress;

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

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

val descriptor = new NodeDescriptor(shortName, address, port);
val nodeInfo = CACHE.compute(descriptor, COMPUTE);
return ofNullable(nodeInfo);
}

void clearCache () {
CACHE.clear();
}

@Value
private static class NodeDescriptor {

@NonNull
String node;

@NonNull
InetAddress address;

@NonNull
Integer port;
val request = new GetNodeInfo(shortName);
try (val connection = new Connection(address, port)) {
val response = connection.send(request, NodeInfo.class);
log.debug("Lookup result is {}", response);
return ofNullable(response)
.filter(NodeInfo::isOk);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public void before () {
@After
public void after () {
if (client != null) {
client.clearCaches();
client.close();
client = null;
}
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ limitations under the License.
<parent>
<groupId>io.appulse</groupId>
<artifactId>epmd-java</artifactId>
<version>0.4.1</version>
<version>0.4.2</version>
</parent>

<groupId>io.appulse.epmd.java</groupId>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ limitations under the License.

<groupId>io.appulse</groupId>
<artifactId>epmd-java</artifactId>
<version>0.4.1</version>
<version>0.4.2</version>
<packaging>pom</packaging>

<modules>
Expand Down Expand Up @@ -68,7 +68,7 @@ limitations under the License.
<url>https://github.com/appulse-projects/epmd-java</url>
<connection>scm:git:https://github.com/appulse-projects/epmd-java.git</connection>
<developerConnection>scm:git:https://github.com/appulse-projects/epmd-java.git</developerConnection>
<tag>0.4.1</tag>
<tag>0.4.2</tag>
</scm>

<distributionManagement>
Expand Down
4 changes: 2 additions & 2 deletions server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Include the dependency to your project's pom.xml file:
<dependency>
<groupId>io.appulse.epmd.java</groupId>
<artifactId>server</artifactId>
<version>0.4.1</version>
<version>0.4.2</version>
</dependency>
...
</dependencies>
Expand All @@ -27,5 +27,5 @@ Include the dependency to your project's pom.xml file:
or Gradle:

```groovy
compile 'io.appulse.epmd.java:server:0.4.1'
compile 'io.appulse.epmd.java:server:0.4.2'
```
2 changes: 1 addition & 1 deletion server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ limitations under the License.
<parent>
<groupId>io.appulse</groupId>
<artifactId>epmd-java</artifactId>
<version>0.4.1</version>
<version>0.4.2</version>
</parent>

<groupId>io.appulse.epmd.java</groupId>
Expand Down

0 comments on commit a8241f9

Please sign in to comment.