@@ -73,26 +73,17 @@ public class ReloadingKeyManagerFactory extends KeyManagerFactory implements Aut
73
73
* @return
74
74
*/
75
75
public static ReloadingKeyManagerFactory create (
76
- Path keystorePath , String keystorePassword , Duration reloadInterval ) {
77
- KeyManagerFactory kmf ;
78
- try {
79
- kmf = KeyManagerFactory .getInstance (KeyManagerFactory .getDefaultAlgorithm ());
80
- } catch (NoSuchAlgorithmException e ) {
81
- throw new RuntimeException (e );
82
- }
76
+ Path keystorePath , String keystorePassword , Duration reloadInterval )
77
+ throws UnrecoverableKeyException , KeyStoreException , NoSuchAlgorithmException ,
78
+ CertificateException , IOException {
79
+ KeyManagerFactory kmf = KeyManagerFactory .getInstance (KeyManagerFactory .getDefaultAlgorithm ());
83
80
84
81
KeyStore ks ;
85
82
try (InputStream ksf = Files .newInputStream (keystorePath )) {
86
83
ks = KeyStore .getInstance (KEYSTORE_TYPE );
87
84
ks .load (ksf , keystorePassword .toCharArray ());
88
- } catch (IOException | CertificateException | KeyStoreException | NoSuchAlgorithmException e ) {
89
- throw new RuntimeException (e );
90
- }
91
- try {
92
- kmf .init (ks , keystorePassword .toCharArray ());
93
- } catch (KeyStoreException | NoSuchAlgorithmException | UnrecoverableKeyException e ) {
94
- throw new RuntimeException (e );
95
85
}
86
+ kmf .init (ks , keystorePassword .toCharArray ());
96
87
97
88
ReloadingKeyManagerFactory reloadingKeyManagerFactory = new ReloadingKeyManagerFactory (kmf );
98
89
reloadingKeyManagerFactory .start (keystorePath , keystorePassword , reloadInterval );
@@ -115,32 +106,37 @@ private ReloadingKeyManagerFactory(Spi spi, Provider provider, String algorithm)
115
106
private void start (Path keystorePath , String keystorePassword , Duration reloadInterval ) {
116
107
this .keystorePath = keystorePath ;
117
108
this .keystorePassword = keystorePassword ;
118
- this .executor =
119
- Executors .newScheduledThreadPool (
120
- 1 ,
121
- runnable -> {
122
- Thread t = Executors .defaultThreadFactory ().newThread (runnable );
123
- t .setDaemon (true );
124
- return t ;
125
- });
126
109
127
110
// Ensure that reload is called once synchronously, to make sure the file exists etc.
128
111
reload ();
129
112
130
- if (!reloadInterval .isZero ())
113
+ if (!reloadInterval .isZero ()) {
114
+ this .executor =
115
+ Executors .newScheduledThreadPool (
116
+ 1 ,
117
+ runnable -> {
118
+ Thread t = Executors .defaultThreadFactory ().newThread (runnable );
119
+ t .setName (String .format ("%s-%%d" , this .getClass ().getSimpleName ()));
120
+ t .setDaemon (true );
121
+ return t ;
122
+ });
131
123
this .executor .scheduleWithFixedDelay (
132
124
this ::reload ,
133
125
reloadInterval .toMillis (),
134
126
reloadInterval .toMillis (),
135
127
TimeUnit .MILLISECONDS );
128
+ }
136
129
}
137
130
138
131
@ VisibleForTesting
139
132
void reload () {
140
133
try {
141
134
reload0 ();
142
135
} catch (Exception e ) {
143
- logger .warn ("Failed to reload" , e );
136
+ String msg =
137
+ "Failed to reload KeyStore. If this continues to happen, your client may use stale identity"
138
+ + "certificates and fail to re-establish connections to Cassandra hosts." ;
139
+ logger .warn (msg , e );
144
140
}
145
141
}
146
142
0 commit comments