@Override
  public void unregisterService(ServiceState serviceState) {
    List<ServiceName> serviceNames = serviceState.getServiceNames();
    log.debug("Unregister service: " + serviceNames);

    AbstractBundle serviceOwner = serviceState.getServiceOwner();

    // This event is synchronously delivered before the service has completed unregistering.
    eventsPlugin.fireServiceEvent(serviceOwner, ServiceEvent.UNREGISTERING, serviceState);

    // Remove from using bundles
    for (AbstractBundle bundleState : serviceState.getUsingBundlesInternal()) {
      while (ungetService(bundleState, serviceState)) ;
    }

    // Remove from owner bundle
    serviceOwner.removeRegisteredService(serviceState);

    // Unregister name associations
    for (ServiceName serviceName : serviceNames) {
      String[] clazzes = (String[]) serviceState.getProperty(Constants.OBJECTCLASS);
      for (String clazz : clazzes) unregisterNameAssociation(clazz, serviceName);
    }

    // Remove from controller
    ServiceName rootServiceName = serviceNames.get(0);
    try {
      ServiceController<?> controller = serviceContainer.getService(rootServiceName);
      controller.setMode(Mode.REMOVE);
    } catch (RuntimeException ex) {
      log.error("Cannot remove service: " + rootServiceName, ex);
    }
  }
  public ModelController createController(final ModelNode model, final Setup registration)
      throws InterruptedException {
    final ServiceController<?> existingController =
        serviceContainer.getService(ServiceName.of("ModelController"));
    if (existingController != null) {
      final CountDownLatch latch = new CountDownLatch(1);
      existingController.addListener(
          new AbstractServiceListener<Object>() {
            public void listenerAdded(ServiceController<?> serviceController) {
              serviceController.setMode(ServiceController.Mode.REMOVE);
            }

            public void transition(
                ServiceController<?> serviceController, ServiceController.Transition transition) {
              if (transition.equals(ServiceController.Transition.REMOVING_to_REMOVED)) {
                latch.countDown();
              }
            }
          });
      latch.await();
    }

    ServiceTarget target = serviceContainer.subTarget();
    ControlledProcessState processState = new ControlledProcessState(true);
    ModelControllerService svc = new ModelControllerService(processState, registration, model);
    ServiceBuilder<ModelController> builder =
        target.addService(ServiceName.of("ModelController"), svc);
    builder.install();
    svc.latch.await();
    ModelController controller = svc.getValue();
    ModelNode setup = Util.getEmptyOperation("setup", new ModelNode());
    controller.execute(setup, null, null, null);
    processState.setRunning();
    return controller;
  }
예제 #3
0
  /**
   * Test configuration
   *
   * @throws Throwable Thrown if case of an error
   */
  @Test
  public void testRegistryConfiguration() throws Throwable {
    ServiceController<?> controller =
        serviceContainer.getService(ConnectorServices.RA_REPOSITORY_SERVICE);
    assertNotNull(controller);
    ResourceAdapterRepository repository = (ResourceAdapterRepository) controller.getValue();
    assertNotNull(repository);
    Set<String> ids = repository.getResourceAdapters(javax.jms.MessageListener.class);

    assertNotNull(ids);
    int pureInflowListener = 0;
    for (String id : ids) {
      if (id.indexOf("PureInflow") != -1) {
        pureInflowListener++;
      }
    }
    assertEquals(1, pureInflowListener);

    String piId = ids.iterator().next();
    assertNotNull(piId);

    Endpoint endpoint = repository.getEndpoint(piId);
    assertNotNull(endpoint);

    List<MessageListener> listeners = repository.getMessageListeners(piId);
    assertNotNull(listeners);
    assertEquals(1, listeners.size());

    MessageListener listener = listeners.get(0);

    ActivationSpec as = listener.getActivation().createInstance();
    assertNotNull(as);
    assertNotNull(as.getResourceAdapter());
  }
 private synchronized void establishModelControllerClient(ControlledProcessState.State state) {
   ModelControllerClient newClient = null;
   if (state != ControlledProcessState.State.STOPPING && serviceContainer != null) {
     @SuppressWarnings("unchecked")
     final Value<ModelController> controllerService =
         (Value<ModelController>) serviceContainer.getService(Services.JBOSS_SERVER_CONTROLLER);
     if (controllerService != null) {
       final ModelController controller = controllerService.getValue();
       newClient = controller.createClient(executorService);
     } // else TODO use some sort of timeout and poll. A non-stopping server should install a
     // ModelController very quickly
   }
   modelControllerClient = newClient;
   currentProcessState = state;
 }
예제 #5
0
  @Test
  public void testMetadataConfiguration() throws Throwable {
    ServiceController<?> controller =
        serviceContainer.getService(ConnectorServices.IRONJACAMAR_MDR);
    assertNotNull(controller);
    MetadataRepository repository = (MetadataRepository) controller.getValue();
    assertNotNull(repository);
    Set<String> ids = repository.getResourceAdapters();

    assertNotNull(ids);

    String piId = ids.iterator().next();
    assertNotNull(piId);
    assertNotNull(repository.getResourceAdapter(piId));
  }
 public ModuleIdentifier addExternalModule(VirtualFile externalModule) {
   ModuleIdentifier identifier =
       ModuleIdentifier.create(EXTERNAL_MODULE_PREFIX + externalModule.getPathName());
   ServiceName serviceName = ServiceModuleLoader.moduleSpecServiceName(identifier);
   ServiceController<?> controller = serviceContainer.getService(serviceName);
   if (controller == null) {
     try {
       ExternalModuleSpecService service =
           new ExternalModuleSpecService(identifier, externalModule.getPhysicalFile());
       serviceContainer.addService(serviceName, service).setInitialMode(Mode.ON_DEMAND).install();
     } catch (IOException e) {
       throw new RuntimeException(e);
     }
   }
   return identifier;
 }
