liubao68 commented on a change in pull request #2691:
URL:
https://github.com/apache/servicecomb-java-chassis/pull/2691#discussion_r790361285
##########
File path:
clients/service-center-client/src/main/java/org/apache/servicecomb/service/center/client/AddressManager.java
##########
@@ -17,47 +17,23 @@
package org.apache.servicecomb.service.center.client;
-import java.util.ArrayList;
import java.util.List;
-import org.apache.servicecomb.http.client.common.HttpUtils;
+import org.apache.servicecomb.http.client.common.AbstractAddressManager;
+import org.apache.servicecomb.http.client.event.RefreshEndpointEvent;
-public class AddressManager {
- private final String projectName;
+import com.google.common.eventbus.EventBus;
+import com.google.common.eventbus.Subscribe;
- private final List<String> addresses;
-
- private int index = 0;
-
- public AddressManager(String projectName, List<String> addresses) {
- this.projectName = projectName;
- this.addresses = new ArrayList<>(addresses.size());
- this.addresses.addAll(addresses);
- }
-
- private String formatAddress(String address) {
- try {
- return address + "/v4/" + HttpUtils.encodeURLParam(this.projectName);
- } catch (Exception e) {
- throw new IllegalStateException("not possible");
- }
+public class AddressManager extends AbstractAddressManager {
+ public AddressManager(String projectName, List<String> addresses, EventBus
eventBus) {
+ super(projectName, addresses, "/v4/");
+ eventBus.register(this);
}
- public boolean sslEnabled() {
- return address().startsWith("https://");
- }
-
- public String address() {
- synchronized (this) {
- index++;
- if (index >= addresses.size()) {
- index = 0;
- }
- return addresses.get(index);
- }
- }
- public String formatUrl(String url, boolean absoluteUrl) {
- return absoluteUrl ? address() + url : formatAddress(address()) + url;
+ @Subscribe
+ public void onRefreshEndpointEvent(RefreshEndpointEvent event) {
+ refreshEndpoint(event, "SERVICECENTER");
Review comment:
Define constants in RefreshEndpointEvent
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]