Skip to content

Commit

Permalink
Introduce template method to supply a custom ClusterTopologyRefresh i…
Browse files Browse the repository at this point in the history
…mplementation #1598
  • Loading branch information
mp911de committed Jan 22, 2021
1 parent 121c2f4 commit 230d7ba
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/main/java/io/lettuce/core/cluster/RedisClusterClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ public class RedisClusterClient extends AbstractRedisClient {

private static final InternalLogger logger = InternalLoggerFactory.getInstance(RedisClusterClient.class);

private final ClusterTopologyRefresh refresh = ClusterTopologyRefresh.create(new NodeConnectionFactoryImpl(),
getResources());
private final ClusterTopologyRefresh refresh;

private final ClusterTopologyRefreshScheduler topologyRefreshScheduler = new ClusterTopologyRefreshScheduler(
this::getClusterClientOptions, this::getPartitions, this::refreshPartitionsAsync, getResources());
Expand All @@ -158,7 +157,8 @@ protected RedisClusterClient() {

super(null);

initialUris = Collections.emptyList();
this.initialUris = Collections.emptyList();
this.refresh = createTopologyRefresh();
}

/**
Expand All @@ -178,6 +178,7 @@ protected RedisClusterClient(ClientResources clientResources, Iterable<RedisURI>
assertSameOptions(redisURIs);

this.initialUris = Collections.unmodifiableList(LettuceLists.newList(redisURIs));
this.refresh = createTopologyRefresh();

setDefaultTimeout(getFirstUri().getTimeout());
setOptions(ClusterClientOptions.create());
Expand Down Expand Up @@ -1089,6 +1090,16 @@ protected <T extends Closeable> void forEachCloseable(Predicate<? super Closeabl
}
}

/**
* Template method to create {@link ClusterTopologyRefresh}. Can be overriden by subclasses.
*
* @return
* @since 6.0.3
*/
protected ClusterTopologyRefresh createTopologyRefresh() {
return ClusterTopologyRefresh.create(new NodeConnectionFactoryImpl(), getResources());
}

/**
* Returns {@code true} if {@link ClusterTopologyRefreshOptions#useDynamicRefreshSources() dynamic refresh sources} are
* enabled.
Expand Down

0 comments on commit 230d7ba

Please sign in to comment.