Search in sources :

Example 1 with Context

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);
        }
    }
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) Context(org.glassfish.internal.api.JavaEEContextUtil.Context) DeploymentContext(org.glassfish.api.deployment.DeploymentContext) InitialContext(javax.naming.InitialContext) Application(com.sun.enterprise.deployment.Application)

Example 2 with Context

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;
    };
}
Also used : Context(org.glassfish.internal.api.JavaEEContextUtil.Context) CacheLoaderException(javax.cache.integration.CacheLoaderException) Factory(javax.cache.configuration.Factory) Cleanup(lombok.Cleanup) Map(java.util.Map)

Example 3 with Context

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);
                }
            }
        });
    }
}
Also used : Context(org.glassfish.internal.api.JavaEEContextUtil.Context) InitialContext(javax.naming.InitialContext) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) Serializable(java.io.Serializable) HashSet(java.util.HashSet) Set(java.util.Set) Inbound(fish.payara.micro.cdi.Inbound) Annotation(java.lang.annotation.Annotation) Outbound(fish.payara.micro.cdi.Outbound)

Example 4 with Context

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;
    };
}
Also used : Context(org.glassfish.internal.api.JavaEEContextUtil.Context) Factory(javax.cache.configuration.Factory) Cleanup(lombok.Cleanup) CacheWriter(javax.cache.integration.CacheWriter) Cache(javax.cache.Cache) CacheWriterException(javax.cache.integration.CacheWriterException)

Aggregations

Context (org.glassfish.internal.api.JavaEEContextUtil.Context)4 Factory (javax.cache.configuration.Factory)2 InitialContext (javax.naming.InitialContext)2 Cleanup (lombok.Cleanup)2 Application (com.sun.enterprise.deployment.Application)1 Inbound (fish.payara.micro.cdi.Inbound)1 Outbound (fish.payara.micro.cdi.Outbound)1 Serializable (java.io.Serializable)1 Annotation (java.lang.annotation.Annotation)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 Cache (javax.cache.Cache)1 CacheLoaderException (javax.cache.integration.CacheLoaderException)1 CacheWriter (javax.cache.integration.CacheWriter)1 CacheWriterException (javax.cache.integration.CacheWriterException)1 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)1 DeploymentContext (org.glassfish.api.deployment.DeploymentContext)1 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)1