/** {@inheritDoc} */
 public void serviceFailed(
     ServiceController<? extends Object> serviceController, StartException reason) {
   final ServiceName serviceName = serviceController.getName();
   log.errorf(reason, "Service [%s] start failed", serviceName);
   serviceFailures.put(serviceName, reason);
   if (!expectedOnDemandServices.contains(serviceController.getName())
       && countUpdater.decrementAndGet(this) == 0) {
     batchComplete();
   }
   serviceController.removeListener(this);
 }
 /** {@inheritDoc} */
 public void serviceStarted(final ServiceController<? extends Object> serviceController) {
   startedServicesUpdater.incrementAndGet(this);
   if (expectedOnDemandServices.contains(serviceController.getName())) {
     startedOnDemandServicesUpdater.incrementAndGet(this);
   }
   if (!expectedOnDemandServices.contains(serviceController.getName())
       && countUpdater.decrementAndGet(this) == 0) {
     batchComplete();
   }
   serviceController.removeListener(this);
 }
Пример #3
0
 public void serviceFailed(
     ServiceController<? extends Object> serviceController, StartException reason) {
   final ServiceFailureFuture future = expectedFailures.remove(serviceController.getName());
   if (future != null) {
     future.setStartException(reason);
   }
 }
Пример #4
0
 public void transition(
     ServiceController<? extends Object> controller, ServiceController.Transition transition) {
   if (transition == ServiceController.Transition.STARTING_to_UP
       || transition == ServiceController.Transition.REMOVING_to_REMOVED) {
     services.put(transition, controller.getName());
     latch.countDown();
   }
 }
Пример #5
0
 /**
  * Rollback runtime changes made in {@link #performRuntime(OperationContext,
  * org.jboss.dmr.ModelNode, org.jboss.dmr.ModelNode, ServiceVerificationHandler, java.util.List)}.
  *
  * <p>This default implementation removes all services in the given list of {@code controllers}.
  * The contents of {@code controllers} is the same as what was in the {@code newControllers}
  * parameter passed to {@code performRuntime()} when that method returned.
  *
  * @param context the operation context
  * @param operation the operation being executed
  * @param model persistent configuration model node that corresponds to the address of {@code
  *     operation}
  * @param controllers holder for the {@link ServiceController} for any new services installed by
  *     {@link #performRuntime(OperationContext, org.jboss.dmr.ModelNode, org.jboss.dmr.ModelNode,
  *     ServiceVerificationHandler, java.util.List)}
  */
 protected void rollbackRuntime(
     OperationContext context,
     final ModelNode operation,
     final ModelNode model,
     List<ServiceController<?>> controllers) {
   for (ServiceController<?> controller : controllers) {
     context.removeService(controller.getName());
   }
 }
 void setServiceMode(ServiceController<?> controller, Mode mode) {
   try {
     LOGGER.tracef("Set mode %s on service: %s", mode, controller.getName());
     controller.setMode(mode);
   } catch (IllegalArgumentException rte) {
     // [MSC-105] Cannot determine whether container is shutting down
     if (rte.getMessage().equals("Container is shutting down") == false) throw rte;
   }
 }
  @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);
    }
  }
Пример #8
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());
   }
 }
Пример #9
0
 ServiceBuilder<ArquillianConfig> buildService(
     ServiceTarget serviceTarget, ServiceController<?> depController) {
   ServiceBuilder<ArquillianConfig> builder = serviceTarget.addService(getServiceName(), this);
   builder.addDependency(
       DependencyType.OPTIONAL,
       Services.SYSTEM_CONTEXT,
       BundleContext.class,
       injectedBundleContext);
   builder.addDependency(depController.getName());
   return builder;
 }
