Search in sources :

Example 1 with ProviderNotFoundException

use of com.serotonin.provider.ProviderNotFoundException in project ma-core-public by infiniteautomation.

the class BackgroundProcessingImpl method initialize.

/* (non-Javadoc)
     * @see com.serotonin.m2m2.rt.maint.BackroundProcessing#initialize(boolean)
     */
@Override
public void initialize(boolean safe) {
    if (state != PRE_INITIALIZE)
        return;
    // Set the started indicator to true.
    state = INITIALIZE;
    try {
        this.timer = Providers.get(TimerProvider.class).getTimer();
        this.highPriorityService = (OrderedThreadPoolExecutor) timer.getExecutorService();
        this.highPriorityRejectionHandler = new TaskRejectionHandler();
        this.mediumPriorityRejectionHandler = new TaskRejectionHandler();
    } catch (ProviderNotFoundException e) {
        throw new ShouldNeverHappenException(e);
    }
    this.highPriorityService.setRejectedExecutionHandler(this.highPriorityRejectionHandler);
    // Adjust the high priority pool sizes now
    int corePoolSize = SystemSettingsDao.getIntValue(SystemSettingsDao.HIGH_PRI_CORE_POOL_SIZE);
    int maxPoolSize = SystemSettingsDao.getIntValue(SystemSettingsDao.HIGH_PRI_MAX_POOL_SIZE);
    this.highPriorityService.setCorePoolSize(corePoolSize);
    this.highPriorityService.setMaximumPoolSize(maxPoolSize);
    // TODO Quick Fix for Setting default size somewhere other than in Lifecycle or Main
    Common.defaultTaskQueueSize = Common.envProps.getInt("runtime.realTimeTimer.defaultTaskQueueSize", 1);
    // Pull our settings from the System Settings
    corePoolSize = SystemSettingsDao.getIntValue(SystemSettingsDao.MED_PRI_CORE_POOL_SIZE);
    // Sanity check to ensure the pool sizes are appropriate
    if (corePoolSize < MED_PRI_MAX_POOL_SIZE_MIN)
        corePoolSize = MED_PRI_MAX_POOL_SIZE_MIN;
    mediumPriorityService = new OrderedThreadPoolExecutor(corePoolSize, corePoolSize, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new MangoThreadFactory("medium", Thread.MAX_PRIORITY - 2), mediumPriorityRejectionHandler, Common.envProps.getBoolean("runtime.realTimeTimer.flushTaskQueueOnReject", false), Common.timer.getTimeSource());
    corePoolSize = SystemSettingsDao.getIntValue(SystemSettingsDao.LOW_PRI_CORE_POOL_SIZE);
    // Sanity check to ensure the pool sizes are appropriate
    if (corePoolSize < LOW_PRI_MAX_POOL_SIZE_MIN)
        corePoolSize = LOW_PRI_MAX_POOL_SIZE_MIN;
    lowPriorityService = new ThreadPoolExecutor(corePoolSize, corePoolSize, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new MangoThreadFactory("low", Thread.NORM_PRIORITY));
    this.state = RUNNING;
}
Also used : TaskRejectionHandler(com.serotonin.m2m2.util.timeout.TaskRejectionHandler) ProviderNotFoundException(com.serotonin.provider.ProviderNotFoundException) OrderedThreadPoolExecutor(com.serotonin.timer.OrderedThreadPoolExecutor) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) OrderedThreadPoolExecutor(com.serotonin.timer.OrderedThreadPoolExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Aggregations

ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)1 TaskRejectionHandler (com.serotonin.m2m2.util.timeout.TaskRejectionHandler)1 ProviderNotFoundException (com.serotonin.provider.ProviderNotFoundException)1 OrderedThreadPoolExecutor (com.serotonin.timer.OrderedThreadPoolExecutor)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1