DATAREDIS-720 - Polishing.
Add missing @Nullable annotatione, use early return and favor while(true) over for(;;). Original Pull Request: #290
This commit is contained in:
@@ -805,6 +805,7 @@ public class LettuceConnectionFactory
|
||||
* @return the shared connection using {@literal byte} array encoding for imperative API use. {@literal null} if
|
||||
* {@link #getShareNativeConnection() connection sharing} is disabled.
|
||||
*/
|
||||
@Nullable
|
||||
protected StatefulRedisConnection<byte[], byte[]> getSharedConnection() {
|
||||
return shareNativeConnection ? (StatefulRedisConnection) getOrCreateSharedConnection().getConnection() : null;
|
||||
}
|
||||
@@ -814,6 +815,7 @@ public class LettuceConnectionFactory
|
||||
* {@link #getShareNativeConnection() connection sharing} is disabled.
|
||||
* @since 2.0.1
|
||||
*/
|
||||
@Nullable
|
||||
protected StatefulConnection<ByteBuffer, ByteBuffer> getSharedReactiveConnection() {
|
||||
return shareNativeConnection ? getOrCreateSharedReactiveConnection().getConnection() : null;
|
||||
}
|
||||
@@ -928,13 +930,14 @@ public class LettuceConnectionFactory
|
||||
*
|
||||
* @param <E> connection encoding.
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
* @since 2.1
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
class SharedConnection<E> {
|
||||
|
||||
private final LettuceConnectionProvider connectionProvider;
|
||||
private final boolean clusterEnabled;
|
||||
private final boolean shareNativeClusterConnection;
|
||||
|
||||
/** Synchronization monitor for the shared Connection */
|
||||
private final Object connectionMonitor = new Object();
|
||||
@@ -947,6 +950,7 @@ public class LettuceConnectionFactory
|
||||
*
|
||||
* @return the connection.
|
||||
*/
|
||||
@Nullable
|
||||
StatefulConnection<E, E> getConnection() {
|
||||
|
||||
synchronized (this.connectionMonitor) {
|
||||
@@ -968,20 +972,20 @@ public class LettuceConnectionFactory
|
||||
*
|
||||
* @return the connection.
|
||||
*/
|
||||
@Nullable
|
||||
private StatefulConnection<E, E> getNativeConnection() {
|
||||
|
||||
try {
|
||||
|
||||
StatefulConnection<E, E> connection;
|
||||
|
||||
if ((isClusterAware() && clusterEnabled) || !isClusterAware()) {
|
||||
connection = connectionProvider.getConnection(StatefulConnection.class);
|
||||
if (connection instanceof StatefulRedisConnection && getDatabase() > 0) {
|
||||
((StatefulRedisConnection) connection).sync().select(getDatabase());
|
||||
}
|
||||
} else {
|
||||
connection = null;
|
||||
if (isClusterAware() && !shareNativeClusterConnection) {
|
||||
return null;
|
||||
}
|
||||
|
||||
StatefulConnection<E, E> connection = connectionProvider.getConnection(StatefulConnection.class);
|
||||
if (connection instanceof StatefulRedisConnection && getDatabase() > 0) {
|
||||
((StatefulRedisConnection) connection).sync().select(getDatabase());
|
||||
}
|
||||
|
||||
return connection;
|
||||
} catch (RedisException e) {
|
||||
throw new RedisConnectionFailureException("Unable to connect to Redis", e);
|
||||
|
||||
@@ -317,6 +317,7 @@ class LettuceReactiveRedisConnection implements ReactiveRedisConnection {
|
||||
* </ol>
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
* @since 2.0.1
|
||||
*/
|
||||
static class AsyncConnect {
|
||||
@@ -345,12 +346,12 @@ class LettuceReactiveRedisConnection implements ReactiveRedisConnection {
|
||||
* Obtain a connection publisher. This method connects asynchronously by requesting a connection from
|
||||
* {@link LettuceConnectionProvider} with non-blocking synchronization if called concurrently.
|
||||
*
|
||||
* @return
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
Mono<StatefulConnection<ByteBuffer, ByteBuffer>> getConnection() {
|
||||
|
||||
if (state.get() == State.CLOSED) {
|
||||
throw new IllegalStateException("Connection is closed!");
|
||||
throw new IllegalStateException("Unable to connect. Connection is closed!");
|
||||
}
|
||||
|
||||
CompletableFuture<StatefulConnection<ByteBuffer, ByteBuffer>> connection = this.connection;
|
||||
@@ -363,7 +364,7 @@ class LettuceReactiveRedisConnection implements ReactiveRedisConnection {
|
||||
this.connection = connectionPublisher.toFuture();
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
while (true) {
|
||||
|
||||
connection = this.connection;
|
||||
if (connection != null) {
|
||||
|
||||
Reference in New Issue
Block a user