use of org.glassfish.hk2.external.org.objectweb.asm.commons.Method in project Payara by payara.
the class TransactionalInterceptorBase method getTransactionalAnnotation.
private Transactional getTransactionalAnnotation(InvocationContext invocationContext) {
Optional<Transactional> optionalTransactional;
// Try the Weld bindings first. This gives us the *exact* binding which caused this interceptor being called
@SuppressWarnings("unchecked") Set<Annotation> bindings = (Set<Annotation>) invocationContext.getContextData().get("org.jboss.weld.interceptor.bindings");
if (bindings != null) {
optionalTransactional = bindings.stream().filter(annotation -> annotation.annotationType().equals(Transactional.class)).findAny().map(annotation -> Transactional.class.cast(annotation));
if (optionalTransactional.isPresent()) {
return optionalTransactional.get();
}
}
BeanManager beanManager = CDI.current().getBeanManager();
// Failing the Weld binding, check the method first
optionalTransactional = getAnnotation(beanManager, invocationContext.getMethod(), Transactional.class);
if (optionalTransactional.isPresent()) {
return optionalTransactional.get();
}
// If nothing found on the method, check the the bean class
optionalTransactional = getAnnotation(beanManager, invocationContext.getTarget().getClass(), Transactional.class);
if (optionalTransactional.isPresent()) {
return optionalTransactional.get();
}
// find it signals a critical error.
throw new IllegalStateException("@Transactional not found on " + invocationContext.getTarget().getClass());
}
use of org.glassfish.hk2.external.org.objectweb.asm.commons.Method in project Payara by payara.
the class ConfigModularityUtils method getCurrentConfigBeanForDefaultValue.
public <T extends ConfigBeanProxy> T getCurrentConfigBeanForDefaultValue(ConfigBeanDefaultValue defaultValue) throws InvocationTargetException, IllegalAccessException {
// TODO make this method target aware!
Class parentClass = getOwningClassForLocation(defaultValue.getLocation());
Class configBeanClass = getClassForFullName(defaultValue.getConfigBeanClassName());
Method m = findSuitableCollectionGetter(parentClass, configBeanClass);
if (m != null) {
ConfigParser configParser = new ConfigParser(serviceLocator);
// I don't use the GlassFish document here as I don't need persistence
final DomDocument doc = new DomDocument<GlassFishConfigBean>(serviceLocator) {
@Override
public Dom make(final ServiceLocator serviceLocator, XMLStreamReader xmlStreamReader, GlassFishConfigBean dom, ConfigModel configModel) {
// by default, people get the translated view.
return new GlassFishConfigBean(serviceLocator, this, dom, configModel, xmlStreamReader);
}
};
ConfigBeanProxy parent = getOwningObject(defaultValue.getLocation());
ConfigurationPopulator populator = new ConfigurationPopulator(defaultValue.getXmlConfiguration(), doc, parent);
populator.run(configParser);
ConfigBeanProxy configBean = doc.getRoot().createProxy(configBeanClass);
Collection col = (Collection) m.invoke(parent);
return (T) getConfigBeanFromCollection(col, configBean, configBeanClass);
}
return null;
}
use of org.glassfish.hk2.external.org.objectweb.asm.commons.Method in project Payara by payara.
the class ConfigurationParser method parseAndSetConfigBean.
/**
* @param <T> the ConfigBeanProxy type we are looking for
*/
public <T extends ConfigBeanProxy> void parseAndSetConfigBean(List<ConfigBeanDefaultValue> values) {
ConfigParser configParser = new ConfigParser(serviceLocator);
// I don't use the GlassFish document here as I don't need persistence
final DomDocument doc = new DomDocument<GlassFishConfigBean>(serviceLocator) {
@Override
public Dom make(final ServiceLocator serviceLocator, XMLStreamReader xmlStreamReader, GlassFishConfigBean dom, ConfigModel configModel) {
return new GlassFishConfigBean(serviceLocator, this, dom, configModel, xmlStreamReader);
}
};
// the solution is to put the loop into the apply method... But it would be some fine amount of work
for (final ConfigBeanDefaultValue configBeanDefaultValue : values) {
final ConfigBeanProxy parent = configModularityUtils.getOwningObject(configBeanDefaultValue.getLocation());
if (parent == null)
continue;
ConfigurationPopulator populator = null;
if (replaceSystemProperties)
try {
populator = new ConfigurationPopulator(configModularityUtils.replacePropertiesWithCurrentValue(configBeanDefaultValue.getXmlConfiguration(), configBeanDefaultValue), doc, parent);
} catch (Exception e) {
LOG.log(Level.SEVERE, ConfigApiLoggerInfo.CFG_EXT_ADD_FAILED, e);
}
else {
// Check that parent is not null!
populator = new ConfigurationPopulator(configBeanDefaultValue.getXmlConfiguration(), doc, parent);
}
populator.run(configParser);
synchronized (configModularityUtils) {
boolean oldValue = configModularityUtils.isIgnorePersisting();
try {
Class configBeanClass = configModularityUtils.getClassForFullName(configBeanDefaultValue.getConfigBeanClassName());
final ConfigBeanProxy pr = doc.getRoot().createProxy(configBeanClass);
configModularityUtils.setIgnorePersisting(true);
ConfigSupport.apply(new SingleConfigCode<ConfigBeanProxy>() {
public Object run(ConfigBeanProxy param) throws PropertyVetoException, TransactionFailure {
configModularityUtils.setConfigBean(pr, configBeanDefaultValue, param);
return param;
}
}, parent);
} catch (TransactionFailure e) {
LOG.log(Level.SEVERE, ConfigApiLoggerInfo.CFG_EXT_ADD_FAILED, e);
} finally {
configModularityUtils.setIgnorePersisting(oldValue);
}
}
}
}
use of org.glassfish.hk2.external.org.objectweb.asm.commons.Method in project Payara by payara.
the class ApplicationLifecycle method setupContainerInfos.
/**
* set up containers and prepare the sorted ModuleInfos
* @param handler
* @param sniffers
* @param context
* @return
* @throws java.lang.Exception
*/
@Override
public List<EngineInfo> setupContainerInfos(final ArchiveHandler handler, Collection<? extends Sniffer> sniffers, DeploymentContext context) throws Exception {
final ActionReport report = context.getActionReport();
DeploymentTracing tracing = context.getModuleMetaData(DeploymentTracing.class);
Map<Deployer, EngineInfo> containerInfosByDeployers = new LinkedHashMap<Deployer, EngineInfo>();
for (Sniffer sniffer : sniffers) {
if (sniffer.getContainersNames() == null || sniffer.getContainersNames().length == 0) {
report.failure(logger, "no container associated with application of type : " + sniffer.getModuleType(), null);
return null;
}
final String containerName = sniffer.getContainersNames()[0];
if (tracing != null) {
tracing.addContainerMark(DeploymentTracing.ContainerMark.SNIFFER_DONE, containerName);
}
// start all the containers associated with sniffers.
EngineInfo engineInfo = containerRegistry.getContainer(containerName);
if (engineInfo == null) {
// need to synchronize on the registry to not end up starting the same container from
// different threads.
Collection<EngineInfo> containersInfo = null;
synchronized (containerRegistry) {
if (containerRegistry.getContainer(containerName) == null) {
if (tracing != null) {
tracing.addContainerMark(DeploymentTracing.ContainerMark.BEFORE_CONTAINER_SETUP, containerName);
}
containersInfo = setupContainer(sniffer, logger, context);
if (tracing != null) {
tracing.addContainerMark(DeploymentTracing.ContainerMark.AFTER_CONTAINER_SETUP, containerName);
}
if (containersInfo == null || containersInfo.size() == 0) {
String msg = "Cannot start container(s) associated to application of type : " + sniffer.getModuleType();
report.failure(logger, msg, null);
throw new Exception(msg);
}
}
}
// now start all containers, by now, they should be all setup...
if (containersInfo != null && !startContainers(containersInfo, logger, context)) {
final String msg = "Aborting, Failed to start container " + containerName;
report.failure(logger, msg, null);
throw new Exception(msg);
}
}
engineInfo = containerRegistry.getContainer(sniffer.getContainersNames()[0]);
if (tracing != null) {
tracing.addContainerMark(DeploymentTracing.ContainerMark.GOT_CONTAINER, containerName);
}
if (engineInfo == null) {
final String msg = "Aborting, Failed to start container " + containerName;
report.failure(logger, msg, null);
throw new Exception(msg);
}
Deployer deployer = getDeployer(engineInfo);
if (deployer == null) {
if (!startContainers(Collections.singleton(engineInfo), logger, context)) {
final String msg = "Aborting, Failed to start container " + containerName;
report.failure(logger, msg, null);
throw new Exception(msg);
}
deployer = getDeployer(engineInfo);
if (deployer == null) {
report.failure(logger, "Got a null deployer out of the " + engineInfo.getContainer().getClass() + " container, is it annotated with @Service ?");
return null;
}
}
if (tracing != null) {
tracing.addContainerMark(DeploymentTracing.ContainerMark.GOT_DEPLOYER, containerName);
}
containerInfosByDeployers.put(deployer, engineInfo);
}
// all containers that have recognized parts of the application being deployed
// have now been successfully started. Start the deployment process.
List<ApplicationMetaDataProvider> providers = new LinkedList<ApplicationMetaDataProvider>();
providers.addAll(habitat.<ApplicationMetaDataProvider>getAllServices(ApplicationMetaDataProvider.class));
List<EngineInfo> sortedEngineInfos = new ArrayList<EngineInfo>();
Map<Class, ApplicationMetaDataProvider> typeByProvider = new HashMap<Class, ApplicationMetaDataProvider>();
for (ApplicationMetaDataProvider provider : habitat.<ApplicationMetaDataProvider>getAllServices(ApplicationMetaDataProvider.class)) {
if (provider.getMetaData() != null) {
for (Class provided : provider.getMetaData().provides()) {
typeByProvider.put(provided, provider);
}
}
}
// check if everything is provided.
for (ApplicationMetaDataProvider provider : habitat.<ApplicationMetaDataProvider>getAllServices(ApplicationMetaDataProvider.class)) {
if (provider.getMetaData() != null) {
for (Class dependency : provider.getMetaData().requires()) {
if (!typeByProvider.containsKey(dependency)) {
// at this point, I only log problems, because it maybe that what I am deploying now
// will not require this application metadata.
logger.log(Level.WARNING, KernelLoggerInfo.applicationMetaDataProvider, new Object[] { provider, dependency });
}
}
}
}
Map<Class, Deployer> typeByDeployer = new HashMap<Class, Deployer>();
for (Deployer deployer : containerInfosByDeployers.keySet()) {
if (deployer.getMetaData() != null) {
for (Class provided : deployer.getMetaData().provides()) {
typeByDeployer.put(provided, deployer);
}
}
}
for (Deployer deployer : containerInfosByDeployers.keySet()) {
if (deployer.getMetaData() != null) {
for (Class dependency : deployer.getMetaData().requires()) {
if (!typeByDeployer.containsKey(dependency) && !typeByProvider.containsKey(dependency)) {
Service s = deployer.getClass().getAnnotation(Service.class);
String serviceName;
if (s != null && s.name() != null && s.name().length() > 0) {
serviceName = s.name();
} else {
serviceName = deployer.getClass().getSimpleName();
}
report.failure(logger, serviceName + " deployer requires " + dependency + " but no other deployer provides it", null);
return null;
}
}
}
}
// ok everything is satisfied, just a matter of running things in order
List<Deployer> orderedDeployers = new ArrayList<Deployer>();
for (Deployer deployer : containerInfosByDeployers.keySet()) {
if (logger.isLoggable(Level.FINE)) {
logger.fine("Keyed Deployer " + deployer.getClass());
}
loadDeployer(orderedDeployers, deployer, typeByDeployer, typeByProvider, context);
}
// now load metadata from deployers.
for (Deployer deployer : orderedDeployers) {
if (logger.isLoggable(Level.FINE)) {
logger.fine("Ordered Deployer " + deployer.getClass());
}
final MetaData metadata = deployer.getMetaData();
try {
if (metadata != null) {
if (metadata.provides() == null || metadata.provides().length == 0) {
deployer.loadMetaData(null, context);
} else {
for (Class<?> provide : metadata.provides()) {
if (context.getModuleMetaData(provide) == null) {
context.addModuleMetaData(deployer.loadMetaData(provide, context));
} else {
deployer.loadMetaData(null, context);
}
}
}
} else {
deployer.loadMetaData(null, context);
}
} catch (Exception e) {
report.failure(logger, "Exception while invoking " + deployer.getClass() + " prepare method", e);
throw e;
}
sortedEngineInfos.add(containerInfosByDeployers.get(deployer));
}
return sortedEngineInfos;
}
use of org.glassfish.hk2.external.org.objectweb.asm.commons.Method in project Payara by payara.
the class ResourceUtil method getMethodMetaData2.
public static MethodMetaData getMethodMetaData2(Dom parent, ConfigModel childModel, int parameterType) {
MethodMetaData methodMetaData = new MethodMetaData();
List<Class<?>> interfaces = new ArrayList<Class<?>>();
Map<String, ParameterMetaData> params = new HashMap<String, ParameterMetaData>();
try {
Class<? extends ConfigBeanProxy> configBeanProxy = (Class<? extends ConfigBeanProxy>) childModel.classLoaderHolder.loadClass(childModel.targetTypeName);
getInterfaces(configBeanProxy, interfaces);
Set<String> attributeNames = childModel.getAttributeNames();
for (String attributeName : attributeNames) {
String methodName = ResourceUtil.getAttributeMethodName(attributeName);
// camelCase the attributeName before passing out
attributeName = Util.eleminateHypen(attributeName);
ParameterMetaData parameterMetaData = params.get(attributeName);
if (parameterMetaData == null) {
parameterMetaData = new ParameterMetaData();
params.put(attributeName, parameterMetaData);
}
// Check parent interfaces
for (int i = interfaces.size() - 1; i >= 0; i--) {
Class<?> intf = interfaces.get(i);
try {
Method method = intf.getMethod(methodName);
Attribute attribute = method.getAnnotation(Attribute.class);
if (attribute != null) {
ParameterMetaData localParam = ResourceUtil.getParameterMetaData(attribute);
copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.DEFAULT_VALUE);
copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.KEY);
copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.TYPE);
copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.OPTIONAL);
}
} catch (NoSuchMethodException e) {
}
}
// Check ConfigBean
try {
Method method = configBeanProxy.getMethod(methodName);
Attribute attribute = method.getAnnotation(Attribute.class);
if (attribute != null) {
ParameterMetaData localParam = ResourceUtil.getParameterMetaData(attribute);
copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.DEFAULT_VALUE);
copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.KEY);
copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.TYPE);
copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.OPTIONAL);
}
} catch (NoSuchMethodException e) {
}
methodMetaData.putParameterMetaData(attributeName, parameterMetaData);
}
} catch (MultiException cnfe) {
throw new RuntimeException(cnfe);
}
return methodMetaData;
}
Aggregations