public synchronized void start(StartContext startContext) throws StartException {
    try {
      final ServiceContainer container = startContext.getController().getServiceContainer();

      deploymentMD = getDeployer().deploy(container);
      if (deploymentMD.getCfs().length != 1) {
        throw ConnectorLogger.ROOT_LOGGER.cannotStartDs();
      }
      sqlDataSource =
          new WildFlyDataSource(
              (javax.sql.DataSource) deploymentMD.getCfs()[0], jndiName.getAbsoluteJndiName());
      DS_DEPLOYER_LOGGER.debugf("Adding datasource: %s", deploymentMD.getCfJndiNames()[0]);
      CommonDeploymentService cdService = new CommonDeploymentService(deploymentMD);
      final ServiceName cdServiceName = CommonDeploymentService.getServiceName(jndiName);
      startContext
          .getController()
          .getServiceContainer()
          .addService(cdServiceName, cdService)
          // The dependency added must be the JNDI name which for subsystem resources is an alias.
          // This service
          // is also used in deployments where the capability service name is not registered for the
          // service.
          .addDependency(getServiceName(jndiName))
          .setInitialMode(ServiceController.Mode.ACTIVE)
          .install();
    } catch (Throwable t) {
      throw ConnectorLogger.ROOT_LOGGER.deploymentError(t, dsName);
    }
  }
  @Override
  public synchronized void start(StartContext context) throws StartException {
    ServiceController<?> controller = context.getController();
    LOGGER.tracef("Starting: %s in mode %s", controller.getName(), controller.getMode());
    try {
      ServiceContainer serviceContainer = context.getController().getServiceContainer();

      // Setup the OSGi {@link Framework} properties
      SubsystemState subsystemState = injectedSubsystemState.getValue();
      Map<String, Object> props = new HashMap<String, Object>(subsystemState.getProperties());
      setupIntegrationProperties(context, props);

      // Register the URLStreamHandlerFactory
      Module coreFrameworkModule =
          ((ModuleClassLoader) FrameworkBuilder.class.getClassLoader()).getModule();
      Module.registerURLStreamHandlerFactoryModule(coreFrameworkModule);
      Module.registerContentHandlerFactoryModule(coreFrameworkModule);

      ServiceTarget serviceTarget = context.getChildTarget();
      JAXPServiceProvider.addService(serviceTarget);
      ResolverService.addService(serviceTarget);
      RepositoryService.addService(serviceTarget);

      Activation activation = subsystemState.getActivationPolicy();
      Mode initialMode = (activation == Activation.EAGER ? Mode.ACTIVE : Mode.LAZY);

      // Configure the {@link Framework} builder
      FrameworkBuilder builder = FrameworkBuilderFactory.create(props, initialMode);
      builder.setServiceContainer(serviceContainer);
      builder.setServiceTarget(serviceTarget);

      builder.createFrameworkServices(serviceContainer, true);
      builder.registerIntegrationService(FrameworkPhase.CREATE, new BundleLifecycleIntegration());
      builder.registerIntegrationService(
          FrameworkPhase.CREATE, new FrameworkModuleIntegration(props));
      builder.registerIntegrationService(FrameworkPhase.CREATE, new ModuleLoaderIntegration());
      builder.registerIntegrationService(
          FrameworkPhase.CREATE, new SystemServicesIntegration(resource, extensions));
      builder.registerIntegrationService(FrameworkPhase.INIT, new BootstrapBundlesIntegration());
      builder.registerIntegrationService(
          FrameworkPhase.INIT, new PersistentBundlesIntegration(deploymentTracker));

      // Install the services to create the framework
      builder.installServices(FrameworkPhase.CREATE, serviceTarget, verificationHandler);

      if (activation == Activation.EAGER) {
        builder.installServices(FrameworkPhase.INIT, serviceTarget, verificationHandler);
        builder.installServices(FrameworkPhase.ACTIVE, serviceTarget, verificationHandler);
      }

      // Create the framework activator
      FrameworkActivator.create(builder);

    } catch (Throwable th) {
      throw MESSAGES.startFailedToCreateFrameworkServices(th);
    }
  }
 @Override
 public void start(StartContext context) throws StartException {
   if (serviceContainer != null) {
     throw new IllegalStateException("External Module Service already started");
   }
   serviceContainer = context.getController().getServiceContainer();
 }
