1313
1414public class DefaultJedisSocketFactory implements JedisSocketFactory {
1515
16- private HostAndPort hostPort ; // TODO: should be final
17- private final JedisSocketConfig config ;
16+ private String host = Protocol .DEFAULT_HOST ;
17+ private int port = Protocol .DEFAULT_PORT ;
18+ private int connectionTimeout = Protocol .DEFAULT_TIMEOUT ;
19+ private int soTimeout = Protocol .DEFAULT_TIMEOUT ;
20+ private boolean ssl = false ;
21+ private SSLSocketFactory sslSocketFactory = null ;
22+ private SSLParameters sslParameters = null ;
23+ private HostnameVerifier hostnameVerifier = null ;
24+ private HostAndPortMapper hostAndPortMapper = null ;
25+
26+ public DefaultJedisSocketFactory () {
27+ }
1828
1929 @ Deprecated
2030 public DefaultJedisSocketFactory (String host , int port , int connectionTimeout , int soTimeout ,
2131 boolean ssl , SSLSocketFactory sslSocketFactory , SSLParameters sslParameters ,
2232 HostnameVerifier hostnameVerifier ) {
23- this (new HostAndPort (host , port ),
24- DefaultJedisSocketConfig .builder ()
25- .withConnectionTimeout (connectionTimeout )
26- .withSoTimeout (soTimeout )
27- .withSsl (ssl )
28- .withSslSocketFactory (sslSocketFactory )
29- .withSslParameters (sslParameters )
30- .withHostnameVerifier (hostnameVerifier )
31- .build ()
32- );
33+ setHost (host );
34+ setPort (port );
35+ setConnectionTimeout (connectionTimeout );
36+ setSoTimeout (soTimeout );
37+ setSsl (ssl );
38+ setSslSocketFactory (sslSocketFactory );
39+ setSslParameters (sslParameters );
40+ setHostnameVerifier (hostnameVerifier );
3341 }
3442
3543 public DefaultJedisSocketFactory (HostAndPort hostAndPort , JedisSocketConfig socketConfig ) {
36- this .hostPort = hostAndPort ;
37- this .config = socketConfig != null ? socketConfig : DefaultJedisSocketConfig .DEFAULT_SOCKET_CONFIG ;
44+ setHostAndPort (hostAndPort );
45+ if (socketConfig != null ) {
46+ setConnectionTimeout (socketConfig .getConnectionTimeout ());
47+ setSoTimeout (socketConfig .getSoTimeout ());
48+ setSsl (socketConfig .isSsl ());
49+ setSslSocketFactory (socketConfig .getSslSocketFactory ());
50+ setSslParameters (socketConfig .getSslParameters ());
51+ setHostnameVerifier (socketConfig .getHostnameVerifier ());
52+ setHostAndPortMapper (socketConfig .getHostAndPortMapper ());
53+ }
3854 }
3955
4056 @ Override
@@ -53,19 +69,19 @@ public Socket createSocket() throws JedisConnectionException {
5369 socket .connect (new InetSocketAddress (hostAndPort .getHost (), hostAndPort .getPort ()), getConnectionTimeout ());
5470 socket .setSoTimeout (getSoTimeout ());
5571
56- if (config . isSsl () ) {
57- SSLSocketFactory sslSocketFactory = config . getSslSocketFactory ();
72+ if (ssl ) {
73+ SSLSocketFactory sslSocketFactory = getSslSocketFactory ();
5874 if (null == sslSocketFactory ) {
5975 sslSocketFactory = (SSLSocketFactory ) SSLSocketFactory .getDefault ();
6076 }
6177 socket = sslSocketFactory .createSocket (socket , hostAndPort .getHost (), hostAndPort .getPort (), true );
6278
63- SSLParameters sslParameters = config . getSslParameters ();
79+ SSLParameters sslParameters = getSslParameters ();
6480 if (null != sslParameters ) {
6581 ((SSLSocket ) socket ).setSSLParameters (sslParameters );
6682 }
6783
68- HostnameVerifier hostnameVerifier = config . getHostnameVerifier ();
84+ HostnameVerifier hostnameVerifier = getHostnameVerifier ();
6985 if (null != hostnameVerifier
7086 && !hostnameVerifier .verify (getHost (), ((SSLSocket ) socket ).getSession ())) {
7187 String message = String .format (
@@ -84,12 +100,8 @@ public Socket createSocket() throws JedisConnectionException {
84100 }
85101 }
86102
87- public HostAndPort getHostAndPort () {
88- return this .hostPort ;
89- }
90-
91103 public HostAndPort getSocketHostAndPort () {
92- HostAndPortMapper mapper = config . getHostAndPortMapper ();
104+ HostAndPortMapper mapper = getHostAndPortMapper ();
93105 HostAndPort hostAndPort = getHostAndPort ();
94106 if (mapper != null ) {
95107 HostAndPort mapped = mapper .getHostAndPort (hostAndPort );
@@ -98,58 +110,97 @@ public HostAndPort getSocketHostAndPort() {
98110 return hostAndPort ;
99111 }
100112
113+ public HostAndPort getHostAndPort () {
114+ return new HostAndPort (this .host , this .port );
115+ }
116+
117+ public void setHostAndPort (HostAndPort hostPort ) {
118+ this .host = hostPort .getHost ();
119+ this .port = hostPort .getPort ();
120+ }
121+
101122 @ Override
102123 public String getDescription () {
103- return this . hostPort . toString () ;
124+ return host + ":" + port ;
104125 }
105126
106127 @ Override
107128 public String getHost () {
108- return this .hostPort . getHost () ;
129+ return this .host ;
109130 }
110131
111- /**
112- * @param host
113- * @deprecated This method will be removed in future.
114- */
115132 @ Override
116- @ Deprecated
117133 public void setHost (String host ) {
118- this .hostPort = new HostAndPort ( host , this . hostPort . getPort ()) ;
134+ this .host = host ;
119135 }
120136
121137 @ Override
122138 public int getPort () {
123- return this .hostPort . getPort () ;
139+ return this .port ;
124140 }
125141
126- /**
127- * @param port
128- * @deprecated This method will be removed in future.
129- */
130142 @ Override
131- @ Deprecated
132143 public void setPort (int port ) {
133- this .hostPort = new HostAndPort ( this . hostPort . getHost (), port ) ;
144+ this .port = port ;
134145 }
135146
136147 @ Override
137148 public int getConnectionTimeout () {
138- return config . getConnectionTimeout () ;
149+ return this . connectionTimeout ;
139150 }
140151
141152 @ Override
142153 public void setConnectionTimeout (int connectionTimeout ) {
143- // throw exception?
154+ this . connectionTimeout = connectionTimeout ;
144155 }
145156
146157 @ Override
147158 public int getSoTimeout () {
148- return config . getSoTimeout () ;
159+ return this . soTimeout ;
149160 }
150161
151162 @ Override
152163 public void setSoTimeout (int soTimeout ) {
153- // throw exception?
164+ this .soTimeout = soTimeout ;
165+ }
166+
167+ public boolean isSsl () {
168+ return ssl ;
169+ }
170+
171+ public void setSsl (boolean ssl ) {
172+ this .ssl = ssl ;
173+ }
174+
175+ public SSLSocketFactory getSslSocketFactory () {
176+ return sslSocketFactory ;
177+ }
178+
179+ public void setSslSocketFactory (SSLSocketFactory sslSocketFactory ) {
180+ this .sslSocketFactory = sslSocketFactory ;
181+ }
182+
183+ public SSLParameters getSslParameters () {
184+ return sslParameters ;
185+ }
186+
187+ public void setSslParameters (SSLParameters sslParameters ) {
188+ this .sslParameters = sslParameters ;
189+ }
190+
191+ public HostnameVerifier getHostnameVerifier () {
192+ return hostnameVerifier ;
193+ }
194+
195+ public void setHostnameVerifier (HostnameVerifier hostnameVerifier ) {
196+ this .hostnameVerifier = hostnameVerifier ;
197+ }
198+
199+ public HostAndPortMapper getHostAndPortMapper () {
200+ return hostAndPortMapper ;
201+ }
202+
203+ public void setHostAndPortMapper (HostAndPortMapper hostAndPortMapper ) {
204+ this .hostAndPortMapper = hostAndPortMapper ;
154205 }
155206}
0 commit comments