Skip to content

Commit

Permalink
feature_Support_reconnect_backoff_interface
Browse files Browse the repository at this point in the history
  • Loading branch information
cmgyqjj committed Sep 25, 2024
1 parent 6fcf621 commit 22429e1
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ public interface ClientBuilder {
ClientBuilder okHttpClient(OkHttpClient okHttpClient);
ClientBuilder messageListener(MessageListener messageListener);
ClientBuilder callbackThreadPool(ThreadPoolExecutor callbackThreadPool);
ClientBuilder backoffStrategy(String backoffStrategy);
ClientBuilder backoffStrategy(BackoffStrategy backoffStrategy);
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,8 @@ public ClientBuilder callbackThreadPool(ThreadPoolExecutor callbackThreadPool) {
}

@Override
public ClientBuilder backoffStrategy(String backoffStrategy) {
Class<?> clazz = null;
try {
clazz = Class.forName(backoffStrategy);
Constructor<?> constructor = clazz.getDeclaredConstructor();
this.conf.setBackoffStrategy((BackoffStrategy) constructor.newInstance());
} catch (Exception e) {
logger.error("error loader backoffStrategy, using default RandomBackoff", e);
}
public ClientBuilder backoffStrategy(BackoffStrategy backoffStrategy) {
this.conf.setBackoffStrategy(backoffStrategy);
return this;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.crossoverjie.cim.client.sdk;

import com.crossoverjie.cim.client.sdk.impl.ClientConfigurationData;
import com.crossoverjie.cim.client.sdk.io.backoff.RandomBackoff;
import com.crossoverjie.cim.client.sdk.route.AbstractRouteBaseTest;
import com.crossoverjie.cim.common.pojo.CIMUserInfo;
import com.crossoverjie.cim.route.api.vo.req.P2PReqVO;
Expand Down Expand Up @@ -224,7 +225,7 @@ public void testReconnect() throws Exception {
.userName(zs)
.userId(zsId)
.build();
var backoffStrategy = "com.crossoverjie.cim.client.sdk.io.backoff.RandomBackoff";
var backoffStrategy = new RandomBackoff();

@Cleanup
Client client1 = Client.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public class AppConfiguration {

@Value("${cim.reconnect.count}")
private int reconnectCount;
@Value("${cim.reconnect.backoff.strategy}")
private String backoffStrategy;

@Value("${cim.route.url}")
private String routeUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public Client buildClient(@Qualifier("callBackThreadPool") ThreadPoolExecutor ca
.okHttpClient(okHttpClient)
.messageListener(new MsgCallBackListener(msgLogger))
.callbackThreadPool(callbackThreadPool)
.backoffStrategy(appConfiguration.getBackoffStrategy())
.backoffStrategy(new RandomBackoff())
.build();
}

Expand Down

0 comments on commit 22429e1

Please sign in to comment.