Uploaded image for project: 'Weld'
  1. Weld
  2. WELD-1495

use java ServiceLoader mechanism and/or system property to bootstrap spi

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Done
    • Major
    • 3.0.0.Alpha2, 2.2.7.Final
    • 2.0.3.Final
    • Weld SPI
    • None

    Description

      Weld SPI offer us the mechanism to bootstrap custom Service by overriding it is Deployment. In a Weld SE environment, we would do the following to bootstrap a custom TransactionService:

      weld = new Weld(){
          @Override
          protected Deployment createDeployment(ResourceLoader resourceLoader, Bootstrap bootstrap) {
              Deployment deployment = super.createDeployment(resourceLoader, bootstrap);
              deployment.getServices().add(TransactionServices.class, new InMemoryTransactionServices());
              return deployment;
          }
      };
      

      Though, when using third parties libraries like Arquillian to bootstrap Weld, it is fairly complicated to override the Weld Deployment.

      By looking at the Weld 2.0.3.Final source code, especially the WeldBootstrap class, it would be nice if code would lookup for a well known service or system property to init the services.

      ex, instead of:

      if (!registry.contains(TransactionServices.class)) {
          log.info(JTA_UNAVAILABLE);
      }
      

      we could do something like:

      if (!registry.contains(TransactionServices.class)) {
          // first, lookup for a system property
          TransactionServices transactionServices = System.getProperty("org.jboss.weld.transaction.spi.TransactionServices");
          if (transactionServices != null){
              registry.getServices().add(TransactionServices.class, transactionServices);
          }
          // else, lookup for a service
          else if (ServiceLoader.load(TransactionServices.class).hasNext()) {
              transactionServices = ServiceLoader.load(TransactionServices.class).next();
              registry.getServices().add(TransactionServices.class, transactionServices);
          }
          // then we can safely assume that TransactionServices is really unavailable
          else {
              log.info(JTA_UNAVAILABLE);
          }
      }
      

      By doing so, it would resolve my issue documented in the related forum references.

      Thanks,

      Attachments

        Activity

          People

            rhn-engineering-jharting Jozef Hartinger
            mathieu@mathieulachance.com Mathieu Lachance (Inactive)
            Votes:
            3 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: