class IncrementalBuilderExecutorManagerFactoryImpl implements IncrementalBuilderExecutorManagerFactory {

    @Override
    public synchronized IncrementalBuilderExecutorManager getExecutorManager() {
        if (executorManager == null) {
            IncrementalBuilderExecutorManager _executorManager = null;

            //Unless overridden, delegate instantiation of the ExecutorService to the container
            //See https://issues.jboss.org/browse/UF-244 and https://issues.jboss.org/browse/WFLY-4198
            //When running in Hosted Mode (on Wildfly 8.1 at present) the System Property should be set
            //to "true"
            if (!USE_EXECUTOR_SAFE_MODE) {
                try {
                    _executorManager = InitialContext.doLookup("java:module/IncrementalBuilderExecutorManager");
                } catch (final Exception e) {
                    LOG.warn("Unable to instantiate EJB Asynchronous Bean. Falling back to Executors' CachedThreadPool.",
                             e);
                }
            } else {
                LOG.info("Use of to Executors' CachedThreadPool has been requested; overriding container provisioning.");
            }

            if (_executorManager == null) {
                executorManager = new IncrementalBuilderExecutorManager();
                executorManager.setServices(moduleService,
                                            buildService,
                                            buildResultsEvent,
                                            incrementalBuildResultsEvent);
                executorManager.setExecutorService(this.executorService);
            } else {
                executorManager = _executorManager;
            }
        }

        return executorManager;
    }

    @Inject public  IncrementalBuilderExecutorManagerFactoryImpl(ModuleService<? extends Module> moduleService,
                                                        BuildService buildService,
                                                        Event<BuildResults> buildResultsEvent,
                                                        Event<IncrementalBuildResults> incrementalBuildResultsEvent,
                                                        @Managed ExecutorService executorService);

}