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;
  }
Exemplo n.º 2
0
/** @author <a href="mailto:[email protected]">David M. Lloyd</a> */
public final class LogServices {

  public static final ServiceName JBOSS_LOGGING = ServiceName.JBOSS.append("logging");

  public static final ServiceName LOGGER = JBOSS_LOGGING.append("logger");

  public static final ServiceName ROOT_LOGGER = JBOSS_LOGGING.append("root-logger");

  public static final ServiceName LOGGER_HANDLER = JBOSS_LOGGING.append("logger-handler");

  public static final ServiceName ROOT_LOGGER_HANDLER = JBOSS_LOGGING.append("root-logger-handler");

  public static final ServiceName HANDLER = JBOSS_LOGGING.append("handler");

  private LogServices() {}

  public static ServiceName loggerName(final String name) {
    return "".equals(name) ? ROOT_LOGGER : LOGGER.append(name);
  }

  public static ServiceName loggerHandlerName(final String loggerName, final String handlerName) {
    return loggerName.length() == 0
        ? ROOT_LOGGER_HANDLER.append(handlerName)
        : LOGGER_HANDLER.append(loggerName, handlerName);
  }

  public static ServiceName handlerName(final String name) {
    return HANDLER.append(name);
  }
}
Exemplo n.º 3
0
 /**
  * Get the service name of a context, or {@code null} if there is no service mapping for the
  * context name.
  *
  * @param app the application name
  * @param module the module name
  * @param comp the component name
  * @param context the context to check
  * @return the service name or {@code null} if there is no service
  */
 public static ServiceName serviceNameOfContext(
     String app, String module, String comp, String context) {
   if (context.startsWith("java:")) {
     final String namespace;
     final int i = context.indexOf('/');
     if (i == -1) {
       namespace = context.substring(5);
     } else {
       namespace = context.substring(5, i);
     }
     if (namespace.equals("global")) {
       return GLOBAL_CONTEXT_SERVICE_NAME.append(context.substring(12));
     } else if (namespace.equals("jboss")) {
       return JBOSS_CONTEXT_SERVICE_NAME.append(context.substring(11));
     } else if (namespace.equals("app")) {
       return contextServiceNameOfApplication(app).append(context.substring(9));
     } else if (namespace.equals("module")) {
       return contextServiceNameOfModule(app, module).append(context.substring(12));
     } else if (namespace.equals("comp")) {
       return contextServiceNameOfComponent(app, module, comp).append(context.substring(10));
     } else {
       return JAVA_CONTEXT_SERVICE_NAME.append(context);
     }
   } else {
     return null;
   }
 }
  /**
   * Add a ContextService for this module.
   *
   * @param phaseContext the deployment unit context
   * @throws org.jboss.as.server.deployment.DeploymentUnitProcessingException
   */
  public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (isEarDeployment(deploymentUnit)) {
      return;
    }
    final ServiceTarget serviceTarget = phaseContext.getServiceTarget();

    final ServiceName moduleContextServiceName = ContextServiceNameBuilder.module(deploymentUnit);
    final RootContextService contextService = new RootContextService();
    serviceTarget.addService(moduleContextServiceName, contextService).install();

    final BinderService<String> moduleNameBinder =
        new BinderService<String>(
            "ModuleName", Values.immediateValue(getModuleName(deploymentUnit)));
    serviceTarget
        .addService(moduleContextServiceName.append("ModuleName"), moduleNameBinder)
        .addDependency(
            moduleContextServiceName, Context.class, moduleNameBinder.getContextInjector())
        .install();

    final ContextService envContextService = new ContextService("env");
    serviceTarget
        .addService(moduleContextServiceName.append("env"), envContextService)
        .addDependency(
            moduleContextServiceName, Context.class, envContextService.getParentContextInjector())
        .install();

    phaseContext
        .getDeploymentUnit()
        .putAttachment(
            Attachments.MODULE_CONTEXT_CONFIG, new NamingContextConfig(moduleContextServiceName));
  }
  /**
   * Check the deployment annotation index for all classes with the @ManagedBean annotation. For
   * each class with the annotation, collect all the required information to create a managed bean
   * instance, and attach it to the context.
   *
   * @param phaseContext the deployment unit context
   * @throws DeploymentUnitProcessingException
   */
  public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final EEModuleDescription moduleDescription =
        deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
    final String applicationName = moduleDescription.getAppName();
    final CompositeIndex compositeIndex =
        deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
    if (compositeIndex == null) {
      return;
    }
    final List<AnnotationInstance> instances =
        compositeIndex.getAnnotations(MANAGED_BEAN_ANNOTATION_NAME);
    if (instances == null || instances.isEmpty()) {
      return;
    }

    for (AnnotationInstance instance : instances) {
      AnnotationTarget target = instance.target();
      if (!(target instanceof ClassInfo)) {
        throw new DeploymentUnitProcessingException(
            "The ManagedBean annotation is only allowed at the class level: " + target);
      }
      final ClassInfo classInfo = (ClassInfo) target;
      final String beanClassName = classInfo.name().toString();

      // Get the managed bean name from the annotation
      final AnnotationValue nameValue = instance.value();
      final String beanName =
          nameValue == null || nameValue.asString().isEmpty()
              ? beanClassName
              : nameValue.asString();
      final ManagedBeanComponentDescription componentDescription =
          new ManagedBeanComponentDescription(
              beanName, beanClassName, moduleDescription.getModuleName(), applicationName);
      final ServiceName baseName =
          deploymentUnit.getServiceName().append("component").append(beanName);

      // Add the view
      componentDescription.getViewClassNames().add(beanClassName);

      // Bind the view to its two JNDI locations
      // TODO - this should be a bit more elegant
      final BindingDescription moduleBinding = new BindingDescription();
      moduleBinding.setAbsoluteBinding(true);
      moduleBinding.setBindingName("java:module/" + beanName);
      moduleBinding.setBindingType(beanClassName);
      moduleBinding.setReferenceSourceDescription(
          new ServiceBindingSourceDescription(baseName.append("VIEW").append(beanClassName)));
      componentDescription.getBindings().add(moduleBinding);
      final BindingDescription appBinding = new BindingDescription();
      appBinding.setAbsoluteBinding(true);
      appBinding.setBindingName("java:app/" + moduleDescription.getModuleName() + "/" + beanName);
      appBinding.setBindingType(beanClassName);
      appBinding.setReferenceSourceDescription(
          new ServiceBindingSourceDescription(baseName.append("VIEW").append(beanClassName)));
      componentDescription.getBindings().add(appBinding);
      moduleDescription.addComponent(componentDescription);
    }
  }
