use of org.jboss.as.server.deployment.ServicesAttachment in project wildfly by wildfly.
the class DriverProcessor method undeploy.
/**
* {@inheritDoc}
*/
@Override
public void undeploy(final DeploymentUnit context) {
/**
* https://issues.redhat.com/browse/WFLY-14114
*
* This hack allows to deregister all drivers registered by this module. See comments in {@link DriverManagerAdapterProcessor}
*/
final Module module = context.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
final ServicesAttachment servicesAttachment = context.getAttachment(Attachments.SERVICES);
if (module != null && servicesAttachment != null) {
final List<String> driverNames = servicesAttachment.getServiceImplementations(Driver.class.getName());
if (!driverNames.isEmpty()) {
try {
Class<?> driverManagerAdapterClass = module.getClassLoader().loadClass(DriverManagerAdapter.class.getName());
Method getDriversMethod = driverManagerAdapterClass.getDeclaredMethod("getDrivers");
Enumeration<Driver> drivers = (Enumeration<Driver>) getDriversMethod.invoke(null, null);
Method deregisterDriverMethod = driverManagerAdapterClass.getDeclaredMethod("deregisterDriver", Driver.class);
while (drivers.hasMoreElements()) {
Driver driver = drivers.nextElement();
if (driverNames.contains(driver.getClass().getName())) {
deregisterDriverMethod.invoke(null, driver);
}
}
} catch (ClassNotFoundException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
Assert.unreachableCode();
}
}
}
}
use of org.jboss.as.server.deployment.ServicesAttachment in project wildfly by wildfly.
the class DriverProcessor method deploy.
/**
* {@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());
int idx = 0;
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) {
DEPLOYER_JDBC_LOGGER.deployingCompliantJdbcDriver(driverClass, majorVersion, minorVersion);
} else {
DEPLOYER_JDBC_LOGGER.deployingNonCompliantJdbcDriver(driverClass, majorVersion, minorVersion);
}
String driverName = deploymentUnit.getName();
if ((driverName.contains(".") && !driverName.endsWith(".jar")) || driverNames.size() != 1) {
driverName += "_" + driverClassName + "_" + majorVersion + "_" + minorVersion;
}
InstalledDriver driverMetadata = new InstalledDriver(driverName, driverClass.getName(), null, 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();
if (idx == 0 && driverNames.size() != 1) {
// create short name driver service
// reset driverName to the deployment unit name
driverName = deploymentUnit.getName();
driverMetadata = new InstalledDriver(driverName, driverClass.getName(), null, null, majorVersion, minorVersion, compliant);
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();
}
idx++;
} catch (Throwable e) {
DEPLOYER_JDBC_LOGGER.cannotInstantiateDriverClass(driverClassName, e);
}
}
}
}
use of org.jboss.as.server.deployment.ServicesAttachment in project wildfly by wildfly.
the class PersistenceProviderHandler method deploy.
public static void deploy(final DeploymentPhaseContext phaseContext, final Platform platform) 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 deploymentModuleClassLoader = module.getClassLoader();
PersistenceProvider provider;
// collect list of persistence providers packaged with the application
final List<String> providerNames = servicesAttachment.getServiceImplementations(PERSISTENCE_PROVIDER_CLASSNAME);
List<PersistenceProvider> providerList = new ArrayList<PersistenceProvider>();
for (String providerName : providerNames) {
try {
final Class<? extends PersistenceProvider> providerClass = deploymentModuleClassLoader.loadClass(providerName).asSubclass(PersistenceProvider.class);
final Constructor<? extends PersistenceProvider> constructor = providerClass.getConstructor();
provider = constructor.newInstance();
providerList.add(provider);
JpaLogger.ROOT_LOGGER.tracef("deployment %s is using its own copy of %s", deploymentUnit.getName(), providerName);
} catch (Exception e) {
throw JpaLogger.ROOT_LOGGER.cannotDeployApp(e, providerName);
}
}
if (!providerList.isEmpty()) {
final String adapterClass = deploymentUnit.getAttachment(JpaAttachments.ADAPTOR_CLASS_NAME);
PersistenceProviderAdaptor adaptor;
if (adapterClass != null) {
try {
adaptor = (PersistenceProviderAdaptor) deploymentModuleClassLoader.loadClass(adapterClass).newInstance();
adaptor.injectJtaManager(new JtaManagerImpl(deploymentUnit.getAttachment(JpaAttachments.TRANSACTION_SYNCHRONIZATION_REGISTRY)));
adaptor.injectPlatform(platform);
ArrayList<PersistenceProviderAdaptor> adaptorList = new ArrayList<>();
adaptorList.add(adaptor);
PersistenceProviderDeploymentHolder.savePersistenceProviderInDeploymentUnit(deploymentUnit, providerList, adaptorList);
} catch (InstantiationException e) {
throw JpaLogger.ROOT_LOGGER.cannotCreateAdapter(e, adapterClass);
} catch (IllegalAccessException e) {
throw JpaLogger.ROOT_LOGGER.cannotCreateAdapter(e, adapterClass);
} catch (ClassNotFoundException e) {
throw JpaLogger.ROOT_LOGGER.cannotCreateAdapter(e, adapterClass);
}
} else {
// register the provider (no adapter specified)
PersistenceProviderDeploymentHolder.savePersistenceProviderInDeploymentUnit(deploymentUnit, providerList, null);
}
}
}
}
Aggregations