/** * The returned object will be injected (if injector is available) and will be cached, meaning that only the first * invocation of this method will instantiate a fresh strategy and any subsequent invocation will return the same * object. * * @return the strategy S whose alias is found configured in the properties. This method will never return null. If no * alias is defined the default strategy will be returned. If an invalid alias is provided - a runtime * exception will be thrown. */ public final S getConfiguredStrategy() { return lazyInitializer.get(); }
/** * The returned object will be injected (if injector is available) and will be cached, meaning that only the first * invocation of this method will instantiate a fresh strategy and any subsequent invocation will return the same * object. * * @return the strategy S whose alias is found configured in the properties. This method will never return null. If no * alias is defined the default strategy will be returned. If an invalid alias is provided - a runtime * exception will be thrown. */ public final S getConfiguredStrategy() { return lazyInitializer.get(); }
/** * This method is used to ensure that lazy initialized object is injected as well. */ private RequestHandler getRequestHandler() { return getDecoratedObject().get(); }
/** * This method is used to ensure that lazy initialized object is injected as well. */ private RequestHandler getRequestHandler() { return getDecoratedObject().get(); }
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); } } }
/** * The following method shuts down an ExecutorService in two phases, first by calling shutdown to reject incoming * tasks, and then calling shutdownNow, if necessary, to cancel any lingering tasks: * * @param destroyNow * - if true, any running operation will be stopped immediately, otherwise scheduler will await termination. */ private synchronized void destroyScheduler() { if (!poolInitializer.get().isShutdown()) { // Disable new tasks from being submitted poolInitializer.get().shutdown(); if (future != null) { future.cancel(true); } try { while (!poolInitializer.get().awaitTermination(5, TimeUnit.SECONDS)) { LOG.debug("Termination awaited: {}", name); poolInitializer.get().shutdownNow(); } } catch (final InterruptedException e) { LOG.debug("Interrupted Exception occured during scheduler destroy", e); // (Re-)Cancel if current thread also interrupted poolInitializer.get().shutdownNow(); // Preserve interrupt status Thread.currentThread().interrupt(); } finally { LOG.debug("[STOP] Scheduler terminated successfully! {}", name); } } }
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); } } }
/** * The following method shuts down an ExecutorService in two phases, first by calling shutdown to reject incoming * tasks, and then calling shutdownNow, if necessary, to cancel any lingering tasks: * * @param destroyNow * - if true, any running operation will be stopped immediately, otherwise scheduler will await termination. */ private synchronized void destroyScheduler() { if (!poolInitializer.get().isShutdown()) { // Disable new tasks from being submitted poolInitializer.get().shutdown(); if (future != null) { future.cancel(true); } try { while (!poolInitializer.get().awaitTermination(5, TimeUnit.SECONDS)) { LOG.debug("Termination awaited: {}", name); poolInitializer.get().shutdownNow(); } } catch (final InterruptedException e) { LOG.debug("Interrupted Exception occured during scheduler destroy", e); // (Re-)Cancel if current thread also interrupted poolInitializer.get().shutdownNow(); // Preserve interrupt status Thread.currentThread().interrupt(); } finally { LOG.debug("[STOP] Scheduler terminated successfully! {}", name); } } }
/** * {@inheritDoc} */ public WroModel create() { return getDecoratedObject().get().create(); }
/** * {@inheritDoc} */ public void destroy() { getDecoratedObject().get().destroy(); } }
/** * {@inheritDoc} */ public void destroy() { getDecoratedObject().get().destroy(); } }
/** * {@inheritDoc} */ public WroModel create() { return getDecoratedObject().get().create(); }
/** * 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; }
/** * 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; }
/** * Transforms a sass content into css using Sass ruby engine. This method is synchronized because the engine itself is * not thread-safe. * * @param content * the Sass content to process. */ public String process(final String content) { if (isEmpty(content)) { return StringUtils.EMPTY; } try { synchronized(this) { return engineInitializer.get().eval(buildUpdateScript(content)).toString(); } } catch (final ScriptException e) { throw new WroRuntimeException(e.getMessage(), e); } }
private ProcessorDecorator getProcessorDecorator() { if (processor == null) { processor = new ProcessorDecorator(getDecoratedObject().get()); injector.inject(processor); } return processor; }
private ProcessorDecorator getProcessorDecorator() { if (processor == null) { processor = new ProcessorDecorator(getDecoratedObject().get()); injector.inject(processor); } return processor; }