/** @author Emanuel Muckenhuber */
public final class PlayServices {

  /** The service name of the play framework configuration. */
  public static final ServiceName PLAY = ServiceName.JBOSS.append("play");

  public static final ServiceName PLAY_DEPLOYMENT = PLAY.append("deployment");

  /** internal name for the framework path service name. */
  static final ServiceName PLAY_PATH = PLAY.append("path");
}
 private ServiceName buildServiceName(final Name name) {
   final Enumeration<String> parts = name.getAll();
   ServiceName current = serviceNameBase;
   while (parts.hasMoreElements()) {
     final String currentPart = parts.nextElement();
     if (!currentPart.isEmpty()) {
       current = current.append(currentPart);
     }
   }
   return current;
 }
 @Override
 public ServiceName getServiceName(Deployment dep, int state) {
   // Currently the bundleId is needed for uniqueness because of
   // [MSC-97] Cannot re-install service with same name
   Long bundleId = dep.getAttachment(Long.class);
   ServiceName serviceName =
       ServiceName.of(
           BUNDLE_BASE_NAME, "" + bundleId, "" + dep.getSymbolicName(), "" + dep.getVersion());
   if (state == Bundle.INSTALLED || state == Bundle.RESOLVED || state == Bundle.ACTIVE) {
     serviceName = serviceName.append(ConstantsHelper.bundleState(state));
   }
   return serviceName;
 }
  @Override
  public ServiceBuilder<SessionManagerFactory<TransactionBatch>> build(ServiceTarget target) {
    ServiceName templateCacheServiceName = getCacheServiceName(this.configuration.getCacheName());
    String templateCacheName = templateCacheServiceName.getSimpleName();
    String containerName = templateCacheServiceName.getParent().getSimpleName();
    String cacheName = this.configuration.getDeploymentName();

    new TemplateConfigurationBuilder(containerName, cacheName, templateCacheName)
        .build(target)
        .install();

    new CacheBuilder<>(containerName, cacheName)
        .build(target)
        .addAliases(InfinispanRouteLocatorBuilder.getCacheServiceAlias(cacheName))
        .install();

    new AliasServiceBuilder<>(
            InfinispanRouteLocatorBuilder.getNodeFactoryServiceAlias(cacheName),
            CacheGroupServiceName.NODE_FACTORY.getServiceName(
                containerName, RouteCacheGroupBuilderProvider.CACHE_NAME),
            NodeFactory.class)
        .build(target)
        .install();
    new AliasServiceBuilder<>(
            InfinispanRouteLocatorBuilder.getRegistryServiceAlias(cacheName),
            CacheGroupServiceName.REGISTRY.getServiceName(
                containerName, RouteCacheGroupBuilderProvider.CACHE_NAME),
            Registry.class)
        .build(target)
        .install();

    return target
        .addService(this.getServiceName(), new ValueService<>(this))
        .addDependency(
            CacheServiceName.CACHE.getServiceName(containerName, cacheName),
            Cache.class,
            this.cache)
        .addDependency(
            CacheContainerServiceName.AFFINITY.getServiceName(containerName),
            KeyAffinityServiceFactory.class,
            this.affinityFactory)
        .addDependency(
            GroupServiceName.COMMAND_DISPATCHER.getServiceName(containerName),
            CommandDispatcherFactory.class,
            this.dispatcherFactory)
        .addDependency(
            InfinispanRouteLocatorBuilder.getNodeFactoryServiceAlias(cacheName),
            NodeFactory.class,
            this.nodeFactory)
        .setInitialMode(ServiceController.Mode.ON_DEMAND);
  }
