Пример #1
0
  @Override
  protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model)
      throws OperationFailedException {

    ServiceRegistry registry = context.getServiceRegistry(false);
    final ServiceName serviceName =
        MessagingServices.getActiveMQServiceName(
            PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
    ServiceController<?> service = registry.getService(serviceName);
    if (service != null) {
      context.reloadRequired();
    } else {
      final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
      final String name = address.getLastElement().getValue();

      final ServiceTarget target = context.getServiceTarget();
      if (model.hasDefined(JGROUPS_CHANNEL.getName())) {
        // nothing to do, in that case, the clustering.jgroups subsystem will have setup the stack
      } else if (model.hasDefined(RemoteTransportDefinition.SOCKET_BINDING.getName())) {
        final GroupBindingService bindingService = new GroupBindingService();
        target
            .addService(
                GroupBindingService.getBroadcastBaseServiceName(serviceName).append(name),
                bindingService)
            .addDependency(
                SocketBinding.JBOSS_BINDING_NAME.append(model.get(SOCKET_BINDING).asString()),
                SocketBinding.class,
                bindingService.getBindingRef())
            .install();
      }
    }
  }
  void updatePoolService(final OperationContext context, final ModelNode model)
      throws OperationFailedException {

    final ModelNode poolName = poolAttribute.resolveModelAttribute(context, model);

    final ServiceRegistry serviceRegistry = context.getServiceRegistry(true);
    ServiceController existingDefaultPoolConfigService =
        serviceRegistry.getService(poolConfigServiceName);
    // if a default MDB pool is already installed, then remove it first
    if (existingDefaultPoolConfigService != null) {
      context.removeService(existingDefaultPoolConfigService);
    }

    if (poolName.isDefined()) {
      // now install default pool config service which points to an existing pool config service
      final ValueInjectionService<PoolConfig> newDefaultPoolConfigService =
          new ValueInjectionService<PoolConfig>();
      ServiceController<?> newController =
          context
              .getServiceTarget()
              .addService(poolConfigServiceName, newDefaultPoolConfigService)
              .addDependency(
                  PoolConfigService.EJB_POOL_CONFIG_BASE_SERVICE_NAME.append(poolName.asString()),
                  PoolConfig.class,
                  newDefaultPoolConfigService.getInjector())
              .install();
    }
  }
Пример #3
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;
  }
 public void undeploy(DeploymentUnit deploymentUnit) {
   final List<ResourceRoot> childRoots = deploymentUnit.getAttachment(Attachments.RESOURCE_ROOTS);
   if (childRoots != null) {
     final ServiceRegistry serviceRegistry = deploymentUnit.getServiceRegistry();
     for (final ResourceRoot childRoot : childRoots) {
       if (!SubDeploymentMarker.isSubDeployment(childRoot)) {
         continue;
       }
       final ServiceName serviceName =
           deploymentUnit.getServiceName().append(childRoot.getRootName());
       final ServiceController<?> serviceController = serviceRegistry.getService(serviceName);
       if (serviceController != null) {
         serviceController.setMode(ServiceController.Mode.REMOVE);
       }
     }
   }
 }
  @SuppressWarnings("unchecked")
  @Override
  public final Object getObjectInstance(
      Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
    final Reference reference = asReference(obj);
    final ServiceNameRefAdr nameAdr = (ServiceNameRefAdr) reference.get("srof");
    if (nameAdr == null) {
      throw new NamingException("Invalid context reference.  Not a 'srof' reference.");
    }
    final ServiceName serviceName = (ServiceName) nameAdr.getContent();
    final ServiceController<?> controller;
    try {
      controller = serviceRegistry.getRequiredService(serviceName);
    } catch (ServiceNotFoundException e) {
      throw new NamingException("Could not resolve service " + serviceName);
    }

    ServiceReferenceListener listener = new ServiceReferenceListener();
    controller.addListener(listener);
    synchronized (listener) {
      // if we are interrupted just let the exception propagate for now
      while (!listener.finished) {
        try {
          listener.wait();
        } catch (InterruptedException e) {
          throw new NamingException(
              "Thread interrupted while retrieving service reference for service " + serviceName);
        }
      }
    }
    switch (listener.getState()) {
      case UP:
        return getObjectInstance(listener.getValue(), obj, name, nameCtx, environment);
      case START_FAILED:
        throw new NamingException(
            "Could not resolve service reference to "
                + serviceName
                + " in factory "
                + getClass().getName()
                + ". Service was in state START_FAILED.");
      case REMOVED:
        throw new NamingException(
            "Could not resolve service reference to "
                + serviceName
                + " in factory "
                + getClass().getName()
                + ". Service was in state START_FAILED.");
    }
    // we should never get here, as the listener should not notify unless the state was one of the
    // above
    throw new NamingException(
        "Could not resolve service reference to "
            + serviceName
            + " in factory "
            + getClass().getName()
            + ". This is a bug in ServiceReferenceObjectFactory. State was"
            + listener.getState());
  }
