@@ -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 ;
@@ -111,6 +112,7 @@ protected void configureClient() {
111112 .restrictRelay (relay .isRestrict ())
112113 .silentMode (silent )
113114 .timeoutMs (timeout )
115+ .autoRefreshToken (autoRefreshToken )
114116 .poolConnectionSize (poolSize )
115117 .snapshotLocation (snapshot .getLocation ())
116118 .snapshotAutoLoad (snapshot .isAuto ())
@@ -197,9 +199,12 @@ public static void initializeClient() {
197199 * @return SwitcherExecutor instance
198200 */
199201 private static SwitcherExecutor buildInstance () {
202+ initTokenExecutorService ();
203+
200204 final ClientWS clientWS = initRemotePoolExecutorService ();
201205 final SwitcherValidator validatorService = new ValidatorService ();
202- final ClientRemote clientRemote = new ClientRemoteService (clientWS , switcherProperties );
206+ final ClientRemote clientRemote = new ClientRemoteService (
207+ clientWS , switcherProperties , scheduledTokenExecutorService );
203208 final ClientLocal clientLocal = new ClientLocalService (validatorService );
204209
205210 if (contextBol (ContextKey .LOCAL_MODE )) {
@@ -306,7 +311,7 @@ public static ScheduledFuture<?> scheduleSnapshotAutoUpdate(String intervalValue
306311 return null ;
307312 }
308313
309- if (Objects .nonNull (scheduledExecutorService )) {
314+ if (Objects .nonNull (scheduledSnapshotExecutorService )) {
310315 terminateSnapshotAutoUpdateWorker ();
311316 }
312317
@@ -324,7 +329,7 @@ public static ScheduledFuture<?> scheduleSnapshotAutoUpdate(String intervalValue
324329 };
325330
326331 initSnapshotExecutorService ();
327- return scheduledExecutorService .scheduleAtFixedRate (runnableSnapshotValidate , 0 , interval , TimeUnit .MILLISECONDS );
332+ return scheduledSnapshotExecutorService .scheduleAtFixedRate (runnableSnapshotValidate , 0 , interval , TimeUnit .MILLISECONDS );
328333 }
329334
330335 /**
@@ -339,17 +344,29 @@ public static ScheduledFuture<?> scheduleSnapshotAutoUpdate(String intervalValue
339344 }
340345
341346 /**
342- * Configure Executor Service for Snapshot Update Worker
347+ * Configure Scheduled Executor Service for Snapshot Update Worker
343348 */
344349 private static void initSnapshotExecutorService () {
345- scheduledExecutorService = Executors .newSingleThreadScheduledExecutor (r -> {
350+ scheduledSnapshotExecutorService = Executors .newSingleThreadScheduledExecutor (r -> {
346351 Thread thread = new Thread (r );
347352 thread .setName (WorkerName .SNAPSHOT_UPDATE_WORKER .toString ());
348353 thread .setDaemon (true );
349354 return thread ;
350355 });
351356 }
352357
358+ /**
359+ * Configure Scheduled Executor Service for Token Refresh Worker
360+ */
361+ private static void initTokenExecutorService () {
362+ scheduledTokenExecutorService = Executors .newSingleThreadScheduledExecutor (r -> {
363+ Thread thread = new Thread (r );
364+ thread .setName (WorkerName .SWITCHER_TOKEN_WORKER .toString ());
365+ thread .setDaemon (true );
366+ return thread ;
367+ });
368+ }
369+
353370 /**
354371 * Configure Executor Service for Snapshot Watch Worker
355372 */
@@ -538,9 +555,19 @@ public static void configure(ContextBuilder builder) {
538555 * Cancel existing scheduled task for updating local Snapshot
539556 */
540557 public static void terminateSnapshotAutoUpdateWorker () {
541- if (Objects .nonNull (scheduledExecutorService )) {
542- scheduledExecutorService .shutdownNow ();
543- scheduledExecutorService = null ;
558+ if (Objects .nonNull (scheduledSnapshotExecutorService )) {
559+ scheduledSnapshotExecutorService .shutdownNow ();
560+ scheduledSnapshotExecutorService = null ;
561+ }
562+ }
563+
564+ /**
565+ * Cancel existing scheduled task for token refresh
566+ */
567+ public static void terminateTokenRefreshWorker () {
568+ if (Objects .nonNull (scheduledTokenExecutorService )) {
569+ scheduledTokenExecutorService .shutdownNow ();
570+ scheduledTokenExecutorService = null ;
544571 }
545572 }
546573
0 commit comments