|
19 | 19 | import static com.google.common.base.Preconditions.checkNotNull;
|
20 | 20 |
|
21 | 21 | import com.google.common.collect.Sets;
|
22 |
| -import com.google.common.util.concurrent.SettableFuture; |
| 22 | +import io.grpc.ChannelCredentials; |
23 | 23 | import io.grpc.InsecureChannelCredentials;
|
24 | 24 | import io.grpc.SynchronizationContext;
|
25 | 25 | import io.grpc.xds.RlqsFilterConfig;
|
26 | 26 | import io.grpc.xds.client.Bootstrapper.RemoteServerInfo;
|
27 | 27 | import java.util.Set;
|
28 | 28 | import java.util.concurrent.ConcurrentHashMap;
|
29 |
| -import java.util.concurrent.ExecutionException; |
30 | 29 | import java.util.concurrent.ScheduledExecutorService;
|
31 |
| -import java.util.concurrent.TimeUnit; |
32 |
| -import java.util.concurrent.TimeoutException; |
33 | 30 | import java.util.logging.Level;
|
34 | 31 | import java.util.logging.Logger;
|
35 | 32 |
|
@@ -80,34 +77,20 @@ public void shutdownRlqsEngine(RlqsFilterConfig oldConfig) {
|
80 | 77 | // TODO(sergiitk): shutdown one
|
81 | 78 | }
|
82 | 79 |
|
83 |
| - public RlqsEngine getOrCreateRlqsEngine(RlqsFilterConfig config) { |
84 |
| - final String configHash = hashRlqsFilterConfig(config); |
85 |
| - if (enginePool.containsKey(configHash)) { |
86 |
| - return enginePool.get(configHash); |
87 |
| - } |
| 80 | + public RlqsEngine getOrCreateRlqsEngine(final RlqsFilterConfig config) { |
| 81 | + String configHash = hashRlqsFilterConfig(config); |
| 82 | + return enginePool.computeIfAbsent(configHash, k -> newRlqsEngine(k, config)); |
| 83 | + } |
88 | 84 |
|
89 |
| - final SettableFuture<RlqsEngine> future = SettableFuture.create(); |
90 |
| - syncContext.execute(() -> { |
91 |
| - // TODO(sergiitk): [IMPL] get channel creds from the bootstrap. |
92 |
| - RemoteServerInfo rlqsServer = RemoteServerInfo.create(config.rlqsService().targetUri(), |
93 |
| - InsecureChannelCredentials.create()); |
94 |
| - RlqsEngine rlqsEngine = new RlqsEngine( |
95 |
| - rlqsServer, |
96 |
| - config.domain(), |
97 |
| - config.bucketMatchers(), |
98 |
| - configHash, |
99 |
| - scheduler); |
100 |
| - |
101 |
| - enginePool.put(configHash, rlqsEngine); |
102 |
| - future.set(enginePool.get(configHash)); |
103 |
| - }); |
104 |
| - try { |
105 |
| - // TODO(sergiitk): [IMPL] clarify time |
106 |
| - return future.get(1, TimeUnit.SECONDS); |
107 |
| - } catch (InterruptedException | ExecutionException | TimeoutException e) { |
108 |
| - // TODO(sergiitk): [IMPL] handle properly |
109 |
| - throw new RuntimeException(e); |
110 |
| - } |
| 85 | + private RlqsEngine newRlqsEngine(String configHash, RlqsFilterConfig config) { |
| 86 | + // TODO(sergiitk): [IMPL] get channel creds from the bootstrap. |
| 87 | + ChannelCredentials creds = InsecureChannelCredentials.create(); |
| 88 | + return new RlqsEngine( |
| 89 | + RemoteServerInfo.create(config.rlqsService().targetUri(), creds), |
| 90 | + config.domain(), |
| 91 | + config.bucketMatchers(), |
| 92 | + configHash, |
| 93 | + scheduler); |
111 | 94 | }
|
112 | 95 |
|
113 | 96 | private String hashRlqsFilterConfig(RlqsFilterConfig config) {
|
|
0 commit comments