Пример #10
0
  private synchronized ContainerStateChangeReport createContainerStateChangeReport() {

    final Map<ServiceName, Set<ServiceName>> missingDeps =
        new HashMap<ServiceName, Set<ServiceName>>();
    for (ServiceController<?> controller : servicesWithMissingDeps) {
      for (ServiceName missing : controller.getImmediateUnavailableDependencies()) {
        Set<ServiceName> dependents = missingDeps.get(missing);
        if (dependents == null) {
          dependents = new HashSet<ServiceName>();
          missingDeps.put(missing, dependents);
        }
        dependents.add(controller.getName());
      }
    }

    final Set<ServiceName> previousMissing = previousMissingDepSet;

    // no longer missing deps...
    final Map<ServiceName, Boolean> noLongerMissingServices = new TreeMap<ServiceName, Boolean>();
    for (ServiceName name : previousMissing) {
      if (!missingDeps.containsKey(name)) {
        ServiceController<?> controller = serviceRegistry.getService(name);
        noLongerMissingServices.put(name, controller == null);
      }
    }

    // newly missing deps
    final Map<ServiceName, MissingDependencyInfo> missingServices =
        new TreeMap<ServiceName, MissingDependencyInfo>();
    for (Map.Entry<ServiceName, Set<ServiceName>> entry : missingDeps.entrySet()) {
      final ServiceName name = entry.getKey();
      if (!previousMissing.contains(name)) {
        ServiceController<?> controller = serviceRegistry.getService(name);
        boolean unavailable = controller != null;
        missingServices.put(name, new MissingDependencyInfo(name, unavailable, entry.getValue()));
      }
    }

    final Map<ServiceController<?>, String> currentFailedControllers =
        new HashMap<ServiceController<?>, String>(failedControllers);

    previousMissingDepSet = new HashSet<ServiceName>(missingDeps.keySet());

    failedControllers.clear();

    boolean needReport =
        !missingServices.isEmpty()
            || !currentFailedControllers.isEmpty()
            || !noLongerMissingServices.isEmpty();
    return needReport
        ? new ContainerStateChangeReport(
            missingServices, currentFailedControllers, noLongerMissingServices)
        : null;
  }
Пример #11
0
 ServiceBuilder<ArquillianConfig> buildService(
     ServiceTarget serviceTarget, ServiceController<?> depController) {
   ServiceBuilder<ArquillianConfig> builder = serviceTarget.addService(getServiceName(), this);
   builder.addDependency(
       DependencyType.OPTIONAL,
       ServiceName.parse("jbosgi.framework.CREATE"),
       BundleContext.class,
       injectedBundleContext);
   builder.addDependency(depController.getName());
   return builder;
 }
 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;
 }
Пример #13
0
 /**
  * Unbind the entry from the injected context.
  *
  * @param context The stop context
  */
 public synchronized void stop(StopContext context) {
   final ServiceBasedNamingStore namingStore = namingStoreValue.getValue();
   namingStore.remove(context.getController().getName());
   if (deploymentServiceName != null) {
     // remove the service name from the related deployment runtime bindings management service,
     final Set<ServiceName> duBindingReferences =
         (Set<ServiceName>)
             controller
                 .getServiceContainer()
                 .getService(JndiNamingDependencyProcessor.serviceName(deploymentServiceName))
                 .getValue();
     if (duBindingReferences != null) {
       // the set is null if the binder service was stopped by the deployment unit undeploy
       duBindingReferences.remove(controller.getName());
     }
   }
 }
  /**
   * Uninstall the Bundle associated with this deployment.
   *
   * @param context The stop context.
   */
  public synchronized void stop(StopContext context) {
    log.tracef("Uninstalling deployment: %s", deployment);
    try {
      BundleManager bundleManager = injectedBundleManager.getValue();
      bundleManager.uninstallBundle(deployment);

      ServiceController<?> controller = context.getController();
      ServiceContainer serviceContainer = controller.getServiceContainer();
      controller.setMode(Mode.REMOVE);

      // [JBAS-8801] Undeployment leaks root deployment service
      // [TODO] remove this workaround
      ServiceName serviceName = Services.deploymentUnitName(controller.getName().getSimpleName());
      ServiceController<?> deploymentController = serviceContainer.getService(serviceName);
      if (deploymentController != null) {
        deploymentController.setMode(Mode.REMOVE);
      }
    } catch (Throwable t) {
      log.errorf(t, "Failed to uninstall deployment: %s", deployment);
    }
  }
Пример #15
0
 /** {@inheritDoc} */
 public void listenerAdded(final ServiceController<? extends Object> serviceController) {
   totalServicesUpdater.incrementAndGet(this);
   if (!expectedOnDemandServices.contains(serviceController.getName())) {
     countUpdater.incrementAndGet(this);
   }
 }
 @Override
 public synchronized void stop(StopContext context) {
   ServiceController<?> controller = context.getController();
   LOGGER.tracef("Stopping: %s in mode %s", controller.getName(), controller.getMode());
 }
Пример #17
0
 public void serviceRemoved(ServiceController<? extends Object> serviceController) {
   final ServiceFuture future = expectedRemovals.remove(serviceController.getName());
   if (future != null) {
     future.setServiceController(serviceController);
   }
 }