@@ -87,7 +87,8 @@ public abstract class SwitcherContextBase extends SwitcherConfig {
8787 protected static Set <String > switcherKeys ;
8888 protected static Map <String , SwitcherRequest > switchers ;
8989 protected static SwitcherExecutor switcherExecutor ;
90- private static ScheduledExecutorService scheduledExecutorService ;
90+ private static ScheduledExecutorService scheduledSnapshotExecutorService ;
91+ private static ScheduledExecutorService scheduledTokenExecutorService ;
9192 private static ExecutorService watcherExecutorService ;
9293 private static SnapshotWatcher watcherSnapshot ;
9394 protected static SwitcherContextBase contextBase ;
@@ -112,6 +113,7 @@ protected void configureClient() {
112113 .silentMode (silent )
113114 .regexTimeout (regexTimeout )
114115 .timeoutMs (timeout )
116+ .autoRefreshToken (autoRefreshToken )
115117 .poolConnectionSize (poolSize )
116118 .snapshotLocation (snapshot .getLocation ())
117119 .snapshotAutoLoad (snapshot .isAuto ())
@@ -198,9 +200,12 @@ public static void initializeClient() {
198200 * @return SwitcherExecutor instance
199201 */
200202 private static SwitcherExecutor buildInstance () {
203+ initTokenExecutorService ();
204+
201205 final ClientWS clientWS = initRemotePoolExecutorService ();
202206 final SwitcherValidator validatorService = new ValidatorService ();
203- final ClientRemote clientRemote = new ClientRemoteService (clientWS , switcherProperties );
207+ final ClientRemote clientRemote = new ClientRemoteService (
208+ clientWS , switcherProperties , scheduledTokenExecutorService );
204209 final ClientLocal clientLocal = new ClientLocalService (validatorService );
205210
206211 if (contextBol (ContextKey .LOCAL_MODE )) {
@@ -307,7 +312,7 @@ public static ScheduledFuture<?> scheduleSnapshotAutoUpdate(String intervalValue
307312 return null ;
308313 }
309314
310- if (Objects .nonNull (scheduledExecutorService )) {
315+ if (Objects .nonNull (scheduledSnapshotExecutorService )) {
311316 terminateSnapshotAutoUpdateWorker ();
312317 }
313318
@@ -325,7 +330,7 @@ public static ScheduledFuture<?> scheduleSnapshotAutoUpdate(String intervalValue
325330 };
326331
327332 initSnapshotExecutorService ();
328- return scheduledExecutorService .scheduleAtFixedRate (runnableSnapshotValidate , 0 , interval , TimeUnit .MILLISECONDS );
333+ return scheduledSnapshotExecutorService .scheduleAtFixedRate (runnableSnapshotValidate , 0 , interval , TimeUnit .MILLISECONDS );
329334 }
330335
331336 /**
@@ -340,17 +345,29 @@ public static ScheduledFuture<?> scheduleSnapshotAutoUpdate(String intervalValue
340345 }
341346
342347 /**
343- * Configure Executor Service for Snapshot Update Worker
348+ * Configure Scheduled Executor Service for Snapshot Update Worker
344349 */
345350 private static void initSnapshotExecutorService () {
346- scheduledExecutorService = Executors .newSingleThreadScheduledExecutor (r -> {
351+ scheduledSnapshotExecutorService = Executors .newSingleThreadScheduledExecutor (r -> {
347352 Thread thread = new Thread (r );
348353 thread .setName (WorkerName .SNAPSHOT_UPDATE_WORKER .toString ());
349354 thread .setDaemon (true );
350355 return thread ;
351356 });
352357 }
353358
359+ /**
360+ * Configure Scheduled Executor Service for Token Refresh Worker
361+ */
362+ private static void initTokenExecutorService () {
363+ scheduledTokenExecutorService = Executors .newSingleThreadScheduledExecutor (r -> {
364+ Thread thread = new Thread (r );
365+ thread .setName (WorkerName .SWITCHER_TOKEN_WORKER .toString ());
366+ thread .setDaemon (true );
367+ return thread ;
368+ });
369+ }
370+
354371 /**
355372 * Configure Executor Service for Snapshot Watch Worker
356373 */
@@ -539,9 +556,19 @@ public static void configure(ContextBuilder builder) {
539556 * Cancel existing scheduled task for updating local Snapshot
540557 */
541558 public static void terminateSnapshotAutoUpdateWorker () {
542- if (Objects .nonNull (scheduledExecutorService )) {
543- scheduledExecutorService .shutdownNow ();
544- scheduledExecutorService = null ;
559+ if (Objects .nonNull (scheduledSnapshotExecutorService )) {
560+ scheduledSnapshotExecutorService .shutdownNow ();
561+ scheduledSnapshotExecutorService = null ;
562+ }
563+ }
564+
565+ /**
566+ * Cancel existing scheduled task for token refresh
567+ */
568+ public static void terminateTokenRefreshWorker () {
569+ if (Objects .nonNull (scheduledTokenExecutorService )) {
570+ scheduledTokenExecutorService .shutdownNow ();
571+ scheduledTokenExecutorService = null ;
545572 }
546573 }
547574
0 commit comments