Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename socket timeout params and builder methods #2422

Merged
merged 3 commits into from
Mar 18, 2021
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
84 changes: 42 additions & 42 deletions src/main/java/redis/clients/jedis/BinaryJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ private void initializeFromClientConfig(JedisClientConfig config) {
}

public BinaryJedis(final String host, final int port, final boolean ssl) {
this(host, port, DefaultJedisClientConfig.builder().withSsl(ssl).build());
this(host, port, DefaultJedisClientConfig.builder().ssl(ssl).build());
}

public BinaryJedis(final String host, final int port, final boolean ssl,
final SSLSocketFactory sslSocketFactory, final SSLParameters sslParameters,
final HostnameVerifier hostnameVerifier) {
this(host, port, DefaultJedisClientConfig.builder().withSsl(ssl)
.withSslSocketFactory(sslSocketFactory).withSslParameters(sslParameters)
.withHostnameVerifier(hostnameVerifier).build());
this(host, port, DefaultJedisClientConfig.builder().ssl(ssl)
.sslSocketFactory(sslSocketFactory).sslParameters(sslParameters)
.hostnameVerifier(hostnameVerifier).build());
}

public BinaryJedis(final String host, final int port, final int timeout) {
Expand All @@ -145,51 +145,51 @@ public BinaryJedis(final String host, final int port, final int timeout, final b
public BinaryJedis(final String host, final int port, final int connectionTimeout,
final int soTimeout) {
this(host, port, DefaultJedisClientConfig.builder()
.withConnectionTimeoutMillis(connectionTimeout).withSoTimeoutMillis(soTimeout).build());
.connectionTimeoutMillis(connectionTimeout).socketTimeoutMillis(soTimeout).build());
}

public BinaryJedis(final String host, final int port, final int connectionTimeout,
final int soTimeout, final int infiniteSoTimeout) {
this(host, port, DefaultJedisClientConfig.builder()
.withConnectionTimeoutMillis(connectionTimeout).withSoTimeoutMillis(soTimeout)
.withInfiniteSoTimeoutMillis(infiniteSoTimeout).build());
.connectionTimeoutMillis(connectionTimeout).socketTimeoutMillis(soTimeout)
.blockingSocketTimeoutMillis(infiniteSoTimeout).build());
}

public BinaryJedis(final String host, final int port, final int connectionTimeout,
final int soTimeout, final boolean ssl) {
this(host, port, DefaultJedisClientConfig.builder()
.withConnectionTimeoutMillis(connectionTimeout).withSoTimeoutMillis(soTimeout).withSsl(ssl)
.connectionTimeoutMillis(connectionTimeout).socketTimeoutMillis(soTimeout).ssl(ssl)
.build());
}

public BinaryJedis(final String host, final int port, final int connectionTimeout,
final int soTimeout, final boolean ssl, final SSLSocketFactory sslSocketFactory,
final SSLParameters sslParameters, final HostnameVerifier hostnameVerifier) {
this(host, port, DefaultJedisClientConfig.builder()
.withConnectionTimeoutMillis(connectionTimeout).withSoTimeoutMillis(soTimeout).withSsl(ssl)
.withSslSocketFactory(sslSocketFactory).withSslParameters(sslParameters)
.withHostnameVerifier(hostnameVerifier).build());
.connectionTimeoutMillis(connectionTimeout).socketTimeoutMillis(soTimeout).ssl(ssl)
.sslSocketFactory(sslSocketFactory).sslParameters(sslParameters)
.hostnameVerifier(hostnameVerifier).build());
}

public BinaryJedis(final String host, final int port, final int connectionTimeout,
final int soTimeout, final int infiniteSoTimeout, final boolean ssl,
final SSLSocketFactory sslSocketFactory, final SSLParameters sslParameters,
final HostnameVerifier hostnameVerifier) {
this(host, port, DefaultJedisClientConfig.builder()
.withConnectionTimeoutMillis(connectionTimeout).withSoTimeoutMillis(soTimeout)
.withInfiniteSoTimeoutMillis(infiniteSoTimeout).withSsl(ssl)
.withSslSocketFactory(sslSocketFactory).withSslParameters(sslParameters)
.withHostnameVerifier(hostnameVerifier).build());
.connectionTimeoutMillis(connectionTimeout).socketTimeoutMillis(soTimeout)
.blockingSocketTimeoutMillis(infiniteSoTimeout).ssl(ssl)
.sslSocketFactory(sslSocketFactory).sslParameters(sslParameters)
.hostnameVerifier(hostnameVerifier).build());
}

