@Override public void start(StartContext context) throws StartException { final ExecutorService executorService = getExecutorServiceInjector().getValue(); this.hostControllerConfigurationPersister = new HostControllerConfigurationPersister( environment, hostControllerInfo, executorService, extensionRegistry); setConfigurationPersister(hostControllerConfigurationPersister); prepareStepHandler.setExecutorService(executorService); ThreadFactory threadFactory = new JBossThreadFactory( new ThreadGroup("proxy-threads"), Boolean.FALSE, null, "%G - %t", null, null, doPrivileged(GetAccessControlContextAction.getInstance())); proxyExecutor = Executors.newCachedThreadPool(threadFactory); ThreadFactory pingerThreadFactory = new JBossThreadFactory( new ThreadGroup("proxy-pinger-threads"), Boolean.TRUE, null, "%G - %t", null, null, doPrivileged(GetAccessControlContextAction.getInstance())); pingScheduler = Executors.newScheduledThreadPool(PINGER_POOL_SIZE, pingerThreadFactory); super.start(context); }
@Override public void stop(final StopContext context) { final ExecutorService executor = executorInjector.getValue(); final AccessControlContext accessControlContext = AccessController.doPrivileged(GetAccessControlContextAction.getInstance()); final Runnable task = new Runnable() { // run async in a background thread @Override public void run() { PrivilegedAction<Void> privilegedAction = new PrivilegedAction<Void>() { // run as security privileged action @Override public Void run() { if (phaseOnePersistenceUnitServiceInjectedValue.getOptionalValue() != null) { JPA_LOGGER.stoppingPersistenceUnitService( 2, pu.getScopedPersistenceUnitName()); } else { JPA_LOGGER.stoppingService( "Persistence Unit", pu.getScopedPersistenceUnitName()); } if (entityManagerFactory != null) { WritableServiceBasedNamingStore.pushOwner(deploymentUnitServiceName); try { entityManagerFactory.close(); } catch (Throwable t) { JPA_LOGGER.failedToStopPUService(t, pu.getScopedPersistenceUnitName()); } finally { entityManagerFactory = null; pu.setTempClassLoaderFactory(null); WritableServiceBasedNamingStore.popOwner(); persistenceUnitRegistry.remove(getScopedPersistenceUnitName()); } } if (proxyBeanManager != null) { proxyBeanManager.setDelegate(null); proxyBeanManager = null; } context.complete(); return null; } }; WildFlySecurityManager.doChecked(privilegedAction, accessControlContext); } }; context.asynchronous(); executor.execute(task); }
static { final BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<Runnable>(); final ThreadFactory threadFactory = new JBossThreadFactory( new ThreadGroup("cli-remoting"), Boolean.FALSE, null, "%G - %t", null, null, doPrivileged(GetAccessControlContextAction.getInstance())); executorService = new ThreadPoolExecutor(2, 4, 60L, TimeUnit.SECONDS, workQueue, threadFactory); // Allow the core threads to time out as well executorService.allowCoreThreadTimeOut(true); try { endpoint = Remoting.createEndpoint("cli-client", OptionMap.EMPTY); endpoint.addConnectionProvider( "remote", new RemoteConnectionProviderFactory(), OptionMap.EMPTY); endpoint.addConnectionProvider( "http-remoting", new HttpUpgradeConnectionProviderFactory(), OptionMap.create(Options.SSL_ENABLED, Boolean.FALSE)); endpoint.addConnectionProvider( "https-remoting", new HttpUpgradeConnectionProviderFactory(), OptionMap.create(Options.SSL_ENABLED, Boolean.TRUE)); } catch (IOException e) { throw new IllegalStateException("Failed to create remoting endpoint", e); } CliShutdownHook.add( new CliShutdownHook.Handler() { @Override public void shutdown() { executorService.shutdown(); try { executorService.awaitTermination(1, TimeUnit.SECONDS); } catch (InterruptedException e) { } try { endpoint.close(); } catch (IOException e) { } } }); }
@Override public void start(StartContext context) throws StartException { try { final JBossThreadFactory threadFactory = new JBossThreadFactory( new ThreadGroup("ServerDeploymentRepository-temp-threads"), Boolean.FALSE, null, "%G - %t", null, null, doPrivileged(GetAccessControlContextAction.getInstance())); tempFileProvider = TempFileProvider.create("temp", Executors.newScheduledThreadPool(2, threadFactory)); } catch (IOException e) { throw ServerMessages.MESSAGES.failedCreatingTempProvider(); } ServerLogger.ROOT_LOGGER.debugf( "%s started", DeploymentMountProvider.class.getSimpleName()); }
@Override public void start(final StartContext context) throws StartException { final ExecutorService executor = executorInjector.getValue(); final AccessControlContext accessControlContext = AccessController.doPrivileged(GetAccessControlContextAction.getInstance()); final Runnable task = new Runnable() { // run async in a background thread @Override public void run() { PrivilegedAction<Void> privilegedAction = new PrivilegedAction<Void>() { // run as security privileged action @Override public Void run() { try { PhaseOnePersistenceUnitServiceImpl phaseOnePersistenceUnitService = phaseOnePersistenceUnitServiceInjectedValue.getOptionalValue(); WritableServiceBasedNamingStore.pushOwner(deploymentUnitServiceName); // handle phase 2 of 2 of bootstrapping the persistence unit if (phaseOnePersistenceUnitService != null) { JPA_LOGGER.startingPersistenceUnitService( 2, pu.getScopedPersistenceUnitName()); // indicate that the second phase of bootstrapping the persistence unit has // started phaseOnePersistenceUnitService.setSecondPhaseStarted(true); if (beanManagerInjector.getOptionalValue() != null) { // update the bean manager proxy to the actual CDI bean manager proxyBeanManager = phaseOnePersistenceUnitService.getBeanManager(); proxyBeanManager.setDelegate(beanManagerInjector.getOptionalValue()); } entityManagerFactory = phaseOnePersistenceUnitService.getEntityManagerFactoryBuilder().build(); } else { JPA_LOGGER.startingService( "Persistence Unit", pu.getScopedPersistenceUnitName()); // start the persistence unit in one pass (1 of 1) pu.setTempClassLoaderFactory(new TempClassLoaderFactoryImpl(classLoader)); pu.setJtaDataSource(jtaDataSource.getOptionalValue()); pu.setNonJtaDataSource(nonJtaDataSource.getOptionalValue()); if (beanManagerInjector.getOptionalValue() != null) { proxyBeanManager = new ProxyBeanManager(); proxyBeanManager.setDelegate(beanManagerInjector.getOptionalValue()); properties.getValue().put(CDI_BEAN_MANAGER, proxyBeanManager); } entityManagerFactory = createContainerEntityManagerFactory(); } persistenceUnitRegistry.add(getScopedPersistenceUnitName(), getValue()); context.complete(); } catch (Throwable t) { context.failed(new StartException(t)); } finally { pu.setTempClassLoaderFactory( null); // release the temp classloader factory (only needed when creating // the EMF) WritableServiceBasedNamingStore.popOwner(); } return null; } }; WildFlySecurityManager.doChecked(privilegedAction, accessControlContext); } }; context.asynchronous(); executor.execute(task); }