use of org.glassfish.internal.api.JavaEEContextUtil.Context in project Payara by payara.
the class ResourceValidator method event.
@Override
public void event(Event event) {
if (event.is(Deployment.AFTER_APPLICATION_CLASSLOADER_CREATION)) {
dc = (DeploymentContext) event.hook();
Application application = dc.getModuleMetaData(Application.class);
DeployCommandParameters commandParams = dc.getCommandParameters(DeployCommandParameters.class);
target = commandParams.target;
if (System.getProperty("deployment.resource.validation", "true").equals("false")) {
deplLogger.log(Level.INFO, SKIP_RESOURCE_VALIDATION);
return;
}
if (application == null) {
return;
}
AppResources appResources = new AppResources();
// Puts all resouces found in the application via annotation or xml into appResources
parseResources(application, appResources);
// Ensure we have a valid component invocation before triggering lookups
String componentId = null;
for (BundleDescriptor bundleDescriptor : application.getBundleDescriptors()) {
if (bundleDescriptor instanceof JndiNameEnvironment) {
componentId = DOLUtils.getComponentEnvId((JndiNameEnvironment) bundleDescriptor);
if (componentId != null) {
break;
}
}
}
contextUtil.setInstanceComponentId(componentId);
try (Context ctx = contextUtil.pushContext()) {
validateResources(application, appResources);
}
}
}
use of org.glassfish.internal.api.JavaEEContextUtil.Context in project Payara by payara.
the class CompleteConfigurationProxy method proxyLoader.
private Factory<CacheLoader<K, V>> proxyLoader(final Factory<CacheLoader<K, V>> fact) {
return new Factory<CacheLoader<K, V>>() {
@Override
public CacheLoader<K, V> create() {
@Cleanup Context ctx = ctxUtil.pushContext();
final CacheLoader<K, V> loader = fact.create();
return new CacheLoaderImpl(loader);
}
class CacheLoaderImpl implements CacheLoader<K, V> {
public CacheLoaderImpl(CacheLoader<K, V> loader) {
this.loader = loader;
}
@Override
public V load(K k) throws CacheLoaderException {
@Cleanup Context context = ctxUtil.pushRequestContext();
return loader.load(k);
}
@Override
public Map<K, V> loadAll(Iterable<? extends K> itrbl) throws CacheLoaderException {
@Cleanup Context context = ctxUtil.pushRequestContext();
return loader.loadAll(itrbl);
}
private final CacheLoader<K, V> loader;
}
private static final long serialVersionUID = 1L;
};
}
use of org.glassfish.internal.api.JavaEEContextUtil.Context in project Payara by payara.
the class ClusteredCDIEventBusImpl method eventReceived.
@Override
public void eventReceived(final PayaraClusteredCDIEvent event) {
// first check if the event is targetted at a specific instance
String instanceName = event.getProperty(INSTANCE_PROPERTY);
if (!(instanceName == null) && !(instanceName.length() == 0)) {
// there is an instance name filter
String[] names = deserializeToArray(instanceName);
boolean forUs = false;
String thisInstance = runtime.getInstanceName();
for (String name : names) {
if (name.equals(thisInstance)) {
forUs = true;
break;
}
}
if (!forUs)
return;
}
try (Context ctx = ctxUtil.pushContext()) {
managedExecutorService.submit(new Runnable() {
@Override
public void run() {
ClassLoader oldCL = Utility.getClassLoader();
try {
Utility.setContextClassLoader(ctxUtil.getInvocationClassLoader());
// create the set of qualifiers for the event
// first add Inbound qualifier with the correct properties
Set<Annotation> qualifiers = new HashSet<>();
Serializable eventPayload = event.getPayload();
Inbound inbound = new Inbound() {
@Override
public String eventName() {
return event.getProperty(EVENT_PROPERTY);
}
@Override
public Class<? extends Annotation> annotationType() {
return Inbound.class;
}
};
qualifiers.add(inbound);
// Now create Qualifiers for the sent event qualifiers
Set<Annotation> receivedQualifiers = event.getQualifiers();
for (Annotation receivedQualifier : receivedQualifiers) {
// strip out OutBound as we don't want it even though it was sent over
if (!(receivedQualifier instanceof Outbound)) {
qualifiers.add(receivedQualifier);
}
}
Annotation[] annotations = qualifiers.toArray(new Annotation[0]);
bm.fireEvent(eventPayload, annotations);
} catch (IOException | ClassNotFoundException ex) {
Logger.getLogger(ClusteredCDIEventBusImpl.class.getName()).log(ex.getCause() instanceof IllegalStateException ? Level.FINE : Level.INFO, "Received Event but could not process it", ex);
} finally {
Utility.setContextClassLoader(oldCL);
}
}
});
}
}
use of org.glassfish.internal.api.JavaEEContextUtil.Context in project Payara by payara.
the class CompleteConfigurationProxy method proxyWriter.
private Factory<CacheWriter<? super K, ? super V>> proxyWriter(final Factory<CacheWriter<? super K, ? super V>> fact) {
return new Factory<CacheWriter<? super K, ? super V>>() {
@Override
public CacheWriter<K, V> create() {
@Cleanup Context ctx = ctxUtil.pushContext();
@SuppressWarnings("unchecked") final CacheWriter<K, V> delegate = (CacheWriter<K, V>) fact.create();
return new CacheWriterImpl(delegate);
}
@RequiredArgsConstructor
class CacheWriterImpl implements CacheWriter<K, V> {
@Override
public void write(Cache.Entry<? extends K, ? extends V> entry) throws CacheWriterException {
@Cleanup Context context = ctxUtil.pushRequestContext();
delegate.write(entry);
}
@Override
public void writeAll(Collection<Cache.Entry<? extends K, ? extends V>> clctn) throws CacheWriterException {
@Cleanup Context context = ctxUtil.pushRequestContext();
delegate.writeAll(clctn);
}
@Override
public void delete(Object o) throws CacheWriterException {
@Cleanup Context context = ctxUtil.pushRequestContext();
delegate.delete(o);
}
@Override
public void deleteAll(Collection<?> clctn) throws CacheWriterException {
@Cleanup Context context = ctxUtil.pushRequestContext();
delegate.deleteAll(clctn);
}
private final CacheWriter<K, V> delegate;
}
private static final long serialVersionUID = 1L;
};
}
Aggregations