Skip to content

Commit

Permalink
save url attributes on initialization (#9467)
Browse files Browse the repository at this point in the history
  • Loading branch information
chickenlj authored Dec 23, 2021
1 parent c2b6303 commit 10aaa0f
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.dubbo.remoting.exchange.ExchangeHandler;

import java.net.InetSocketAddress;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicInteger;
Expand All @@ -44,6 +45,7 @@ final class ReferenceCountExchangeClient implements ExchangeClient {
private final static Logger logger = LoggerFactory.getLogger(ReferenceCountExchangeClient.class);
private final URL url;
private final String codec;
private final Map<String, String> attributes;
private final AtomicInteger referenceCount = new AtomicInteger(0);
private final AtomicInteger disconnectCount = new AtomicInteger(0);
private final Integer warningPeriod = 50;
Expand All @@ -55,6 +57,7 @@ public ReferenceCountExchangeClient(ExchangeClient client, String codec) {
this.referenceCount.incrementAndGet();
this.url = client.getUrl();
this.codec = codec;
this.attributes = url.getParameters();
}

@Override
Expand Down Expand Up @@ -212,10 +215,16 @@ private void replaceWithLazyClient() {
if (!(client instanceof LazyConnectExchangeClient)) {
// this is a defensive operation to avoid client is closed by accident, the initial state of the client is false
URL lazyUrl = url.addParameter(LAZY_CONNECT_INITIAL_STATE_KEY, Boolean.TRUE)
//.addParameter(RECONNECT_KEY, Boolean.FALSE)
.addParameter(SEND_RECONNECT_KEY, Boolean.TRUE.toString());
//.addParameter(RECONNECT_KEY, Boolean.FALSE)
.addParameter(SEND_RECONNECT_KEY, Boolean.TRUE.toString());
//.addParameter(LazyConnectExchangeClient.REQUEST_WITH_WARNING_KEY, true);
client = new LazyConnectExchangeClient(lazyUrl, client.getExchangeHandler(), codec, lazyUrl.getParameters());

// uncomment this snippet when replacing lazyUrl in the futrue
// Map<String, String> lazyAttributes = new HashMap<>(attributes);
// lazyAttributes.put(LAZY_CONNECT_INITIAL_STATE_KEY, Boolean.TRUE.toString());
// lazyAttributes.put(SEND_RECONNECT_KEY, Boolean.TRUE.toString());

client = new LazyConnectExchangeClient(lazyUrl, client.getExchangeHandler(), codec, attributes);
}
}

Expand Down

0 comments on commit 10aaa0f

Please sign in to comment.