Example #4
0
 public static TransactionManager getTransactionManager(StartContext context) {
   @SuppressWarnings("unchecked")
   ServiceController<TransactionManager> service =
       (ServiceController<TransactionManager>)
           context
               .getController()
               .getServiceContainer()
               .getService(TxnServices.JBOSS_TXN_TRANSACTION_MANAGER);
   return service == null ? null : service.getValue();
 }
Example #5
0
 @Override
 public void start(StartContext context) {
   this.container = context.getController().getServiceContainer();
   this.dispatcher =
       this.dispatcherFactory
           .getValue()
           .<SingletonContext<T>>createCommandDispatcher(this.singletonServiceName, this);
   this.registration =
       this.registrationFactory.getValue().createRegistration(this.singletonServiceName, this);
   this.started = true;
 }
  public synchronized void start(StartContext startContext) throws StartException {
    try {
      final ServiceContainer container = startContext.getController().getServiceContainer();

      CommonDeployment deploymentMD = deployer.deploy(container);
      if (deploymentMD.getCfs().length != 1) {
        throw new StartException("unable to start the ds because it generate more than one cf");
      }
      sqlDataSource = (javax.sql.DataSource) deploymentMD.getCfs()[0];
      log.debugf("Adding datasource: %s", deploymentMD.getCfJndiNames()[0]);
    } catch (Throwable t) {
      throw new StartException("Error during the deployment of " + jndiName, t);
    }
  }
Example #7
0
  public synchronized void start(StartContext context) throws StartException {
    try {
      final JMSServerManager jmsServer =
          new JMSServerManagerImpl(
              hornetQServer.getValue(),
              new AS7BindingRegistry(context.getController().getServiceContainer()));

      try {
        // FIXME - we also need the TCCL here in case the JMSServerManager starts the HornetQServer
        final ClassLoader loader = getClass().getClassLoader();
        SecurityActions.setContextClassLoader(loader);
        jmsServer.start();

        // FIXME - this check is a work-around for AS7-3658
        if (!hornetQServer.getValue().getConfiguration().isBackup()) {
          hornetQServer
              .getValue()
              .getRemotingService()
              .allowInvmSecurityOverride(
                  new HornetQPrincipal(
                      HornetQDefaultCredentials.getUsername(),
                      HornetQDefaultCredentials.getPassword()));
        } else {
          hornetQServer
              .getValue()
              .registerActivateCallback(
                  new ActivateCallback() {
                    public void preActivate() {}

                    public void activated() {
                      hornetQServer
                          .getValue()
                          .getRemotingService()
                          .allowInvmSecurityOverride(
                              new HornetQPrincipal(
                                  HornetQDefaultCredentials.getUsername(),
                                  HornetQDefaultCredentials.getPassword()));
                    }

                    public void deActivate() {}
                  });
        }
      } finally {
        SecurityActions.setContextClassLoader(null);
      }
      this.jmsServer = jmsServer;
    } catch (Exception e) {
      throw new StartException(e);
    }
  }
  public synchronized void start(StartContext startContext) throws StartException {
    try {
      final ServiceContainer container = startContext.getController().getServiceContainer();

      deploymentMD = getDeployer().deploy(container);
      if (deploymentMD.getCfs().length != 1) {
        throw ConnectorLogger.ROOT_LOGGER.cannotStartDs();
      }
      sqlDataSource =
          new WildFlyDataSource((javax.sql.DataSource) deploymentMD.getCfs()[0], jndiName);
      DS_DEPLOYER_LOGGER.debugf("Adding datasource: %s", deploymentMD.getCfJndiNames()[0]);
    } catch (Throwable t) {
      throw ConnectorLogger.ROOT_LOGGER.deploymentError(t, dsName);
    }
  }
 @Override
 public void start(StartContext context) throws StartException {
   try {
     JPA_LOGGER.startingService("Persistence Unit", pu.getScopedPersistenceUnitName());
     pu.setTempClassLoaderFactory(new TempClassLoaderFactoryImpl(classLoader));
     pu.setJtaDataSource(jtaDataSource.getOptionalValue());
     pu.setNonJtaDataSource(nonJtaDataSource.getOptionalValue());
     WritableServiceBasedNamingStore.pushOwner(
         context.getController().getServiceContainer().subTarget());
     this.entityManagerFactory = createContainerEntityManagerFactory();
   } finally {
     pu.setTempClassLoaderFactory(
         null); // release the temp classloader factory (only needed when creating the EMF)
     WritableServiceBasedNamingStore.popOwner();
   }
 }