public BinaryJedis(final JedisShardInfo shardInfo) {
this(shardInfo.getHost(), shardInfo.getPort(), DefaultJedisClientConfig.builder()
.withConnectionTimeoutMillis(shardInfo.getConnectionTimeout())
.withSoTimeoutMillis(shardInfo.getSoTimeout()).withUser(shardInfo.getUser())
.withPassword(shardInfo.getPassword()).withDatabse(shardInfo.getDb())
.withSsl(shardInfo.getSsl()).withSslSocketFactory(shardInfo.getSslSocketFactory())
.withSslParameters(shardInfo.getSslParameters())
.withHostnameVerifier(shardInfo.getHostnameVerifier()).build());
.connectionTimeoutMillis(shardInfo.getConnectionTimeout())
.socketTimeoutMillis(shardInfo.getSoTimeout()).user(shardInfo.getUser())
.password(shardInfo.getPassword()).databse(shardInfo.getDb())
.ssl(shardInfo.getSsl()).sslSocketFactory(shardInfo.getSslSocketFactory())
.sslParameters(shardInfo.getSslParameters())
.hostnameVerifier(shardInfo.getHostnameVerifier()).build());
}

public BinaryJedis(URI uri) {
Expand All @@ -199,8 +199,8 @@ public BinaryJedis(URI uri) {

public BinaryJedis(URI uri, final SSLSocketFactory sslSocketFactory,
final SSLParameters sslParameters, final HostnameVerifier hostnameVerifier) {
this(uri, DefaultJedisClientConfig.builder().withSslSocketFactory(sslSocketFactory)
.withSslParameters(sslParameters).withHostnameVerifier(hostnameVerifier).build());
this(uri, DefaultJedisClientConfig.builder().sslSocketFactory(sslSocketFactory)
.sslParameters(sslParameters).hostnameVerifier(hostnameVerifier).build());
}

public BinaryJedis(final URI uri, final int timeout) {
Expand All @@ -213,25 +213,25 @@ public BinaryJedis(final URI uri, final int timeout, final SSLSocketFactory sslS
}

public BinaryJedis(final URI uri, final int connectionTimeout, final int soTimeout) {
this(uri, DefaultJedisClientConfig.builder().withConnectionTimeoutMillis(connectionTimeout)
.withSoTimeoutMillis(soTimeout).build());
this(uri, DefaultJedisClientConfig.builder().connectionTimeoutMillis(connectionTimeout)
.socketTimeoutMillis(soTimeout).build());
}

public BinaryJedis(final URI uri, final int connectionTimeout, final int soTimeout,
final SSLSocketFactory sslSocketFactory, final SSLParameters sslParameters,
final HostnameVerifier hostnameVerifier) {
this(uri, DefaultJedisClientConfig.builder().withConnectionTimeoutMillis(connectionTimeout)
.withSoTimeoutMillis(soTimeout).withSslSocketFactory(sslSocketFactory)
.withSslParameters(sslParameters).withHostnameVerifier(hostnameVerifier).build());
this(uri, DefaultJedisClientConfig.builder().connectionTimeoutMillis(connectionTimeout)
.socketTimeoutMillis(soTimeout).sslSocketFactory(sslSocketFactory)
.sslParameters(sslParameters).hostnameVerifier(hostnameVerifier).build());
}

public BinaryJedis(final URI uri, final int connectionTimeout, final int soTimeout,
final int infiniteSoTimeout, final SSLSocketFactory sslSocketFactory,
final SSLParameters sslParameters, final HostnameVerifier hostnameVerifier) {
this(uri, DefaultJedisClientConfig.builder().withConnectionTimeoutMillis(connectionTimeout)
.withSoTimeoutMillis(soTimeout).withInfiniteSoTimeoutMillis(infiniteSoTimeout)
.withSslSocketFactory(sslSocketFactory).withSslParameters(sslParameters)
.withHostnameVerifier(hostnameVerifier).build());
this(uri, DefaultJedisClientConfig.builder().connectionTimeoutMillis(connectionTimeout)
.socketTimeoutMillis(soTimeout).blockingSocketTimeoutMillis(infiniteSoTimeout)
.sslSocketFactory(sslSocketFactory).sslParameters(sslParameters)
.hostnameVerifier(hostnameVerifier).build());
}

public BinaryJedis(final URI uri, JedisClientConfig config) {
Expand All @@ -240,15 +240,15 @@ public BinaryJedis(final URI uri, JedisClientConfig config) {
"Cannot open Redis connection due invalid URI \"%s\".", uri.toString()));
}
client = new Client(new HostAndPort(uri.getHost(), uri.getPort()), DefaultJedisClientConfig
.builder().withConnectionTimeoutMillis(config.getConnectionTimeoutMillis())
.withSoTimeoutMillis(config.getSoTimeoutMillis())
.withInfiniteSoTimeoutMillis(config.getInfiniteSoTimeoutMillis())
.withUser(JedisURIHelper.getUser(uri)).withPassword(JedisURIHelper.getPassword(uri))
.withDatabse(JedisURIHelper.getDBIndex(uri)).withClientName(config.getClientName())
.withSsl(JedisURIHelper.isRedisSSLScheme(uri))
.withSslSocketFactory(config.getSslSocketFactory())
.withSslParameters(config.getSslParameters())
.withHostnameVerifier(config.getHostnameVerifier()).build());
.builder().connectionTimeoutMillis(config.getConnectionTimeoutMillis())
.socketTimeoutMillis(config.getSocketTimeoutMillis())
.blockingSocketTimeoutMillis(config.getBlockingSocketTimeoutMillis())
.user(JedisURIHelper.getUser(uri)).password(JedisURIHelper.getPassword(uri))
.databse(JedisURIHelper.getDBIndex(uri)).clientName(config.getClientName())
.ssl(JedisURIHelper.isRedisSSLScheme(uri))
.sslSocketFactory(config.getSslSocketFactory())
.sslParameters(config.getSslParameters())
.hostnameVerifier(config.getHostnameVerifier()).build());
initializeFromURI(uri);
}

