Skip to content

Commit 08cd8bd

Browse files
committed
feat: add close method
Signed-off-by: moxiaoying <1159230165@qq.com>
1 parent 80e375c commit 08cd8bd

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/InnerHttpClient.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ public HttpResponse get(String url, String... params) throws IOException, Interr
9999
return client.send(request).get();
100100
}
101101

102+
public void close() throws IOException {
103+
this.client.close();
104+
}
105+
102106
private List<UrlBuilder.Param> convertListToParams(String... requestParams) {
103107
if (requestParams.length % 2 != 0) {
104108
throw new IllegalArgumentException("params list length cannot be odd");

pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/PulsarAdmin.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.github.protocol.pulsar.admin.jdk;
22

3+
import java.io.IOException;
4+
35
public interface PulsarAdmin {
46
static PulsarAdminBuilder builder() {
57
return new PulsarAdminBuilderImpl();
@@ -16,4 +18,6 @@ static PulsarAdminBuilder builder() {
1618
PersistentTopics persistentTopics();
1719

1820
NonPersistentTopics nonPersistentTopics();
21+
22+
void close() throws IOException;
1923
}

pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/PulsarAdminImpl.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import io.github.protocol.pulsar.admin.api.Configuration;
44

5+
import java.io.IOException;
6+
57
public class PulsarAdminImpl implements PulsarAdmin {
68

79
private final Clusters clusters;
@@ -16,14 +18,16 @@ public class PulsarAdminImpl implements PulsarAdmin {
1618

1719
private final NonPersistentTopics nonPersistentTopics;
1820

21+
private final InnerHttpClient innerHttpClient;
22+
1923
PulsarAdminImpl(Configuration conf) {
20-
InnerHttpClient innerHttpClient = new InnerHttpClient(conf);
21-
this.clusters = new Clusters(innerHttpClient);
22-
this.brokers = new Brokers(innerHttpClient);
23-
this.tenants = new Tenants(innerHttpClient);
24-
this.namespaces = new Namespaces(innerHttpClient);
25-
this.persistentTopics = new PersistentTopics(innerHttpClient);
26-
this.nonPersistentTopics = new NonPersistentTopics(innerHttpClient);
24+
this.innerHttpClient = new InnerHttpClient(conf);
25+
this.clusters = new Clusters(this.innerHttpClient);
26+
this.brokers = new Brokers(this.innerHttpClient);
27+
this.tenants = new Tenants(this.innerHttpClient);
28+
this.namespaces = new Namespaces(this.innerHttpClient);
29+
this.persistentTopics = new PersistentTopics(this.innerHttpClient);
30+
this.nonPersistentTopics = new NonPersistentTopics(this.innerHttpClient);
2731
}
2832

2933
@Override
@@ -55,4 +59,9 @@ public PersistentTopics persistentTopics() {
5559
public NonPersistentTopics nonPersistentTopics() {
5660
return nonPersistentTopics;
5761
}
62+
63+
@Override
64+
public void close() throws IOException {
65+
this.innerHttpClient.close();
66+
}
5867
}

0 commit comments

Comments
 (0)