Example #10
0
 /** {@inheritDoc} */
 public void start(StartContext context) throws StartException {
   final T service = getValue();
   // Handle Start
   log.debugf("Starting Service: %s", context.getController().getName());
   try {
     final Method startMethod = service.getClass().getMethod("start");
     ClassLoader old =
         SecurityActions.setThreadContextClassLoader(service.getClass().getClassLoader());
     try {
       startMethod.invoke(service);
     } finally {
       SecurityActions.resetThreadContextClassLoader(old);
     }
   } catch (NoSuchMethodException e) {
   } catch (Exception e) {
     throw new StartException("Failed to execute legacy service start", e);
   }
 }
Example #11
0
  public synchronized void start(StartContext context) throws StartException {
    log.debugf("Starting Arquillian Test Runner");

    final MBeanServer mbeanServer = injectedMBeanServer.getValue();
    serviceContainer = context.getController().getServiceContainer();
    serviceTarget = context.getChildTarget();
    try {
      jmxTestRunner = new ExtendedJMXTestRunner();
      jmxTestRunner.registerMBean(mbeanServer);
    } catch (Throwable t) {
      throw new StartException("Failed to start Arquillian Test Runner", t);
    }

    final ArquillianService arqService = this;
    serviceContainer.addListener(
        new AbstractServiceListener<Object>() {

          @Override
          public void serviceStarted(ServiceController<? extends Object> controller) {
            ServiceName serviceName = controller.getName();
            String simpleName = serviceName.getSimpleName();
            if (JBOSS_DEPLOYMENT.isParentOf(serviceName)
                && simpleName.equals(Phase.INSTALL.toString())) {
              ServiceName parentName = serviceName.getParent();
              ServiceController<?> parentController = serviceContainer.getService(parentName);
              DeploymentUnit depUnit = (DeploymentUnit) parentController.getValue();
              ArquillianConfig arqConfig =
                  ArquillianConfigBuilder.processDeployment(arqService, depUnit);
              if (arqConfig != null) {
                log.infof("Arquillian deployment detected: %s", arqConfig);
                ServiceBuilder<ArquillianConfig> builder =
                    arqConfig.buildService(serviceTarget, controller);
                FrameworkActivationProcessor.process(serviceContainer, builder, arqConfig);
                builder.install();
              }
            }
          }

          @Override
          public void serviceStopped(ServiceController<? extends Object> controller) {}
        });
  }
Example #12
0
 /**
  * Bind the entry into the injected context.
  *
  * @param context The start context
  * @throws StartException If the entity can not be bound
  */
 public synchronized void start(StartContext context) throws StartException {
   final ServiceBasedNamingStore namingStore = namingStoreValue.getValue();
   ServiceController<?> controller = context.getController();
   this.controller = controller;
   namingStore.add(controller.getName());
   ROOT_LOGGER.tracef(
       "Bound resource %s into naming store %s (service name %s)",
       name, namingStore, controller.getName());
   if (deploymentServiceName != null) {
     // add this controller service name to the related deployment runtime bindings management
     // service, which if stop will release this service too, thus removing the bind
     final Set<ServiceName> duBindingReferences =
         (Set<ServiceName>)
             controller
                 .getServiceContainer()
                 .getService(JndiNamingDependencyProcessor.serviceName(deploymentServiceName))
                 .getValue();
     duBindingReferences.add(controller.getName());
   }
 }
