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
2 changes: 1 addition & 1 deletion src/main/java/io/lettuce/core/CommandListenerWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
* @since 6.1
*/
@SuppressWarnings("unchecked")
public class CommandListenerWriter implements RedisChannelWriter {
public class CommandListenerWriter implements RedisChannelWriter, Delegating<RedisChannelWriter> {

private final RedisChannelWriter delegate;

Expand Down
35 changes: 35 additions & 0 deletions src/main/java/io/lettuce/core/Delegating.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.lettuce.core;

/**
* A delegating interface that allows access to the underlying delegate.
*
* @param <T> the type of the delegate.
*
* @author Ali Takavci
* @since 7.1
*/
public interface Delegating<T> {

/**
* The underlying delegate.
*
* @return never {@code null}.
*/
T getDelegate();

/**
* Unwrap the underlying delegate, through the recursively wrapped {@link Delegating} interfaces if available.
*
* @return the unwrapped delegate.
*/
default T unwrap() {
T delegate = getDelegate();
if (delegate instanceof Delegating) {
@SuppressWarnings("unchecked")
T unwrapped = ((Delegating<T>) delegate).unwrap();
return unwrapped;
}
return delegate;
}

}
24 changes: 21 additions & 3 deletions src/main/java/io/lettuce/core/RedisClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ private <K, V> ConnectionFuture<StatefulRedisConnection<K, V>> connectStandalone

logger.debug("Trying to get a Redis connection for: {}", redisURI);

DefaultEndpoint endpoint = new DefaultEndpoint(getOptions(), getResources());
DefaultEndpoint endpoint = createEndpoint();
RedisChannelWriter writer = endpoint;

if (CommandExpiryWriter.isSupported(getOptions())) {
Expand Down Expand Up @@ -408,7 +408,7 @@ private <K, V> ConnectionFuture<StatefulRedisPubSubConnection<K, V>> connectPubS
assertNotNull(codec);
checkValidRedisURI(redisURI);

PubSubEndpoint<K, V> endpoint = new PubSubEndpoint<>(getOptions(), getResources());
PubSubEndpoint<K, V> endpoint = createPubSubEndpoint();
RedisChannelWriter writer = endpoint;

if (CommandExpiryWriter.isSupported(getOptions())) {
Expand Down Expand Up @@ -575,7 +575,7 @@ private <K, V> ConnectionFuture<StatefulRedisSentinelConnection<K, V>> doConnect
connectionBuilder.clientOptions(ClientOptions.copyOf(getOptions()));
connectionBuilder.clientResources(getResources());

DefaultEndpoint endpoint = new DefaultEndpoint(getOptions(), getResources());
DefaultEndpoint endpoint = createEndpoint();
RedisChannelWriter writer = endpoint;

if (CommandExpiryWriter.isSupported(getOptions())) {
Expand Down Expand Up @@ -840,4 +840,22 @@ private void checkForRedisURI() {
checkValidRedisURI(this.redisURI);
}

/**
* Create a new {@link DefaultEndpoint}. Subclasses may override this method to change the default behavior.
*
* @return a new {@link DefaultEndpoint}.
*/
protected DefaultEndpoint createEndpoint() {
return new DefaultEndpoint(getOptions(), getResources());
}

/**
* Create a new {@link PubSubEndpoint}. Subclasses may override this method to change the default behavior.
*
* @return a new {@link PubSubEndpoint}.
*/
protected <K, V> PubSubEndpoint<K, V> createPubSubEndpoint() {
return new PubSubEndpoint<>(getOptions(), getResources());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ private Object doInvoke(Object[] args, Method targetMethod, StatefulRedisConnect
return targetMethod.invoke(executionModel == ExecutionModel.REACTIVE ? it.reactive() : it.async(), argsToUse);
}

@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
private Object getExecutions(Map<RedisClusterNode, Object> executions, long timeoutNs)
throws ExecutionException, InterruptedException {

if (executionModel == ExecutionModel.REACTIVE) {
Map<RedisClusterNode, CompletionStage<? extends Publisher<?>>> reactiveExecutions = (Map) executions;
return new ReactiveExecutionsImpl<>(reactiveExecutions);
return new ReactiveExecutionsImpl(reactiveExecutions);
}

Map<RedisClusterNode, CompletionStage<?>> asyncExecutions = (Map) executions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.concurrent.TimeUnit;

import io.lettuce.core.ClientOptions;
import io.lettuce.core.Delegating;
import io.lettuce.core.RedisChannelWriter;
import io.lettuce.core.TimeoutOptions;
import io.lettuce.core.internal.ExceptionFactory;
Expand All @@ -45,7 +46,7 @@
* @since 5.1
* @see io.lettuce.core.TimeoutOptions
*/
public class CommandExpiryWriter implements RedisChannelWriter {
public class CommandExpiryWriter implements RedisChannelWriter, Delegating<RedisChannelWriter> {

private final RedisChannelWriter delegate;

Expand Down