Exemplo n.º 10
0
  private Name suffix(ServiceName parent, ServiceName child) {
    String[] p = parent.toArray();
    String[] c = child.toArray();

    CompositeName name = new CompositeName();
    for (int i = p.length; i < c.length; i++) {
      try {
        name.add(c[i]);
      } catch (InvalidNameException e) {
        throw new IllegalStateException(e);
      }
    }

    return name;
  }
 private static ServiceName installSessionManagerFactory(
     ServiceTarget target,
     ServiceName deploymentServiceName,
     String deploymentName,
     Module module,
     JBossWebMetaData metaData) {
   ServiceName name = deploymentServiceName.append("session");
   if (metaData.getDistributable() != null) {
     DistributableSessionManagerFactoryBuilder sessionManagerFactoryBuilder =
         new DistributableSessionManagerFactoryBuilderValue().getValue();
     if (sessionManagerFactoryBuilder != null) {
       sessionManagerFactoryBuilder
           .build(
               target,
               name,
               new SimpleDistributableSessionManagerConfiguration(
                   metaData, deploymentName, module))
           .setInitialMode(Mode.ON_DEMAND)
           .install();
       return name;
     }
     // Fallback to local session manager if server does not support clustering
     UndertowLogger.ROOT_LOGGER.clusteringNotSupported();
   }
   Integer maxActiveSessions = metaData.getMaxActiveSessions();
   InMemorySessionManagerFactory factory =
       (maxActiveSessions != null)
           ? new InMemorySessionManagerFactory(maxActiveSessions.intValue())
           : new InMemorySessionManagerFactory();
   target
       .addService(name, new ValueService<>(new ImmediateValue<>(factory)))
       .setInitialMode(Mode.ON_DEMAND)
       .install();
   return name;
 }
Exemplo n.º 12
0
 @Override
 public void configureServiceDependencies(ServiceName serviceName, ServiceBuilder<?> builder) {
   if (serviceName.equals(IntegrationServices.SYSTEM_SERVICES_PLUGIN)) {
     builder.addDependency(
         MBeanServerService.SERVICE_NAME, MBeanServer.class, injectedMBeanServer);
   }
 }
  /*
   * In order to test this specific scenario, we use Byteman to insert a monitor in the specific moment
   *  where the transition from STOP_REQUESTED to the next state is going to occur.
   *  This monitor will force the thread to wait until upperCount is incremented to 1.
   */
  @Test
  public void test() throws Exception {
    ServiceName serviceName = ServiceName.of("service");
    TestServiceListener serviceListener = new TestServiceListener();

    // install service as usual
    Future<ServiceController<?>> serviceStart = serviceListener.expectServiceStart(serviceName);
    serviceContainer.addService(serviceName, Service.NULL).addListener(serviceListener).install();
    ServiceController<?> serviceController = assertController(serviceName, serviceStart);

    Future<ServiceController<?>> serviceStopping =
        serviceListener.expectNoServiceStopping(serviceName);
    Future<ServiceController<?>> serviceStop = serviceListener.expectNoServiceStop(serviceName);
    serviceStart = serviceListener.expectNoServiceStart(serviceName);
    // set the mode to NEVER, so that serviceController enters STOP_REQUESTED state
    serviceController.setMode(ServiceController.Mode.NEVER);
    // set the mode to ACTIVE, so that serviceController transitions to UP state
    serviceController.setMode(ServiceController.Mode.ACTIVE);
    // no notifications are expected
    assertNull(serviceStop.get());
    assertNull(serviceStopping.get());
    assertNull(serviceStart.get());
    // service should still be in the up state
    assertSame(ServiceController.State.UP, serviceController.getState());
  }
