Ejemplo n.º 1
0
  /** {@inheritDoc} */
  @Override
  public void deploy(final DeploymentPhaseContext phaseContext)
      throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    final ServicesAttachment servicesAttachment =
        deploymentUnit.getAttachment(Attachments.SERVICES);
    if (module != null && servicesAttachment != null) {
      final ModuleClassLoader classLoader = module.getClassLoader();
      final List<String> driverNames =
          servicesAttachment.getServiceImplementations(Driver.class.getName());
      for (String driverClassName : driverNames) {
        try {
          final Class<? extends Driver> driverClass =
              classLoader.loadClass(driverClassName).asSubclass(Driver.class);
          final Constructor<? extends Driver> constructor = driverClass.getConstructor();
          final Driver driver = constructor.newInstance();
          final int majorVersion = driver.getMajorVersion();
          final int minorVersion = driver.getMinorVersion();
          final boolean compliant = driver.jdbcCompliant();
          if (compliant) {
            log.infof(
                "Deploying JDBC-compliant driver %s (version %d.%d)",
                driverClass, Integer.valueOf(majorVersion), Integer.valueOf(minorVersion));
          } else {
            log.infof(
                "Deploying non-JDBC-compliant driver %s (version %d.%d)",
                driverClass, Integer.valueOf(majorVersion), Integer.valueOf(minorVersion));
          }
          String driverName = deploymentUnit.getName();
          InstalledDriver driverMetadata =
              new InstalledDriver(
                  driverName, driverClass.getName(), null, majorVersion, minorVersion, compliant);
          DriverService driverService = new DriverService(driverMetadata, driver);
          phaseContext
              .getServiceTarget()
              .addService(
                  ServiceName.JBOSS.append("jdbc-driver", driverName.replaceAll(".", "_")),
                  driverService)
              .addDependency(
                  ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE,
                  DriverRegistry.class,
                  driverService.getDriverRegistryServiceInjector())
              .setInitialMode(Mode.ACTIVE)
              .install();

        } catch (Exception e) {
          log.warnf("Unable to instantiate driver class \"%s\": %s", driverClassName, e);
        }
      }
    }
  }
  @Override
  public Class<?> loadClassLocal(String className, boolean resolve) {

    List<XPackageRequirement> matchingPatterns = findMatchingPatterns(className);
    if (matchingPatterns.isEmpty()) return null;

    String pathName = className.replace('.', '/') + ".class";
    Module module = findModuleDynamically(pathName, matchingPatterns);
    if (module == null) return null;

    ModuleClassLoader moduleClassLoader = module.getClassLoader();
    try {
      return moduleClassLoader.loadClass(className);
    } catch (ClassNotFoundException ex) {
      log.tracef("Cannot load class [%s] from module: %s", className, module);
      return null;
    }
  }
Ejemplo n.º 3
0
  public Set<Class> getUpdatedClasses(
      final String deploymentName, Map<String, Long> updatedClasses) {

    final ModuleIdentifier moduleId = getModuleIdentifier(deploymentName);
    final ModuleClassLoader loader = loadersByModuleIdentifier.get(moduleId);
    if (loader == null) {
      return Collections.emptySet();
    }
    final Map<String, Long> timestamps = this.timestamps.get(loader);

    final Set<Class> ret = new HashSet<Class>();
    for (Map.Entry<String, Long> entry : updatedClasses.entrySet()) {
      if (timestamps.containsKey(entry.getKey())
          && timestamps.get(entry.getKey()) < entry.getValue()) {
        try {
          ret.add(loader.loadClass(entry.getKey()));
          timestamps.put(entry.getKey(), entry.getValue());
        } catch (ClassNotFoundException e) {
          System.err.println("Could not load class " + entry);
        }
      }
    }
    return ret;
  }
Ejemplo n.º 4
0
  private static StandaloneServer create(
      ModuleLoader moduleLoader, File jbossHomeDir, String bundlePath, String[] cmdargs) {

    setupBundlePath(bundlePath);
    setupVfsModule(moduleLoader);
    setupLoggingSystem(moduleLoader);

    // Embedded Server wants this, too. Seems redundant, but supply it.
    WildFlySecurityManager.setPropertyPrivileged(
        SYSPROP_KEY_JBOSS_HOME_DIR, jbossHomeDir.getAbsolutePath());

    // Load the Embedded Server Module
    final Module embeddedModule;
    try {
      embeddedModule = moduleLoader.loadModule(ModuleIdentifier.create(MODULE_ID_EMBEDDED));
    } catch (final ModuleLoadException mle) {
      throw EmbeddedLogger.ROOT_LOGGER.moduleLoaderError(mle, MODULE_ID_EMBEDDED, moduleLoader);
    }

    // Load the Embedded Server Factory via the modular environment
    final ModuleClassLoader embeddedModuleCL = embeddedModule.getClassLoader();
    final Class<?> embeddedServerFactoryClass;
    final Class<?> standaloneServerClass;
    try {
      embeddedServerFactoryClass =
          embeddedModuleCL.loadClass(EmbeddedStandAloneServerFactory.class.getName());
      standaloneServerClass = embeddedModuleCL.loadClass(StandaloneServer.class.getName());
    } catch (final ClassNotFoundException cnfe) {
      throw EmbeddedLogger.ROOT_LOGGER.cannotLoadEmbeddedServerFactory(
          cnfe, EmbeddedStandAloneServerFactory.class.getName());
    }

    // Get a handle to the method which will create the server
    final Method createServerMethod;
    try {
      createServerMethod =
          embeddedServerFactoryClass.getMethod(
              "create",
              File.class,
              ModuleLoader.class,
              Properties.class,
              Map.class,
              String[].class);
    } catch (final NoSuchMethodException nsme) {
      throw EmbeddedLogger.ROOT_LOGGER.cannotGetReflectiveMethod(
          nsme, "create", embeddedServerFactoryClass.getName());
    }

    // Create the server
    Object standaloneServerImpl;
    try {
      Properties sysprops = WildFlySecurityManager.getSystemPropertiesPrivileged();
      Map<String, String> sysenv = WildFlySecurityManager.getSystemEnvironmentPrivileged();
      String[] args = cmdargs != null ? cmdargs : new String[0];
      standaloneServerImpl =
          createServerMethod.invoke(null, jbossHomeDir, moduleLoader, sysprops, sysenv, args);
    } catch (final InvocationTargetException ite) {
      throw EmbeddedLogger.ROOT_LOGGER.cannotCreateStandaloneServer(
          ite.getCause(), createServerMethod);
    } catch (final IllegalAccessException iae) {
      throw EmbeddedLogger.ROOT_LOGGER.cannotCreateStandaloneServer(iae, createServerMethod);
    }
    return new StandaloneServerIndirection(standaloneServerClass, standaloneServerImpl);
  }