Skip to content

Commit

Permalink
[fix][sdk] add utilService to Services
Browse files Browse the repository at this point in the history
  • Loading branch information
wt0530 committed Jul 8, 2024
1 parent be6e1c8 commit 058ef42
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions java/dingo-sdk/src/main/java/io/dingodb/sdk/service/Services.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ public CoordinatorChannelProvider load(Set<Location> key) {
}
});

private static final LoadingCache<Set<Location>, CoordinatorChannelProvider> utilCache = CacheBuilder
.newBuilder()
.expireAfterAccess(60, TimeUnit.MINUTES)
.expireAfterWrite(60, TimeUnit.MINUTES)
.maximumSize(8)
.build(new CacheLoader<Set<Location>, CoordinatorChannelProvider>() {
@Override
public CoordinatorChannelProvider load(Set<Location> key) throws Exception {
return coordinatorServiceChannelProvider(key);
}
});

private static final LoadingCache<Set<Location>, LoadingCache<Long, RegionChannelProvider>> regionCache =
CacheBuilder.newBuilder()
.expireAfterAccess(30, TimeUnit.MINUTES)
Expand Down Expand Up @@ -204,6 +216,14 @@ public static VersionService versionService(Set<Location> locations) {
).getService();
}

@SneakyThrows
public static UtilService utilService(Set<Location> 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<Location> locations, DingoCommonId tableId, DingoCommonId regionId
Expand Down

0 comments on commit 058ef42

Please sign in to comment.