Example #13
0
  @Override
  public void start(StartContext context) throws StartException {
    JacORBLogger.ROOT_LOGGER.debugServiceStartup(
        context.getController().getName().getCanonicalName());

    ORB orb = this.orbInjector.getOptionalValue();
    POA parentPOA = this.parentPOAInjector.getOptionalValue();

    // if an ORB has been injected, we will use the ORB.resolve_initial_references method to
    // instantiate the POA.
    if (orb != null) {
      try {
        this.poa = POAHelper.narrow(orb.resolve_initial_references(this.poaName));
      } catch (Exception e) {
        throw JacORBMessages.MESSAGES.errorResolvingInitRef(this.poaName, e);
      }
    }
    // if a parent POA has been injected, we use it to create the policies and then the POA itself.
    else if (parentPOA != null) {
      try {
        Policy[] poaPolicies = this.createPolicies(parentPOA);
        this.poa = parentPOA.create_POA(this.poaName, null, poaPolicies);
      } catch (Exception e) {
        throw JacORBMessages.MESSAGES.errorCreatingPOAFromParent(e);
      }
    } else {
      throw JacORBMessages.MESSAGES.invalidPOACreationArgs();
    }

    // check if the POA should be bound to JNDI under java:/jboss.
    if (this.bindingName != null) {
      CorbaServiceUtil.bindObject(context.getChildTarget(), this.bindingName, this.poa);
    }

    // activate the created POA.
    try {
      this.poa.the_POAManager().activate();
    } catch (Exception e) {
      throw JacORBMessages.MESSAGES.errorActivatingPOA(e);
    }
  }
