Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/main/java/io/lettuce/core/AbstractRedisClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
package io.lettuce.core;

import java.io.Closeable;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.time.Duration;
import java.util.ArrayList;
Expand All @@ -34,6 +36,7 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

import io.lettuce.core.MaintenanceEventsOptions.AddressTypeSource;
import reactor.core.publisher.Mono;
import io.lettuce.core.event.command.CommandListener;
import io.lettuce.core.event.connection.ConnectEvent;
Expand Down Expand Up @@ -629,8 +632,16 @@ private CompletableFuture<Void> closeClientResources(long quietPeriod, long time
}

protected RedisHandshake createHandshake(ConnectionState state) {
AddressTypeSource source = null;
if (clientOptions.getMaintenanceEventsOptions().supportsMaintenanceEvents()) {
LettuceAssert.notNull(clientOptions.getMaintenanceEventsOptions().getAddressTypeSource(),
"Address type source must not be null");

source = clientOptions.getMaintenanceEventsOptions().getAddressTypeSource();
}

return new RedisHandshake(clientOptions.getConfiguredProtocolVersion(), clientOptions.isPingBeforeActivateConnection(),
state);
state, source);
}

}
32 changes: 16 additions & 16 deletions src/main/java/io/lettuce/core/ClientOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class ClientOptions implements Serializable {

public static final boolean DEFAULT_AUTO_RECONNECT = true;

public static final boolean DEFAULT_SUPPORT_MAINTENANCE_EVENTS = false;
public static final MaintenanceEventsOptions DEFAULT_MAINTENANCE_EVENTS_OPTIONS = MaintenanceEventsOptions.disabled();

public static final Predicate<RedisCommand<?, ?, ?>> DEFAULT_REPLAY_FILTER = (cmd) -> false;

Expand Down Expand Up @@ -98,7 +98,7 @@ public class ClientOptions implements Serializable {

private final boolean autoReconnect;

private final boolean supportMaintenanceEvents;
private final MaintenanceEventsOptions maintenanceEventsOptions;

private final Predicate<RedisCommand<?, ?, ?>> replayFilter;

Expand Down Expand Up @@ -136,7 +136,7 @@ public class ClientOptions implements Serializable {

protected ClientOptions(Builder builder) {
this.autoReconnect = builder.autoReconnect;
this.supportMaintenanceEvents = builder.supportMaintenanceEvents;
this.maintenanceEventsOptions = builder.maintenanceEventsOptions;
this.replayFilter = builder.replayFilter;
this.cancelCommandsOnReconnectFailure = builder.cancelCommandsOnReconnectFailure;
this.decodeBufferPolicy = builder.decodeBufferPolicy;
Expand All @@ -158,7 +158,7 @@ protected ClientOptions(Builder builder) {

protected ClientOptions(ClientOptions original) {
this.autoReconnect = original.isAutoReconnect();
this.supportMaintenanceEvents = original.supportsMaintenanceEvents();
this.maintenanceEventsOptions = original.getMaintenanceEventsOptions();
this.replayFilter = original.getReplayFilter();
this.cancelCommandsOnReconnectFailure = original.isCancelCommandsOnReconnectFailure();
this.decodeBufferPolicy = original.getDecodeBufferPolicy();
Expand Down Expand Up @@ -213,7 +213,7 @@ public static class Builder {

private boolean autoReconnect = DEFAULT_AUTO_RECONNECT;

private boolean supportMaintenanceEvents = DEFAULT_SUPPORT_MAINTENANCE_EVENTS;
private MaintenanceEventsOptions maintenanceEventsOptions = DEFAULT_MAINTENANCE_EVENTS_OPTIONS;

private Predicate<RedisCommand<?, ?, ?>> replayFilter = DEFAULT_REPLAY_FILTER;

Expand Down Expand Up @@ -268,14 +268,14 @@ public Builder autoReconnect(boolean autoReconnect) {
* Configure whether the driver should listen for server events that notify on current maintenance activities. When
* enabled, this option will help with the connection handover and reduce the number of failed commands. This feature
* requires the server to support maintenance events. Defaults to {@code false}. See
* {@link #DEFAULT_SUPPORT_MAINTENANCE_EVENTS}.
* {@link #DEFAULT_MAINTENANCE_EVENTS_OPTIONS}.
*
* @param supportEvents true/false
* @param maintenanceEventsOptions true/false
* @return {@code this}
* @since 7.0
*/
public Builder supportMaintenanceEvents(boolean supportEvents) {
this.supportMaintenanceEvents = supportEvents;
public Builder supportMaintenanceEvents(MaintenanceEventsOptions maintenanceEventsOptions) {
this.maintenanceEventsOptions = maintenanceEventsOptions;
return this;
}

Expand Down Expand Up @@ -574,7 +574,7 @@ public ClientOptions build() {
public ClientOptions.Builder mutate() {
Builder builder = new Builder();

builder.autoReconnect(isAutoReconnect()).supportMaintenanceEvents(supportsMaintenanceEvents())
builder.autoReconnect(isAutoReconnect()).supportMaintenanceEvents(getMaintenanceEventsOptions())
.cancelCommandsOnReconnectFailure(isCancelCommandsOnReconnectFailure()).replayFilter(getReplayFilter())
.decodeBufferPolicy(getDecodeBufferPolicy()).disconnectedBehavior(getDisconnectedBehavior())
.reauthenticateBehavior(getReauthenticateBehaviour()).readOnlyCommands(getReadOnlyCommands())
Expand All @@ -601,15 +601,15 @@ public boolean isAutoReconnect() {
}

/**
* Returns whether the client supports maintenance events.
* Returns the {@link MaintenanceEventsOptions} to listen for server events that notify on current maintenance activities.
*
* @return {@code true} if maintenance events are supported.
* @return {@link MaintenanceEventsOptions}
* @since 7.0
* @see #DEFAULT_SUPPORT_MAINTENANCE_EVENTS
* @see #supportsMaintenanceEvents()
* @see #DEFAULT_MAINTENANCE_EVENTS_OPTIONS
* @see #getMaintenanceEventsOptions()
*/
public boolean supportsMaintenanceEvents() {
return supportMaintenanceEvents;
public MaintenanceEventsOptions getMaintenanceEventsOptions() {
return maintenanceEventsOptions;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/lettuce/core/ConnectionBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ protected ConnectionWatchdog createConnectionWatchdog() {
LettuceAssert.assertState(socketAddressSupplier != null, "SocketAddressSupplier must be set for autoReconnect=true");

ConnectionWatchdog watchdog;
if (clientOptions.supportsMaintenanceEvents()) {
if (clientOptions.getMaintenanceEventsOptions().supportsMaintenanceEvents()) {
watchdog = new MaintenanceAwareConnectionWatchdog(clientResources.reconnectDelay(), clientOptions, bootstrap,
clientResources.timer(), clientResources.eventExecutorGroup(), socketAddressSupplier, reconnectionListener,
connection, clientResources.eventBus(), endpoint);
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/io/lettuce/core/ConnectionMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class ConnectionMetadata {

private volatile String libraryVersion;

private volatile boolean sslEnabled;

public ConnectionMetadata() {
}

Expand All @@ -23,13 +25,15 @@ public void apply(RedisURI redisURI) {
setClientName(redisURI.getClientName());
setLibraryName(redisURI.getLibraryName());
setLibraryVersion(redisURI.getLibraryVersion());
setSslEnabled(redisURI.isSsl());
}

public void apply(ConnectionMetadata metadata) {

setClientName(metadata.getClientName());
setLibraryName(metadata.getLibraryName());
setLibraryVersion(metadata.getLibraryVersion());
setSslEnabled(metadata.isSslEnabled());
}

protected void setClientName(String clientName) {
Expand All @@ -56,4 +60,12 @@ String getLibraryVersion() {
return libraryVersion;
}

boolean isSslEnabled() {
return sslEnabled;
}

void setSslEnabled(boolean sslEnabled) {
this.sslEnabled = sslEnabled;
}

}
Loading