Пример #6
0
 @Override
 protected void performRuntime(
     final OperationContext context,
     final ModelNode operation,
     final ModelNode model,
     final ServiceVerificationHandler verificationHandler,
     final List<ServiceController<?>> newControllers)
     throws OperationFailedException {
   final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
   final String name = address.getLastElement().getValue();
   final ModelNode level = LEVEL.resolveModelAttribute(context, model);
   final ServiceRegistry serviceRegistry = context.getServiceRegistry(true);
   @SuppressWarnings("unchecked")
   final ServiceController<Logger> controller =
       (ServiceController<Logger>) serviceRegistry.getService(LogServices.loggerName(name));
   if (controller != null && level.isDefined()) {
     controller.getValue().setLevel(ModelParser.parseLevel(level));
   }
 }
Пример #7
0
  @Override
  protected void performRuntime(
      OperationContext context,
      ModelNode operation,
      ModelNode model,
      ServiceVerificationHandler verificationHandler,
      List<ServiceController<?>> newControllers)
      throws OperationFailedException {

    ServiceRegistry registry = context.getServiceRegistry(false);
    final ServiceName hqServiceName =
        MessagingServices.getHornetQServiceName(
            PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
    ServiceController<?> hqService = registry.getService(hqServiceName);
    if (hqService != null) {
      context.reloadRequired();
    }
    // else MessagingSubsystemAdd will add a handler that calls addConnectorServiceConfigs
  }
 /**
  * Returns the name of the resource adapter which will be used as the default RA for MDBs (unless
  * overridden by the MDBs).
  *
  * @param serviceRegistry
  * @return
  */
 private String getDefaultResourceAdapterName(final ServiceRegistry serviceRegistry) {
   if (appclient) {
     // we must report the MDB, but we can't use any MDB/JCA facilities
     return "n/a";
   }
   final ServiceController<DefaultResourceAdapterService> serviceController =
       (ServiceController<DefaultResourceAdapterService>)
           serviceRegistry.getRequiredService(
               DefaultResourceAdapterService.DEFAULT_RA_NAME_SERVICE_NAME);
   return serviceController.getValue().getDefaultResourceAdapterName();
 }
 private Object lookup(final String name, final ServiceName lookupName)
     throws NameNotFoundException {
   final ServiceController<?> controller = serviceRegistry.getService(lookupName);
   final Object object;
   if (controller != null) {
     try {
       object = controller.getValue();
     } catch (IllegalStateException e) {
       // occurs if the service is not actually up
       throw new NameNotFoundException(
           "Error looking up " + name + ", service " + lookupName + " is not started");
     }
   } else {
     return null;
   }
   if (object instanceof ManagedReferenceFactory) {
     return ManagedReferenceFactory.class.cast(object).getReference().getInstance();
   }
   return object;
 }
 public static Deployment getDeployment(ServiceRegistry registry, String contextName) {
   ServiceController<?> controller = registry.getService(getServiceName(contextName));
   return controller != null ? (Deployment) controller.getValue() : null;
 }