Example #14
0
  @Override
  public void start(StartContext context) throws StartException {
    log.debugf("Starting Service " + context.getController().getName().getCanonicalName());

    ORB orb = this.orbInjector.getOptionalValue();
    POA parentPOA = this.parentPOAInjector.getOptionalValue();

    // if an ORB has been injected, we will use the ORB.resolve_initial_references method to
    // instantiate the POA.
    if (orb != null) {
      try {
        this.poa = POAHelper.narrow(orb.resolve_initial_references(this.poaName));
      } catch (Exception e) {
        throw new StartException("Failed to resolve initial reference " + this.poaName, e);
      }
    }
    // if a parent POA has been injected, we use it to create the policies and then the POA itself.
    else if (parentPOA != null) {
      try {
        Policy[] poaPolicies = this.createPolicies(parentPOA);
        this.poa = parentPOA.create_POA(this.poaName, null, poaPolicies);
      } catch (Exception e) {
        throw new StartException("Failed to create POA from parent POA", e);
      }
    } else {
      throw new StartException(
          "Unable to instantiate POA: either the running ORB or the parent POA must be specified");
    }

    // check if the POA should be bound to JNDI under java:/jboss.
    if (this.bindingName != null) {
      CorbaServiceUtil.bindObject(context.getChildTarget(), this.bindingName, this.poa);
    }

    // activate the created POA.
    try {
      this.poa.the_POAManager().activate();
    } catch (Exception e) {
      throw new StartException("Failed to activate POA", e);
    }
  }
 public void start(final StartContext context) throws StartException {
   ServiceController<?> controller = context.getController();
   LOGGER.tracef("Starting: %s", controller.getName());
   List<Bundle> bundles = new ArrayList<Bundle>(installedBundles);
   Collections.sort(bundles, new BundleComparator());
   for (Bundle bundle : bundles) {
     TypeAdaptor adaptor = (TypeAdaptor) bundle;
     Deployment dep = adaptor.adapt(Deployment.class);
     OSGiMetaData metadata = adaptor.adapt(OSGiMetaData.class);
     if (dep.isAutoStart() && metadata.getFragmentHost() == null) {
       try {
         bundle.start(Bundle.START_ACTIVATION_POLICY);
       } catch (BundleException ex) {
         LOGGER.errorCannotStartBundle(ex, bundle);
       }
     }
   }
   LOGGER.debugf("Started: %s", controller.getName());
   installedBundles = null;
   tracker = null;
 }
  public void start(final StartContext context) throws StartException {

    if (configurationPersister == null) {
      throw MESSAGES.persisterNotInjected();
    }
    final ServiceController<?> serviceController = context.getController();
    final ServiceContainer container = serviceController.getServiceContainer();
    final ServiceTarget target = context.getChildTarget();
    final ExecutorService executorService = injectedExecutorService.getOptionalValue();
    ManagementResourceRegistration rootResourceRegistration =
        rootDescriptionProvider != null
            ? ManagementResourceRegistration.Factory.create(rootDescriptionProvider)
            : ManagementResourceRegistration.Factory.create(rootResourceDefinition);
    final ModelControllerImpl controller =
        new ModelControllerImpl(
            container,
            target,
            rootResourceRegistration,
            new ContainerStateMonitor(container),
            configurationPersister,
            processType,
            runningModeControl,
            prepareStep,
            processState,
            executorService,
            expressionResolver,
            authorizer,
            auditLogger);

    // Initialize the model
    initModel(controller.getRootResource(), controller.getRootRegistration());
    this.controller = controller;

    final long bootStackSize = getBootStackSize();
    final Thread bootThread =
        new Thread(
            null,
            new Runnable() {
              public void run() {
                try {
                  try {
                    boot(
                        new BootContext() {
                          public ServiceTarget getServiceTarget() {
                            return target;
                          }
                        });
                  } finally {
                    processState.setRunning();
                  }
                } catch (Throwable t) {
                  container.shutdown();
                  if (t instanceof StackOverflowError) {
                    ROOT_LOGGER.errorBootingContainer(t, bootStackSize, BOOT_STACK_SIZE_PROPERTY);
                  } else {
                    ROOT_LOGGER.errorBootingContainer(t);
                  }
                } finally {
                  bootThreadDone();
                }
              }
            },
            "Controller Boot Thread",
            bootStackSize);
    bootThread.start();
  }
  @Override
  public void start(StartContext context) throws StartException {

    processState.setStarting();

    final ProductConfig config = environment.getProductConfig();
    final String prettyVersion = config.getPrettyVersionString();
    ServerLogger.AS_ROOT_LOGGER.serverStarting(prettyVersion);
    if (ServerLogger.CONFIG_LOGGER.isDebugEnabled()) {
      final Properties properties = System.getProperties();
      final StringBuilder b = new StringBuilder(8192);
      b.append("Configured system properties:");
      for (String property : new TreeSet<String>(properties.stringPropertyNames())) {
        b.append("\n\t")
            .append(property)
            .append(" = ")
            .append(properties.getProperty(property, "<undefined>"));
      }
      ServerLogger.CONFIG_LOGGER.debug(b);
      ServerLogger.CONFIG_LOGGER.debugf("VM Arguments: %s", getVMArguments());
      if (ServerLogger.CONFIG_LOGGER.isTraceEnabled()) {
        b.setLength(0);
        final Map<String, String> env = System.getenv();
        b.append("Configured system environment:");
        for (String key : new TreeSet<String>(env.keySet())) {
          b.append("\n\t").append(key).append(" = ").append(env.get(key));
        }
        ServerLogger.CONFIG_LOGGER.trace(b);
      }
    }
    final ServiceTarget serviceTarget = context.getChildTarget();
    final ServiceController<?> myController = context.getController();
    final ServiceContainer serviceContainer = myController.getServiceContainer();
    futureContainer = new FutureServiceContainer();

    long startTime = this.startTime;
    if (startTime == -1) {
      startTime = System.currentTimeMillis();
    } else {
      this.startTime = -1;
    }

    final BootstrapListener bootstrapListener =
        new BootstrapListener(
            serviceContainer,
            startTime,
            serviceTarget,
            futureContainer,
            prettyVersion + " (Host Controller)");
    bootstrapListener.getStabilityMonitor().addController(myController);

    // The first default services are registered before the bootstrap operations are executed.

    // Install the process controller client
    final ProcessControllerConnectionService processControllerClient =
        new ProcessControllerConnectionService(environment, authCode);
    serviceTarget
        .addService(ProcessControllerConnectionService.SERVICE_NAME, processControllerClient)
        .install();

    // Executor Services
    final HostControllerExecutorService executorService = new HostControllerExecutorService();
    serviceTarget
        .addService(HC_EXECUTOR_SERVICE_NAME, executorService)
        .addAliases(
            ManagementRemotingServices
                .SHUTDOWN_EXECUTOR_NAME) // Use this executor for mgmt shutdown for now
        .install();

    // Install required path services. (Only install those identified as required)
    HostPathManagerService hostPathManagerService = new HostPathManagerService();
    HostPathManagerService.addService(serviceTarget, hostPathManagerService, environment);

    HttpListenerRegistryService.install(serviceTarget);

    // Add product config service
    final Value<ProductConfig> productConfigValue = new ImmediateValue<ProductConfig>(config);
    serviceTarget
        .addService(
            Services.JBOSS_PRODUCT_CONFIG_SERVICE,
            new ValueService<ProductConfig>(productConfigValue))
        .setInitialMode(ServiceController.Mode.ACTIVE)
        .install();

    DomainModelControllerService.addService(
        serviceTarget,
        environment,
        runningModeControl,
        processState,
        bootstrapListener,
        hostPathManagerService);
  }
 @Override
 public void start(StartContext startContext) throws StartException {
   ServiceRegistry serviceRegistry = startContext.getController().getServiceContainer();
   createHandlerRegistry =
       new ContextCreateHandlerRegistryImpl(serviceRegistry, startContext.getChildTarget());
 }
  @Override
  public synchronized void start(final StartContext context) throws StartException {
    final ServiceContainer serviceContainer = context.getController().getServiceContainer();

    thread =
        new Thread(
            new Runnable() {

              @Override
              public void run() {
                final ClassLoader oldTccl =
                    WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
                try {
                  try {
                    try {
                      WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(classLoader);
                      AccessController.doPrivileged(new SetSelectorAction(contextSelector));
                      applicationClientDeploymentServiceInjectedValue
                          .getValue()
                          .getDeploymentCompleteLatch()
                          .await();
                      NamespaceContextSelector.setDefault(namespaceContextSelectorInjectedValue);

                      try {
                        // perform any additional setup that may be needed
                        for (SetupAction action : setupActions) {
                          action.setup(Collections.<String, Object>emptyMap());
                        }

                        // do static injection etc
                        instance = applicationClientComponent.getValue().createInstance();

                        mainMethod.invoke(null, new Object[] {parameters});
                      } finally {
                        final ListIterator<SetupAction> iterator =
                            setupActions.listIterator(setupActions.size());
                        Throwable error = null;
                        while (iterator.hasPrevious()) {
                          SetupAction action = iterator.previous();
                          try {
                            action.teardown(Collections.<String, Object>emptyMap());
                          } catch (Throwable e) {
                            error = e;
                          }
                        }
                        if (error != null) {
                          throw new RuntimeException(error);
                        }
                      }
                    } catch (Exception e) {
                      ROOT_LOGGER.exceptionRunningAppClient(e, e.getClass().getSimpleName());
                    } finally {
                      WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl);
                    }
                  } finally {
                    if (contextSelector instanceof LazyConnectionContextSelector) {
                      ((LazyConnectionContextSelector) contextSelector).close();
                    }
                  }
                } finally {
                  serviceContainer.shutdown();
                }
              }
            });
    thread.start();
    Runtime.getRuntime()
        .addShutdownHook(
            new Thread(
                new Runnable() {
                  @Override
                  public void run() {
                    if (serviceContainer != null) {
                      serviceContainer.shutdown();
                    }
                  }
                }));
  }