Exemplo n.º 14
0
 /**
  * @see org.jboss.wsf.spi.ioc.IoCContainerProxy#getBean(java.lang.String, java.lang.Class)
  * @param <T> bean type
  * @param beanName bean name inside IoC registry
  * @param clazz bean type class
  * @return bean instance
  * @throws IllegalArgumentException if bean is not found
  */
 @SuppressWarnings("unchecked")
 public <T> T getBean(final String beanName, final Class<T> clazz) {
   ServiceController<T> service =
       (ServiceController<T>)
           WSServices.getContainerRegistry().getService(ServiceName.parse(beanName));
   return service != null ? service.getValue() : null;
 }
  public static void main(String[] args) throws Exception {
    final int totalServiceDefinitions = Integer.parseInt(args[0]);
    final int threadPoolSize = Integer.parseInt(args[1]);

    final ServiceContainer container = ServiceContainer.Factory.create();
    final ThreadPoolExecutor executor =
        new ThreadPoolExecutor(
            threadPoolSize,
            threadPoolSize,
            1000,
            TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<Runnable>());
    container.setExecutor(executor);

    BatchBuilder batch = container.batchBuilder();

    final LatchedFinishListener listener = new LatchedFinishListener();

    final Value<Field> testFieldValue =
        new CachedValue<Field>(
            new LookupFieldValue(new ImmediateValue<Class<?>>(TestObject.class), "test"));

    final List<Value<Class<?>>> params =
        Collections.singletonList((Value<Class<?>>) new ImmediateValue<Class<?>>(TestObject.class));
    final List<Value<Method>> setterMethodValues = new ArrayList<Value<Method>>(5);
    for (int i = 0; i < 5; i++)
      setterMethodValues.add(
          new CachedValue<Method>(
              new LookupMethodValue(
                  new ImmediateValue<Class<?>>(TestObject.class), "setOther" + (i), params)));

    for (int i = 0; i < totalServiceDefinitions; i++) {
      final TestObject testObject = new TestObject("test" + i);
      final TestObjectService service = new TestObjectService(testObject);
      final ServiceBuilder<TestObject> builder =
          batch.addService(ServiceName.of(("test" + i).intern()), service).addListener(listener);

      final Object injectedValue = new Object();
      //            builder.addInjection(injectedValue).toFieldValue(testFieldValue);

      int nextDivByFive = (5 - (i % 5)) + i;
      int numDeps = Math.min(nextDivByFive - i, totalServiceDefinitions - i - 1);
      for (int j = 0; j < numDeps; j++) {
        int depId = i + j + 1;
        if (depId % 5 == 0) continue;

        //                builder.addDependency(ServiceName.of(("test" +
        // depId).intern())).toMethodValue(setterMethodValues.get(j),
        // Collections.singletonList(Values.injectedValue()));
      }
    }

    batch.install();
    listener.await();
    System.out.println(totalServiceDefinitions + " : " + listener.getElapsedTime() / 1000.0);
    container.shutdown();
    executor.shutdown();
  }
  @Override
  public void deploy(DeploymentPhaseContext context) {

    DeploymentUnit unit = context.getDeploymentUnit();
    final ServiceName name = unit.getServiceName();
    EEModuleDescription moduleDescription = unit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    if (moduleDescription == null) {
      return;
    }

    final ServiceTarget target = context.getServiceTarget();
    @SuppressWarnings("rawtypes")
    final InjectedValue<CacheFactoryBuilderRegistry> registry = new InjectedValue<>();
    Service<Void> service =
        new AbstractService<Void>() {
          @Override
          public void start(StartContext context) {
            // Install dependencies for each registered cache factory builder
            Collection<CacheFactoryBuilder<?, ?>> builders = registry.getValue().getBuilders();
            for (CacheFactoryBuilder<?, ?> builder : builders) {
              builder.installDeploymentUnitDependencies(target, name);
            }
          }
        };
    target
        .addService(name.append("cache-dependencies-installer"), service)
        .addDependency(
            CacheFactoryBuilderRegistryService.SERVICE_NAME,
            CacheFactoryBuilderRegistry.class,
            registry)
        .install();

    // Install versioned marshalling configuration
    InjectedValue<ModuleDeployment> deployment = new InjectedValue<>();
    Module module = unit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    Value<ModuleLoader> moduleLoader = new ImmediateValue<>(module.getModuleLoader());
    target
        .addService(
            VersionedMarshallingConfigurationService.getServiceName(name),
            new VersionedMarshallingConfigurationService(deployment, moduleLoader))
        .addDependency(
            name.append(ModuleDeployment.SERVICE_NAME), ModuleDeployment.class, deployment)
        .setInitialMode(ServiceController.Mode.ON_DEMAND)
        .install();
  }
