diff --git a/cim-client-sdk/src/main/java/com/crossoverjie/cim/client/sdk/ClientBuilder.java b/cim-client-sdk/src/main/java/com/crossoverjie/cim/client/sdk/ClientBuilder.java index 138aac1f..783b3b3c 100644 --- a/cim-client-sdk/src/main/java/com/crossoverjie/cim/client/sdk/ClientBuilder.java +++ b/cim-client-sdk/src/main/java/com/crossoverjie/cim/client/sdk/ClientBuilder.java @@ -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); } diff --git a/cim-client-sdk/src/main/java/com/crossoverjie/cim/client/sdk/impl/ClientBuilderImpl.java b/cim-client-sdk/src/main/java/com/crossoverjie/cim/client/sdk/impl/ClientBuilderImpl.java index 2f2bbab0..80034b28 100644 --- a/cim-client-sdk/src/main/java/com/crossoverjie/cim/client/sdk/impl/ClientBuilderImpl.java +++ b/cim-client-sdk/src/main/java/com/crossoverjie/cim/client/sdk/impl/ClientBuilderImpl.java @@ -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; } } diff --git a/cim-client-sdk/src/test/java/com/crossoverjie/cim/client/sdk/ClientTest.java b/cim-client-sdk/src/test/java/com/crossoverjie/cim/client/sdk/ClientTest.java index 11509998..54dca1ea 100644 --- a/cim-client-sdk/src/test/java/com/crossoverjie/cim/client/sdk/ClientTest.java +++ b/cim-client-sdk/src/test/java/com/crossoverjie/cim/client/sdk/ClientTest.java @@ -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; @@ -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() diff --git a/cim-client/src/main/java/com/crossoverjie/cim/client/config/AppConfiguration.java b/cim-client/src/main/java/com/crossoverjie/cim/client/config/AppConfiguration.java index 41e95530..a0ffad31 100644 --- a/cim-client/src/main/java/com/crossoverjie/cim/client/config/AppConfiguration.java +++ b/cim-client/src/main/java/com/crossoverjie/cim/client/config/AppConfiguration.java @@ -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; diff --git a/cim-client/src/main/java/com/crossoverjie/cim/client/config/BeanConfig.java b/cim-client/src/main/java/com/crossoverjie/cim/client/config/BeanConfig.java index db0205b3..170eca64 100644 --- a/cim-client/src/main/java/com/crossoverjie/cim/client/config/BeanConfig.java +++ b/cim-client/src/main/java/com/crossoverjie/cim/client/config/BeanConfig.java @@ -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(); }