From 058ef42ee172832f3196c5ac8d5c40dca27a054d Mon Sep 17 00:00:00 2001 From: Tao Wang <18234030530@163.com> Date: Mon, 8 Jul 2024 18:43:36 +0800 Subject: [PATCH] [fix][sdk] add utilService to Services --- .../java/io/dingodb/sdk/service/Services.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/java/dingo-sdk/src/main/java/io/dingodb/sdk/service/Services.java b/java/dingo-sdk/src/main/java/io/dingodb/sdk/service/Services.java index 5e93a5dbf..5ad64aad1 100644 --- a/java/dingo-sdk/src/main/java/io/dingodb/sdk/service/Services.java +++ b/java/dingo-sdk/src/main/java/io/dingodb/sdk/service/Services.java @@ -93,6 +93,18 @@ public CoordinatorChannelProvider load(Set key) { } }); + private static final LoadingCache, CoordinatorChannelProvider> utilCache = CacheBuilder + .newBuilder() + .expireAfterAccess(60, TimeUnit.MINUTES) + .expireAfterWrite(60, TimeUnit.MINUTES) + .maximumSize(8) + .build(new CacheLoader, CoordinatorChannelProvider>() { + @Override + public CoordinatorChannelProvider load(Set key) throws Exception { + return coordinatorServiceChannelProvider(key); + } + }); + private static final LoadingCache, LoadingCache> regionCache = CacheBuilder.newBuilder() .expireAfterAccess(30, TimeUnit.MINUTES) @@ -204,6 +216,14 @@ public static VersionService versionService(Set locations) { ).getService(); } + @SneakyThrows + public static UtilService utilService(Set locations) { + Parameters.notEmpty(locations, "locations"); + return new ServiceCaller<>( + utilCache.get(locations), DEFAULT_RETRY_TIMES, DEFAULT, UtilService.Impl::new + ).getService(); + } + @SneakyThrows public static ChannelProvider regionChannelProvider( Set locations, DingoCommonId tableId, DingoCommonId regionId