@Override
  public synchronized void start(final StartContext context) throws StartException {
    File dir = new File(dataDir).getAbsoluteFile();

    try {
      zooKeeperServer = new ZooKeeperServer(dir, dir, (int) tickTime);

      ServerCnxnFactory serverCnxnFactory =
          ServerCnxnFactory.createFactory(binding.getValue().getSocketAddress(), 5);
      zooKeeperServer.setServerCnxnFactory(serverCnxnFactory);

      context.asynchronous();
      executor.getValue().execute(new ZooKeeperServerRunner(zooKeeperServer, context));
    } catch (IOException e) {
      context.failed(new StartException(e));
    }
  }
Esempio n. 2
0
  @Override
  public synchronized void start(final StartContext context) throws StartException {
    final Runnable task =
        new Runnable() {
          @Override
          public void run() {
            try {
              bridge.setTransactionManager(getTransactionManager(context));
              startBridge();

              context.complete();
            } catch (Throwable e) {
              context.failed(MessagingLogger.ROOT_LOGGER.failedToCreate(e, "JMS Bridge"));
            }
          }
        };
    try {
      executorInjector.getValue().execute(task);
    } catch (RejectedExecutionException e) {
      task.run();
    } finally {
      context.asynchronous();
    }
  }
  @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);
  }