Exemplo n.º 17
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;
 }
Exemplo n.º 18
0
 public static ServiceName dsListenerServiceName(String vdbName, int version, String name)
     throws InvalidServiceNameException {
   try {
     return ServiceName.of(
         DS_LISTENER_BASE, vdbName, String.valueOf(version), VDBStatusChecker.stripContext(name));
   } catch (RuntimeException e) {
     throw new InvalidServiceNameException(
         IntegrationPlugin.Event.TEIID50099,
         e,
         IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50099, name, vdbName, version));
   }
 }
Exemplo n.º 19
0
 public List<Binding> listBindings(final Name name) throws NamingException {
   final ServiceName lookupName = buildServiceName(name);
   final ServiceName floor = boundServices.floor(lookupName);
   if (floor != null && floor.isParentOf(lookupName)) {
     // Parent might be a reference or a link
     Object obj = lookup(name.toString(), floor);
     if (obj != null) throw new RequireResolveException(convert(floor));
   }
   final List<ServiceName> children = listChildren(lookupName);
   final String[] lookupParts = lookupName.toArray();
   final Set<String> childContexts = new HashSet<String>();
   final List<Binding> results = new ArrayList<Binding>();
   for (ServiceName child : children) {
     final String[] childParts = child.toArray();
     if (childParts.length > lookupParts.length + 1) {
       childContexts.add(childParts[lookupParts.length]);
     } else {
       final Object binding = lookup(name.toString(), child);
       results.add(new Binding(childParts[childParts.length - 1], binding));
     }
   }
   for (String contextName : childContexts) {
     results.add(
         new Binding(
             contextName, new NamingContext(((Name) name.clone()).add(contextName), this, null)));
   }
   return results;
 }
Exemplo n.º 20
0
  /**
   * Create a new controller with the passed in operations.
   *
   * @param additionalInit Additional initialization that should be done to the parsers, controller
   *     and service container before initializing our extension
   * @param bootOperations the operations
   */
  protected KernelServices installInController(
      AdditionalInitialization additionalInit, List<ModelNode> bootOperations) throws Exception {
    if (additionalInit == null) {
      additionalInit = new AdditionalInitialization();
    }
    ControllerInitializer controllerInitializer = additionalInit.createControllerInitializer();
    additionalInit.setupController(controllerInitializer);

    // Initialize the controller
    ServiceContainer container =
        ServiceContainer.Factory.create("test" + counter.incrementAndGet());
    ServiceTarget target = container.subTarget();
    ControlledProcessState processState = new ControlledProcessState(true);
    List<ModelNode> extraOps = controllerInitializer.initializeBootOperations();
    List<ModelNode> allOps = new ArrayList<ModelNode>();
    if (extraOps != null) {
      allOps.addAll(extraOps);
    }
    allOps.addAll(bootOperations);
    StringConfigurationPersister persister = new StringConfigurationPersister(allOps, testParser);
    ModelControllerService svc =
        new ModelControllerService(
            additionalInit.getType(),
            mainExtension,
            controllerInitializer,
            additionalInit,
            processState,
            persister,
            additionalInit.isValidateOperations());
    ServiceBuilder<ModelController> builder =
        target.addService(ServiceName.of("ModelController"), svc);
    builder.install();

    additionalInit.addExtraServices(target);

    // sharedState = svc.state;
    svc.latch.await();
    ModelController controller = svc.getValue();
    ModelNode setup = Util.getEmptyOperation("setup", new ModelNode());
    controller.execute(setup, null, null, null);
    processState.setRunning();

    KernelServices kernelServices =
        new KernelServices(
            container, controller, persister, new OperationValidator(svc.rootRegistration));
    this.kernelServices.add(kernelServices);
    if (svc.error != null) {
      throw svc.error;
    }

    return kernelServices;
  }
