@@ -73,26 +73,17 @@ public class ReloadingKeyManagerFactory extends KeyManagerFactory implements Aut
7373 * @return
7474 */
7575 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 ());
8380
8481 KeyStore ks ;
8582 try (InputStream ksf = Files .newInputStream (keystorePath )) {
8683 ks = KeyStore .getInstance (KEYSTORE_TYPE );
8784 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 );
9585 }
86+ kmf .init (ks , keystorePassword .toCharArray ());
9687
9788 ReloadingKeyManagerFactory reloadingKeyManagerFactory = new ReloadingKeyManagerFactory (kmf );
9889 reloadingKeyManagerFactory .start (keystorePath , keystorePassword , reloadInterval );
@@ -115,32 +106,37 @@ private ReloadingKeyManagerFactory(Spi spi, Provider provider, String algorithm)
115106 private void start (Path keystorePath , String keystorePassword , Duration reloadInterval ) {
116107 this .keystorePath = keystorePath ;
117108 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- });
126109
127110 // Ensure that reload is called once synchronously, to make sure the file exists etc.
128111 reload ();
129112
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+ });
131123 this .executor .scheduleWithFixedDelay (
132124 this ::reload ,
133125 reloadInterval .toMillis (),
134126 reloadInterval .toMillis (),
135127 TimeUnit .MILLISECONDS );
128+ }
136129 }
137130
138131 @ VisibleForTesting
139132 void reload () {
140133 try {
141134 reload0 ();
142135 } 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 );
144140 }
145141 }
146142
0 commit comments