Skip to content

Commit db8a123

Browse files
committed
Use new resource API.
Motivation: Vert.x core has introduced new API for resource cleanup. This project should use it. Changes: Use new resource cleanup API.
1 parent cb8b208 commit db8a123

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

src/main/java/io/vertx/httpproxy/impl/CacheImpl.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
package io.vertx.httpproxy.impl;
22

33
import io.vertx.core.Future;
4+
import io.vertx.core.internal.Closeable;
45
import io.vertx.httpproxy.cache.CacheOptions;
56
import io.vertx.httpproxy.spi.cache.Cache;
67
import io.vertx.httpproxy.spi.cache.Resource;
78

9+
import java.time.Duration;
810
import java.util.*;
911

1012
/**
1113
* Simplistic implementation.
1214
*/
13-
public class CacheImpl implements Cache {
15+
public class CacheImpl implements Cache, Closeable {
1416

1517
private final int maxSize;
1618
private final Map<String, Resource> data;
@@ -43,4 +45,8 @@ public Future<Void> remove(String key) {
4345
return Future.succeededFuture();
4446
}
4547

48+
@Override
49+
public Future<Void> shutdown(Duration timeout) {
50+
return Future.succeededFuture();
51+
}
4652
}

src/main/java/io/vertx/httpproxy/impl/ReverseProxy.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import io.vertx.core.Vertx;
1515
import io.vertx.core.buffer.Buffer;
1616
import io.vertx.core.http.*;
17-
import io.vertx.core.internal.CloseFuture;
17+
import io.vertx.core.internal.CloseableResource;
1818
import io.vertx.core.internal.VertxInternal;
1919
import io.vertx.core.internal.http.HttpClientInternal;
2020
import io.vertx.core.internal.logging.Logger;
@@ -51,12 +51,14 @@ public ReverseProxy(ProxyOptions options, HttpClient client) {
5151

5252
public Cache newCache(CacheOptions options, Vertx vertx) {
5353
if (options.isShared()) {
54-
CloseFuture closeFuture = new CloseFuture();
55-
return ((VertxInternal) vertx).createSharedResource("__vertx.shared.proxyCache", options.getName(), closeFuture, (cf_) -> {
56-
return new CacheImpl(options);
57-
});
54+
CloseableResource<CacheImpl> resource = ((VertxInternal) vertx).createSharedResource(
55+
"__vertx.shared.proxyCache",
56+
options.getName(),
57+
() -> new CacheImpl(options));
58+
return resource.get();
59+
} else {
60+
return new CacheImpl(options);
5861
}
59-
return new CacheImpl(options);
6062
}
6163

6264
@Override

0 commit comments

Comments
 (0)