1313
1414public class DefaultJedisSocketFactory implements JedisSocketFactory {
1515
16- private String host = Protocol .DEFAULT_HOST ;
17- private int port = Protocol .DEFAULT_PORT ;
16+ protected static final HostAndPort DEFAULT_HOST_AND_PORT = new HostAndPort (Protocol .DEFAULT_HOST , Protocol .DEFAULT_PORT );
17+
18+ private HostAndPort hostAndPort = DEFAULT_HOST_AND_PORT ;
1819 private int connectionTimeout = Protocol .DEFAULT_TIMEOUT ;
1920 private int soTimeout = Protocol .DEFAULT_TIMEOUT ;
2021 private boolean ssl = false ;
@@ -26,30 +27,33 @@ public class DefaultJedisSocketFactory implements JedisSocketFactory {
2627 public DefaultJedisSocketFactory () {
2728 }
2829
30+ public DefaultJedisSocketFactory (HostAndPort hostAndPort ) {
31+ this (hostAndPort , null );
32+ }
33+
2934 @ Deprecated
3035 public DefaultJedisSocketFactory (String host , int port , int connectionTimeout , int soTimeout ,
3136 boolean ssl , SSLSocketFactory sslSocketFactory , SSLParameters sslParameters ,
3237 HostnameVerifier hostnameVerifier ) {
33- setHost (host );
34- setPort (port );
35- setConnectionTimeout (connectionTimeout );
36- setSoTimeout (soTimeout );
37- setSsl (ssl );
38- setSslSocketFactory (sslSocketFactory );
39- setSslParameters (sslParameters );
40- setHostnameVerifier (hostnameVerifier );
38+ this .hostAndPort = new HostAndPort (host , port );
39+ this .connectionTimeout = connectionTimeout ;
40+ this .soTimeout = soTimeout ;
41+ this .ssl = ssl ;
42+ this .sslSocketFactory = sslSocketFactory ;
43+ this .sslParameters = sslParameters ;
44+ this .hostnameVerifier = hostnameVerifier ;
4145 }
4246
4347 public DefaultJedisSocketFactory (HostAndPort hostAndPort , JedisClientConfig config ) {
44- setHostAndPort ( hostAndPort ) ;
48+ this . hostAndPort = hostAndPort ;
4549 if (config != null ) {
46- setConnectionTimeout ( config .getConnectionTimeout () );
47- setSoTimeout ( config .getSoTimeout () );
48- setSsl ( config .isSsl () );
49- setSslSocketFactory ( config .getSslSocketFactory () );
50- setSslParameters ( config .getSslParameters () );
51- setHostnameVerifier ( config .getHostnameVerifier () );
52- setHostAndPortMapper ( config .getHostAndPortMapper () );
50+ this . connectionTimeout = config .getConnectionTimeout ();
51+ this . soTimeout = config .getSoTimeout ();
52+ this . ssl = config .isSsl ();
53+ this . sslSocketFactory = config .getSslSocketFactory ();
54+ this . sslParameters = config .getSslParameters ();
55+ this . hostnameVerifier = config .getHostnameVerifier ();
56+ this . hostAndPortMapper = config .getHostAndPortMapper ();
5357 }
5458 }
5559
@@ -83,9 +87,9 @@ public Socket createSocket() throws JedisConnectionException {
8387
8488 HostnameVerifier hostnameVerifier = getHostnameVerifier ();
8589 if (null != hostnameVerifier
86- && !hostnameVerifier .verify (getHost (), ((SSLSocket ) socket ).getSession ())) {
90+ && !hostnameVerifier .verify (hostAndPort . getHost (), ((SSLSocket ) socket ).getSession ())) {
8791 String message = String .format (
88- "The connection to '%s' failed ssl/tls hostname verification." , getHost ());
92+ "The connection to '%s' failed ssl/tls hostname verification." , hostAndPort . getHost ());
8993 throw new JedisConnectionException (message );
9094 }
9195 }
@@ -105,43 +109,44 @@ public HostAndPort getSocketHostAndPort() {
105109 HostAndPort hostAndPort = getHostAndPort ();
106110 if (mapper != null ) {
107111 HostAndPort mapped = mapper .getHostAndPort (hostAndPort );
108- if (mapped != null ) return mapped ;
112+ if (mapped != null ) {
113+ return mapped ;
114+ }
109115 }
110116 return hostAndPort ;
111117 }
112118
113119 public HostAndPort getHostAndPort () {
114- return new HostAndPort ( this .host , this . port ) ;
120+ return this .hostAndPort ;
115121 }
116122
117- public void setHostAndPort (HostAndPort hostPort ) {
118- this .host = hostPort .getHost ();
119- this .port = hostPort .getPort ();
123+ public void setHostAndPort (HostAndPort hostAndPort ) {
124+ this .hostAndPort = hostAndPort ;
120125 }
121126
122127 @ Override
123128 public String getDescription () {
124- return host + ":" + port ;
129+ return this . hostAndPort . toString () ;
125130 }
126131
127132 @ Override
128133 public String getHost () {
129- return this .host ;
134+ return this .hostAndPort . getHost () ;
130135 }
131136
132137 @ Override
133138 public void setHost (String host ) {
134- this .host = host ;
139+ this .hostAndPort = new HostAndPort ( host , this . hostAndPort . getPort ()) ;
135140 }
136141
137142 @ Override
138143 public int getPort () {
139- return this .port ;
144+ return this .hostAndPort . getPort () ;
140145 }
141146
142147 @ Override
143148 public void setPort (int port ) {
144- this .port = port ;
149+ this .hostAndPort = new HostAndPort ( this . hostAndPort . getHost (), port ) ;
145150 }
146151
147152 @ Override
0 commit comments