|
1 | 1 | package org.hypertrace.core.graphql.utils.grpc;
|
2 | 2 |
|
3 | 3 | import io.grpc.ManagedChannel;
|
4 |
| -import io.grpc.ManagedChannelBuilder; |
5 |
| -import java.util.Map; |
6 |
| -import java.util.concurrent.ConcurrentHashMap; |
7 | 4 | import javax.inject.Inject;
|
8 | 5 | import javax.inject.Singleton;
|
9 | 6 | import org.hypertrace.core.graphql.spi.lifecycle.GraphQlServiceLifecycle;
|
10 |
| -import org.slf4j.Logger; |
11 |
| -import org.slf4j.LoggerFactory; |
12 | 7 |
|
13 | 8 | @Singleton
|
14 | 9 | class DefaultGrpcChannelRegistry implements GrpcChannelRegistry {
|
15 |
| - private static final Logger LOG = LoggerFactory.getLogger(DefaultGrpcChannelRegistry.class); |
16 |
| - private final Map<String, ManagedChannel> channelMap = new ConcurrentHashMap<>(); |
17 |
| - private volatile boolean isShutdown = false; |
| 10 | + |
| 11 | + private final org.hypertrace.core.grpcutils.client.GrpcChannelRegistry delegate = |
| 12 | + new org.hypertrace.core.grpcutils.client.GrpcChannelRegistry(); |
18 | 13 |
|
19 | 14 | @Inject
|
20 | 15 | DefaultGrpcChannelRegistry(GraphQlServiceLifecycle serviceLifecycle) {
|
21 |
| - serviceLifecycle.shutdownCompletion().thenRun(this::shutdown); |
| 16 | + serviceLifecycle.shutdownCompletion().thenRun(this.delegate::shutdown); |
22 | 17 | }
|
23 | 18 |
|
24 | 19 | @Override
|
25 | 20 | public ManagedChannel forAddress(String host, int port) {
|
26 |
| - assert !this.isShutdown; |
27 |
| - String channelId = this.getChannelId(host, port); |
28 |
| - return this.channelMap.computeIfAbsent(channelId, unused -> this.buildNewChannel(host, port)); |
29 |
| - } |
30 |
| - |
31 |
| - private ManagedChannel buildNewChannel(String host, int port) { |
32 |
| - LOG.info("Creating new channel for {}:{}", host, port); |
33 |
| - return ManagedChannelBuilder.forAddress(host, port).usePlaintext().build(); |
34 |
| - } |
35 |
| - |
36 |
| - private String getChannelId(String host, int port) { |
37 |
| - return host + ":" + port; |
38 |
| - } |
39 |
| - |
40 |
| - private void shutdown() { |
41 |
| - channelMap.values().forEach(ManagedChannel::shutdown); |
42 |
| - this.isShutdown = true; |
| 21 | + return this.delegate.forPlaintextAddress(host, port); |
43 | 22 | }
|
44 | 23 | }
|
0 commit comments