All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.squirrelframework.foundation.component.SquirrelConfiguration Maven / Gradle / Ivy

Go to download

foundation module of squirrel framework which provided event driven infrastructure and a finite state machine implementation.

There is a newer version: 0.3.10
Show newest version
package org.squirrelframework.foundation.component;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import com.google.common.util.concurrent.MoreExecutors;

public class SquirrelConfiguration {
    
    public static ExecutorService getExecutor() {
        ExecutorService executorService = SquirrelSingletonProvider.getInstance().get(ExecutorService.class);
        if(executorService==null) {
            // create default executor
            executorService = Executors.newFixedThreadPool(1);
            MoreExecutors.addDelayedShutdownHook(executorService, 120, TimeUnit.SECONDS);
            SquirrelSingletonProvider.getInstance().register(ExecutorService.class, executorService);
        }
        return executorService;
    }
    
    public static ScheduledExecutorService getScheduler() {
        ScheduledExecutorService scheduler = SquirrelSingletonProvider.getInstance().get(ScheduledExecutorService.class);
        if(scheduler==null) {
            // create default scheduler
            scheduler = Executors.newScheduledThreadPool(1);
            MoreExecutors.addDelayedShutdownHook(scheduler, 120, TimeUnit.SECONDS);
            SquirrelSingletonProvider.getInstance().register(ScheduledExecutorService.class, scheduler);
        }
        return scheduler;
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy