/** * @see SchedulerHelper#create(ObjectFactory, String) */ public static SchedulerHelper create(final LazyInitializer<Runnable> runnableFactory) { return new SchedulerHelper(runnableFactory); }
/** * @VisibleForTesting */ SchedulerHelper newResourceWatcherScheduler() { return SchedulerHelper.create(new LazyInitializer<Runnable>() { @Override protected Runnable initialize() { return new Runnable() { public void run() { checkedKeys.clear(); } }; } }, "resourceWatcherScheduler"); }
/** * Stops all jobs runned by the scheduler. It is important to call this method before application stops. */ public void destroy() { destroyScheduler(); }
/** * Schedules with provided period using {@link TimeUnit#SECONDS} as a default time unit. * * @param period * new period for scheduling. */ public SchedulerHelper scheduleWithPeriod(final long period) { scheduleWithPeriod(period, TimeUnit.SECONDS); return this; }
@Override public void destroy() { super.destroy(); resourceWatcherScheduler.destroy(); }
private synchronized void startScheduler(final long period, final TimeUnit timeUnit) { // let the running task to finish its job. cancelRunningTask(); if (period > 0) { // scheduleWithFixedDelay is used instead of scheduleAtFixedRate because the later can cause a problem // (thread tries to make up for lost time in some situations) final Runnable runnable = lazyRunnable.get(); notNull(runnable); // avoid reject when this method is accessed concurrently. if (!poolInitializer.get().isShutdown()) { LOG.debug("[START] Scheduling thread with period of {} {}. ThreadId: {}", period, timeUnit, Thread.currentThread().getId()); // do not execute immediately. Use period also for initial delay. final long initialDelay = period; future = poolInitializer.get().scheduleWithFixedDelay(runnable, initialDelay, period, timeUnit); } } }
/** * Run the scheduler with the provided period of time. If the scheduler is already started, it will be stopped (not * before the running job is complete). * * @param period * new period for scheduling. * @param timeUnit * what kind of time unit is associated with the period. */ public SchedulerHelper scheduleWithPeriod(final long period, final TimeUnit timeUnit) { notNull(timeUnit); LOG.debug("period: {} [{}]", period, timeUnit); if (this.period != period) { this.period = period; if (!poolInitializer.get().isShutdown()) { startScheduler(period, timeUnit); } else { LOG.warn("Cannot schedule because destroy was already called!"); } } return this; }
/** * Schedules with provided period using {@link TimeUnit#SECONDS} as a default time unit. * * @param period * new period for scheduling. */ public SchedulerHelper scheduleWithPeriod(final long period) { scheduleWithPeriod(period, TimeUnit.SECONDS); return this; }
@Override public void destroy() { super.destroy(); resourceWatcherScheduler.destroy(); }
private synchronized void startScheduler(final long period, final TimeUnit timeUnit) { // let the running task to finish its job. cancelRunningTask(); if (period > 0) { // scheduleWithFixedDelay is used instead of scheduleAtFixedRate because the later can cause a problem // (thread tries to make up for lost time in some situations) final Runnable runnable = lazyRunnable.get(); notNull(runnable); // avoid reject when this method is accessed concurrently. if (!poolInitializer.get().isShutdown()) { LOG.debug("[START] Scheduling thread with period of {} {}. ThreadId: {}", period, timeUnit, Thread.currentThread().getId()); // do not execute immediately. Use period also for initial delay. final long initialDelay = period; future = poolInitializer.get().scheduleWithFixedDelay(runnable, initialDelay, period, timeUnit); } } }
/** * Run the scheduler with the provided period of time. If the scheduler is already started, it will be stopped (not * before the running job is complete). * * @param period * new period for scheduling. * @param timeUnit * what kind of time unit is associated with the period. */ public SchedulerHelper scheduleWithPeriod(final long period, final TimeUnit timeUnit) { notNull(timeUnit); LOG.debug("period: {} [{}]", period, timeUnit); if (this.period != period) { this.period = period; if (!poolInitializer.get().isShutdown()) { startScheduler(period, timeUnit); } else { LOG.warn("Cannot schedule because destroy was already called!"); } } return this; }
/** * Factory method. Creates a {@link SchedulerHelper} which consumes a factory providing a runnable. This approach * allows lazy runnable initialization. * * @param runnableFactory * a factory creating the runnable to schedule. * @param name * the name associated with this {@link SchedulerHelper} (useful to detect if this class is causing a memory * leak. */ public static SchedulerHelper create(final LazyInitializer<Runnable> runnableFactory, final String name) { return new SchedulerHelper(runnableFactory, name); }
public final void onCachePeriodChanged(final long period) { LOG.info("onCachePeriodChanged with value {} has been triggered!", period); cacheSchedulerHelper.scheduleWithPeriod(period); // flush the cache by destroying it. cacheStrategy.clear(); }
/** * Called when {@link WroManager} is being taken out of service. */ public final void destroy() { try { cacheSchedulerHelper.destroy(); modelSchedulerHelper.destroy(); cacheStrategy.destroy(); modelFactory.destroy(); resourceWatcher.destroy(); destroyProcessors(); } catch (final Exception e) { LOG.error("Exception occured during manager destroy!", e); } finally { LOG.debug("WroManager destroyed"); } }
/** * Stops all jobs runned by the scheduler. It is important to call this method before application stops. */ public void destroy() { destroyScheduler(); }
/** * @VisibleForTesting */ SchedulerHelper newResourceWatcherScheduler() { return SchedulerHelper.create(new LazyInitializer<Runnable>() { @Override protected Runnable initialize() { return new Runnable() { public void run() { checkedKeys.clear(); } }; } }, "resourceWatcherScheduler"); }
/** * @see SchedulerHelper#create(ObjectFactory, String) */ public static SchedulerHelper create(final LazyInitializer<Runnable> runnableFactory) { return new SchedulerHelper(runnableFactory); }
public final void onCachePeriodChanged(final long period) { LOG.info("onCachePeriodChanged with value {} has been triggered!", period); cacheSchedulerHelper.scheduleWithPeriod(period); // flush the cache by destroying it. cacheStrategy.clear(); }
/** * Called when {@link WroManager} is being taken out of service. */ public final void destroy() { try { cacheSchedulerHelper.destroy(); modelSchedulerHelper.destroy(); cacheStrategy.destroy(); modelFactory.destroy(); resourceWatcher.destroy(); destroyProcessors(); } catch (final Exception e) { LOG.error("Exception occured during manager destroy!", e); } finally { LOG.debug("WroManager destroyed"); } }
/** * Factory method. Creates a {@link SchedulerHelper} which consumes a factory providing a runnable. This approach * allows lazy runnable initialization. * * @param runnableFactory * a factory creating the runnable to schedule. * @param name * the name associated with this {@link SchedulerHelper} (useful to detect if this class is causing a memory * leak. */ public static SchedulerHelper create(final LazyInitializer<Runnable> runnableFactory, final String name) { return new SchedulerHelper(runnableFactory, name); }