IncrementalBuilderExecutorManagerFactoryImpl implements IncrementalBuilderExecutorManagerFactory { @Override public synchronized IncrementalBuilderExecutorManager getExecutorManager() { if (executorManager == null) { IncrementalBuilderExecutorManager _executorManager = null; 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  IncrementalBuilderExecutorManagerFactoryImpl(ModuleService<? extends Module> moduleService,
                                                        BuildService buildService,
                                                        Event<BuildResults> buildResultsEvent,
                                                        Event<IncrementalBuildResults> incrementalBuildResultsEvent,
                                                        @Managed ExecutorService executorService); @Override synchronized IncrementalBuilderExecutorManager getExecutorManager();  }
@Test public void testUseJDNILookup() throws NamingException { System.setProperty(Context.INITIAL_CONTEXT_FACTORY, MockInitialContextFactory.class.getName()); final Context context = mock(Context.class); final IncrementalBuilderExecutorManager service = mock(IncrementalBuilderExecutorManager.class); when(context.lookup("java:module/IncrementalBuilderExecutorManager")).thenReturn(service); MockInitialContextFactory.setCurrentContext(context); final IncrementalBuilderExecutorManagerFactoryImpl factory = new IncrementalBuilderExecutorManagerFactoryImpl(null, null, null, null, new ExecutorServiceProducer().produceUnmanagedExecutorService()); final IncrementalBuilderExecutorManager executor1 = factory.getExecutorManager(); assertNotNull(executor1); assertTrue(executor1 instanceof IncrementalBuilderExecutorManager); assertSame(service, executor1); final IncrementalBuilderExecutorManager executor2 = factory.getExecutorManager(); assertNotNull(executor2); assertTrue(executor2 instanceof IncrementalBuilderExecutorManager); assertSame(service, executor2); assertSame(executor1, executor2); }
@Test public void testUseExecutorThreadPool() { System.setProperty("org.uberfire.async.executor.safemode", "true"); final IncrementalBuilderExecutorManagerFactoryImpl factory = new IncrementalBuilderExecutorManagerFactoryImpl(null, null, null, null, new ExecutorServiceProducer().produceUnmanagedExecutorService()); final IncrementalBuilderExecutorManager executor1 = factory.getExecutorManager(); assertNotNull(executor1); assertTrue(executor1 instanceof IncrementalBuilderExecutorManager); final IncrementalBuilderExecutorManager executor2 = factory.getExecutorManager(); assertNotNull(executor2); assertTrue(executor2 instanceof IncrementalBuilderExecutorManager); assertSame(executor1, executor2); }