Expand All @@ -258,7 +258,7 @@ private static Client createClientFromURI(URI uri) {
"Cannot open Redis connection due invalid URI \"%s\".", uri.toString()));
}
return new Client(new HostAndPort(uri.getHost(), uri.getPort()), DefaultJedisClientConfig
.builder().withSsl(JedisURIHelper.isRedisSSLScheme(uri)).build());
.builder().ssl(JedisURIHelper.isRedisSSLScheme(uri)).build());
}

private void initializeFromURI(URI uri) {
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/redis/clients/jedis/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Connection(final String host, final int port) {
*/
@Deprecated
public Connection(final String host, final int port, final boolean ssl) {
this(new HostAndPort(host, port), DefaultJedisClientConfig.builder().withSsl(ssl).build());
this(new HostAndPort(host, port), DefaultJedisClientConfig.builder().ssl(ssl).build());
}

/**
Expand All @@ -65,15 +65,15 @@ public Connection(final String host, final int port, final boolean ssl) {
public Connection(final String host, final int port, final boolean ssl,
SSLSocketFactory sslSocketFactory, SSLParameters sslParameters,
HostnameVerifier hostnameVerifier) {
this(new HostAndPort(host, port), DefaultJedisClientConfig.builder().withSsl(ssl)
.withSslSocketFactory(sslSocketFactory).withSslParameters(sslParameters)
.withHostnameVerifier(hostnameVerifier).build());
this(new HostAndPort(host, port), DefaultJedisClientConfig.builder().ssl(ssl)
.sslSocketFactory(sslSocketFactory).sslParameters(sslParameters)
.hostnameVerifier(hostnameVerifier).build());
}

public Connection(final HostAndPort hostAndPort, final JedisClientConfig clientConfig) {
this(new DefaultJedisSocketFactory(hostAndPort, clientConfig));
this.soTimeout = clientConfig.getSoTimeoutMillis();
this.infiniteSoTimeout = clientConfig.getInfiniteSoTimeoutMillis();
this.soTimeout = clientConfig.getSocketTimeoutMillis();
this.infiniteSoTimeout = clientConfig.getBlockingSocketTimeoutMillis();
}

public Connection(final JedisSocketFactory jedisSocketFactory) {
Expand Down
56 changes: 28 additions & 28 deletions src/main/java/redis/clients/jedis/DefaultJedisClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
public final class DefaultJedisClientConfig implements JedisClientConfig {

private final int connectionTimeoutMillis;
private final int soTimeoutMillis;
private final int infiniteSoTimeoutMillis;
private final int socketTimeoutMillis;
private final int blockingSocketTimeoutMillis;

private final String user;
private volatile String password;
Expand All @@ -24,12 +24,12 @@ public final class DefaultJedisClientConfig implements JedisClientConfig {
private final HostAndPortMapper hostAndPortMapper;

private DefaultJedisClientConfig(int connectionTimeoutMillis, int soTimeoutMillis,
int infiniteSoTimeoutMillis, String user, String password, int database, String clientName,
int blockingSocketTimeoutMillis, String user, String password, int database, String clientName,
boolean ssl, SSLSocketFactory sslSocketFactory, SSLParameters sslParameters,
HostnameVerifier hostnameVerifier, HostAndPortMapper hostAndPortMapper) {
this.connectionTimeoutMillis = connectionTimeoutMillis;
this.soTimeoutMillis = soTimeoutMillis;
this.infiniteSoTimeoutMillis = infiniteSoTimeoutMillis;
this.socketTimeoutMillis = soTimeoutMillis;
this.blockingSocketTimeoutMillis = blockingSocketTimeoutMillis;
this.user = user;
this.password = password;
this.database = database;
Expand All @@ -47,13 +47,13 @@ public int getConnectionTimeoutMillis() {
}

@Override
public int getSoTimeoutMillis() {
return soTimeoutMillis;
public int getSocketTimeoutMillis() {
return socketTimeoutMillis;
}

@Override
public int getInfiniteSoTimeoutMillis() {
return infiniteSoTimeoutMillis;
public int getBlockingSocketTimeoutMillis() {
return blockingSocketTimeoutMillis;
}

@Override
Expand Down Expand Up @@ -115,8 +115,8 @@ public static Builder builder() {
public static class Builder {

private int connectionTimeoutMillis = Protocol.DEFAULT_TIMEOUT;
private int soTimeoutMillis = Protocol.DEFAULT_TIMEOUT;
private int infiniteSoTimeoutMillis = 0;
private int socketTimeoutMillis = Protocol.DEFAULT_TIMEOUT;
private int blockingSocketTimeoutMillis = 0;

private String user = null;
private String password = null;
Expand All @@ -134,75 +134,75 @@ private Builder() {
}

public DefaultJedisClientConfig build() {
return new DefaultJedisClientConfig(connectionTimeoutMillis, soTimeoutMillis,
infiniteSoTimeoutMillis, user, password, databse, clientName, ssl, sslSocketFactory,
return new DefaultJedisClientConfig(connectionTimeoutMillis, socketTimeoutMillis,
blockingSocketTimeoutMillis, user, password, databse, clientName, ssl, sslSocketFactory,
sslParameters, hostnameVerifier, hostAndPortMapper);
}

public Builder withConnectionTimeoutMillis(int connectionTimeoutMillis) {
public Builder connectionTimeoutMillis(int connectionTimeoutMillis) {
this.connectionTimeoutMillis = connectionTimeoutMillis;
return this;
}

public Builder withSoTimeoutMillis(int soTimeoutMillis) {
this.soTimeoutMillis = soTimeoutMillis;
public Builder socketTimeoutMillis(int socketTimeoutMillis) {
this.socketTimeoutMillis = socketTimeoutMillis;
return this;
}

public Builder withInfiniteSoTimeoutMillis(int infiniteSoTimeoutMillis) {
this.infiniteSoTimeoutMillis = infiniteSoTimeoutMillis;
public Builder blockingSocketTimeoutMillis(int blockingSocketTimeoutMillis) {
this.blockingSocketTimeoutMillis = blockingSocketTimeoutMillis;
return this;
}

public Builder withUser(String user) {
public Builder user(String user) {
this.user = user;
return this;
}

public Builder withPassword(String password) {
public Builder password(String password) {
this.password = password;
return this;
}

public Builder withDatabse(int databse) {
public Builder databse(int databse) {
this.databse = databse;
return this;
}

public Builder withClientName(String clientName) {
public Builder clientName(String clientName) {
this.clientName = clientName;
return this;
}

public Builder withSsl(boolean ssl) {
public Builder ssl(boolean ssl) {
this.ssl = ssl;
return this;
}

public Builder withSslSocketFactory(SSLSocketFactory sslSocketFactory) {
public Builder sslSocketFactory(SSLSocketFactory sslSocketFactory) {
this.sslSocketFactory = sslSocketFactory;
return this;
}

public Builder withSslParameters(SSLParameters sslParameters) {
public Builder sslParameters(SSLParameters sslParameters) {
this.sslParameters = sslParameters;
return this;
}

public Builder withHostnameVerifier(HostnameVerifier hostnameVerifier) {
public Builder hostnameVerifier(HostnameVerifier hostnameVerifier) {
this.hostnameVerifier = hostnameVerifier;
return this;
}

public Builder withHostAndPortMapper(HostAndPortMapper hostAndPortMapper) {
public Builder hostAndPortMapper(HostAndPortMapper hostAndPortMapper) {
this.hostAndPortMapper = hostAndPortMapper;
return this;
}
}

public static DefaultJedisClientConfig copyConfig(JedisClientConfig copy) {
return new DefaultJedisClientConfig(copy.getConnectionTimeoutMillis(),
copy.getSoTimeoutMillis(), copy.getInfiniteSoTimeoutMillis(), copy.getUser(),
copy.getSocketTimeoutMillis(), copy.getBlockingSocketTimeoutMillis(), copy.getUser(),
copy.getPassword(), copy.getDatabase(), copy.getClientName(), copy.isSsl(),
copy.getSslSocketFactory(), copy.getSslParameters(), copy.getHostnameVerifier(),
copy.getHostAndPortMapper());
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/redis/clients/jedis/DefaultJedisSocketFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class DefaultJedisSocketFactory implements JedisSocketFactory {

private HostAndPort hostAndPort = DEFAULT_HOST_AND_PORT;
private int connectionTimeout = Protocol.DEFAULT_TIMEOUT;
private int soTimeout = Protocol.DEFAULT_TIMEOUT;
private int socketTimeout = Protocol.DEFAULT_TIMEOUT;
private boolean ssl = false;
private SSLSocketFactory sslSocketFactory = null;
private SSLParameters sslParameters = null;
Expand All @@ -33,12 +33,12 @@ public DefaultJedisSocketFactory(HostAndPort hostAndPort) {
}

@Deprecated
public DefaultJedisSocketFactory(String host, int port, int connectionTimeout, int soTimeout,
public DefaultJedisSocketFactory(String host, int port, int connectionTimeout, int socketTimeout,
boolean ssl, SSLSocketFactory sslSocketFactory, SSLParameters sslParameters,
HostnameVerifier hostnameVerifier) {
this.hostAndPort = new HostAndPort(host, port);
this.connectionTimeout = connectionTimeout;
this.soTimeout = soTimeout;
this.socketTimeout = socketTimeout;
this.ssl = ssl;
this.sslSocketFactory = sslSocketFactory;
this.sslParameters = sslParameters;
Expand All @@ -49,7 +49,7 @@ public DefaultJedisSocketFactory(HostAndPort hostAndPort, JedisClientConfig conf
this.hostAndPort = hostAndPort;
if (config != null) {
this.connectionTimeout = config.getConnectionTimeoutMillis();
this.soTimeout = config.getSoTimeoutMillis();
this.socketTimeout = config.getSocketTimeoutMillis();
this.ssl = config.isSsl();
this.sslSocketFactory = config.getSslSocketFactory();
this.sslParameters = config.getSslParameters();
Expand Down Expand Up @@ -162,12 +162,12 @@ public void setConnectionTimeout(int connectionTimeout) {

@Override
public int getSoTimeout() {
return this.soTimeout;
return this.socketTimeout;
}

@Override
public void setSoTimeout(int soTimeout) {
this.soTimeout = soTimeout;
this.socketTimeout = soTimeout;
}

public boolean isSsl() {
Expand Down
Loading