Exemplo n.º 21
0
  private Name convert(ServiceName serviceName) {
    String[] c = serviceName.toArray();
    CompositeName name = new CompositeName();
    for (int i = 0; i < c.length; i++) {
      try {
        name.add(c[i]);
      } catch (InvalidNameException e) {
        throw new IllegalStateException(e);
      }
    }

    return name;
  }
Exemplo n.º 22
0
public class ServicesServices {

  private ServicesServices() {}

  public static final ServiceName TORQUEBOX = ServiceName.of("torquebox");
  public static final ServiceName SERVICES = TORQUEBOX.append("services");

  public static ServiceName serviceComponentResolver(DeploymentUnit unit, String serviceName) {
    return unit.getServiceName().append("component_resolver").append(serviceName);
  }

  public static ServiceName serviceCreateRubyService(DeploymentUnit unit, String serviceName) {
    return unit.getServiceName().append("service").append(serviceName).append("create");
  }

  public static ServiceName serviceStartRubyService(DeploymentUnit unit, String serviceName) {
    return unit.getServiceName().append("service").append(serviceName);
  }

  public static ServiceName serviceInjectableService(DeploymentUnit unit, String serviceName) {
    return serviceStartRubyService(unit, serviceName).append("injectable");
  }
}
Exemplo n.º 23
0
  public Object lookup(final Name name) throws NamingException {
    if (name.isEmpty()) {
      return new NamingContext(EMPTY_NAME, this, null);
    }
    final ServiceName lookupName = buildServiceName(name);
    Object obj = lookup(name.toString(), lookupName);
    if (obj == null) {
      final ServiceName lower = boundServices.lower(lookupName);
      if (lower != null && lower.isParentOf(lookupName)) {
        // Parent might be a reference or a link
        obj = lookup(name.toString(), lower);
        checkReferenceForContinuation(name, obj);
        return new ResolveResult(obj, suffix(lower, lookupName));
      }

      final ServiceName ceiling = boundServices.ceiling(lookupName);
      if (ceiling != null && lookupName.isParentOf(ceiling)) {
        return new NamingContext((Name) name.clone(), this, null);
      }
      throw new NameNotFoundException(name.toString() + " -- " + lookupName);
    }

    return obj;
  }
Exemplo n.º 24
0
 private static void install(
     ServiceTarget target, SingletonServiceBuilderFactory factory, ServiceName name, int quorum) {
   InjectedValue<Group> group = new InjectedValue<>();
   NodeService service = new NodeService(group);
   factory
       .createSingletonServiceBuilder(name, service)
       .electionPolicy(
           new PreferredSingletonElectionPolicy(
               new SimpleSingletonElectionPolicy(), new NamePreference(PREFERRED_NODE)))
       .requireQuorum(quorum)
       .build(target)
       .addDependency(
           ServiceName.parse("org.wildfly.clustering.default-group"), Group.class, group)
       .install();
 }
 private static ServiceName getCacheServiceName(String cacheName) {
   ServiceName baseServiceName =
       CacheContainerServiceName.CACHE_CONTAINER
           .getServiceName(DEFAULT_CACHE_CONTAINER)
           .getParent();
   ServiceName serviceName =
       ServiceName.parse((cacheName != null) ? cacheName : DEFAULT_CACHE_CONTAINER);
   if (!baseServiceName.isParentOf(serviceName)) {
     serviceName = baseServiceName.append(serviceName);
   }
   return (serviceName.length() < 4)
       ? serviceName.append(SubGroupServiceNameFactory.DEFAULT_SUB_GROUP)
       : serviceName;
 }