예제 #7
0
  @Test
  public void testMetadataConfiguration() throws Throwable {
    ServiceController<?> controller =
        serviceContainer.getService(ConnectorServices.IRONJACAMAR_MDR);
    assertNotNull(controller);
    MetadataRepository repository = (MetadataRepository) controller.getValue();
    assertNotNull(repository);
    Set<String> ids = repository.getResourceAdapters();

    assertNotNull(ids);
    // on a running server it's always 2 beacause HornetQResourceAdapter is always present
    assertEquals(1, ids.size());

    for (String piId : ids) {
      assertNotNull(piId);
      System.out.println("PID:" + piId);
      assertNotNull(repository.getResourceAdapter(piId));
    }
  }
예제 #8
0
  /**
   * Test configuration
   *
   * @throws Throwable Thrown if case of an error
   */
  @Test
  public void testRegistryConfiguration() throws Throwable {
    ServiceController<?> controller =
        serviceContainer.getService(ConnectorServices.RA_REPOSITORY_SERVICE);
    assertNotNull(controller);
    ResourceAdapterRepository repository = (ResourceAdapterRepository) controller.getValue();
    assertNotNull(repository);
    Set<String> ids = repository.getResourceAdapters();

    assertNotNull(ids);
    // On a running server it's 3 beacause HornetQResourceAdapter is always present  + ra itself and
    // 1 actrivation from DMR
    assertEquals(2, ids.size());

    for (String piId : ids) {
      assertNotNull(piId);
      System.out.println("PID:" + piId);
      assertNotNull(repository.getResourceAdapter(piId));
    }
  }
  /**
   * 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);
    }
  }
  public List<ServiceState> getServiceReferencesInternal(
      AbstractBundle bundleState, String clazz, Filter filter, boolean checkAssignable) {
    if (bundleState == null) throw new IllegalArgumentException("Null bundleState");

    List<ServiceName> serviceNames;
    if (clazz != null) {
      serviceNames = serviceNameMap.get(clazz);
      if (serviceNames == null) serviceNames = new ArrayList<ServiceName>();

      // Add potentially registered xservcie
      ServiceName xserviceName = ServiceName.of(ModuleContext.XSERVICE_PREFIX, clazz);
      ServiceController<?> xservice = serviceContainer.getService(xserviceName);
      if (xservice != null) serviceNames.add(xserviceName);
    } else {
      // [MSC-9] Add ability to query the ServiceContainer
      Set<ServiceName> allServiceNames = new HashSet<ServiceName>();
      for (List<ServiceName> auxList : serviceNameMap.values()) allServiceNames.addAll(auxList);

      serviceNames = new ArrayList<ServiceName>(allServiceNames);
    }

    if (serviceNames.isEmpty()) return Collections.emptyList();

    if (filter == null) filter = NoFilter.INSTANCE;

    List<ServiceState> result = new ArrayList<ServiceState>();
    for (ServiceName serviceName : serviceNames) {
      ServiceController<?> controller = serviceContainer.getService(serviceName);
      if (controller == null)
        throw new IllegalStateException("Cannot obtain service for: " + serviceName);

      Object value = controller.getValue();

      // Create the ServiceState on demand for an XService instance
      // [TODO] This should be done eagerly to keep the serviceId constant
      // [TODO] service events for XService lifecycle changes
      // [MSC-17] Canonical ServiceName string representation
      if (value instanceof ServiceState == false
          && serviceName.toString().contains(ModuleContext.XSERVICE_PREFIX)) {
        long serviceId = getNextServiceId();
        Bundle bundle = packageAdmin.getBundle(value.getClass());
        AbstractBundle owner = AbstractBundle.assertBundleState(bundle);
        value =
            new ServiceState(
                owner,
                serviceId,
                new ServiceName[] {serviceName},
                new String[] {clazz},
                value,
                null);
      }

      ServiceState serviceState = (ServiceState) value;
      if (filter.match(serviceState) == false) continue;

      Object rawValue = serviceState.getRawValue();

      checkAssignable &= (clazz != null);
      checkAssignable &= (bundleState.getBundleId() != 0);
      checkAssignable &= !(rawValue instanceof ServiceFactory);
      if (checkAssignable == false || serviceState.isAssignableTo(bundleState, clazz)) {
        result.add(serviceState);
      }
    }

    // Sort the result
    Collections.sort(result, ServiceReferenceComparator.getInstance());
    Collections.reverse(result);

    return Collections.unmodifiableList(result);
  }
 public static void removeService(ServiceContainer container, String contextName) {
   ServiceController<?> controller = container.getService(getServiceName(contextName));
   if (controller != null) controller.setMode(Mode.REMOVE);
 }
 void setServiceMode(ServiceName serviceName, Mode mode) {
   ServiceController<?> controller = serviceContainer.getService(serviceName);
   if (controller == null)
     LOGGER.debugf("Cannot set mode %s on non-existing service: %s", mode, serviceName);
   else setServiceMode(controller, mode);
 }