Exemplo n.º 26
0
 private List<ServiceName> listChildren(final ServiceName name) throws NamingException {
   final ConcurrentSkipListSet<ServiceName> boundServices = this.boundServices;
   if (boundServices.contains(name)) {
     throw MESSAGES.cannotListNonContextBinding();
   }
   final NavigableSet<ServiceName> tail = boundServices.tailSet(name);
   final List<ServiceName> children = new ArrayList<ServiceName>();
   for (ServiceName next : tail) {
     if (name.isParentOf(next)) {
       children.add(next);
     } else {
       break;
     }
   }
   return children;
 }
  private void bindServices(
      DeploymentUnit deploymentUnit, ServiceTarget serviceTarget, ServiceName contextServiceName) {

    final ServiceName instanceNameServiceName = contextServiceName.append("InstanceName");
    final BinderService instanceNameService = new BinderService("InstanceName");
    serviceTarget
        .addService(instanceNameServiceName, instanceNameService)
        .addDependency(
            contextServiceName,
            ServiceBasedNamingStore.class,
            instanceNameService.getNamingStoreInjector())
        .addDependency(
            ServerEnvironmentService.SERVICE_NAME,
            ServerEnvironment.class,
            new Injector<ServerEnvironment>() {
              @Override
              public void inject(final ServerEnvironment serverEnvironment)
                  throws InjectionException {
                instanceNameService
                    .getManagedObjectInjector()
                    .inject(
                        new ManagedReferenceFactory() {
                          @Override
                          public ManagedReference getReference() {
                            return new ManagedReference() {
                              @Override
                              public void release() {}

                              @Override
                              public Object getInstance() {
                                final String nodeName = serverEnvironment.getNodeName();
                                return nodeName == null ? "" : nodeName;
                              }
                            };
                          }
                        });
              }

              @Override
              public void uninject() {
                instanceNameService.getManagedObjectInjector().uninject();
              }
            })
        .install();
    deploymentUnit.addToAttachmentList(
        org.jboss.as.server.deployment.Attachments.JNDI_DEPENDENCIES, instanceNameServiceName);
  }
/** @author <a href="*****@*****.**">Kabir Khan</a> */
public class SocketBindingUserService implements Service<SocketBindingUserService> {

  public static final ServiceName NAME = ServiceName.of("test", "binding", "user");
  public final InjectedValue<SocketBinding> socketBindingValue = new InjectedValue<SocketBinding>();

  @Override
  public SocketBindingUserService getValue()
      throws IllegalStateException, IllegalArgumentException {
    return this;
  }

  @Override
  public void start(StartContext arg0) throws StartException {}

  @Override
  public void stop(StopContext arg0) {}
}
Exemplo n.º 29
0
 @Override
 public void activate(ServiceActivatorContext context) {
   ServiceTarget target = context.getServiceTarget();
   try {
     SingletonServiceBuilderFactory factory =
         (SingletonServiceBuilderFactory)
             context
                 .getServiceRegistry()
                 .getRequiredService(
                     ServiceName.parse(
                         SingletonDefaultCacheRequirement.SINGLETON_SERVICE_BUILDER_FACTORY
                             .resolve(CONTAINER_NAME)))
                 .awaitValue();
     install(target, factory, DEFAULT_SERVICE_NAME, 1);
     install(target, factory, QUORUM_SERVICE_NAME, 2);
   } catch (InterruptedException e) {
     throw new ServiceRegistryException(e);
   }
 }
 private void bindBeanManager(
     ServiceTarget serviceTarget,
     ServiceName beanManagerServiceName,
     ServiceName contextServiceName,
     final Collection<ServiceName> dependencies,
     final ServiceRegistry serviceRegistry) {
   final ServiceName beanManagerBindingServiceName = contextServiceName.append("BeanManager");
   dependencies.add(beanManagerBindingServiceName);
   BinderService beanManagerBindingService = new BinderService("BeanManager");
   final BeanManagerManagedReferenceFactory referenceFactory =
       new BeanManagerManagedReferenceFactory();
   serviceTarget
       .addService(beanManagerBindingServiceName, beanManagerBindingService)
       .addInjection(beanManagerBindingService.getManagedObjectInjector(), referenceFactory)
       .addDependency(
           contextServiceName,
           ServiceBasedNamingStore.class,
           beanManagerBindingService.getNamingStoreInjector())
       .addDependency(beanManagerServiceName, BeanManager.class, referenceFactory.beanManager)
       .install();
 }