org.infinispan.cdi.CDIDistributedTaskLifecycle Maven / Gradle / Ivy
package org.infinispan.cdi;
import java.util.concurrent.Callable;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.InjectionTarget;
import org.infinispan.Cache;
import org.infinispan.cdi.util.BeanManagerProvider;
import org.infinispan.distexec.spi.DistributedTaskLifecycle;
public class CDIDistributedTaskLifecycle implements
DistributedTaskLifecycle {
@Override
@SuppressWarnings({ "unchecked" })
public void onPreExecute(Callable task, Cache inputCache) {
BeanManager bm = BeanManagerProvider.getInstance().getBeanManager();
ContextInputCache.set(inputCache);
Class> clazz = (Class>) task.getClass();
AnnotatedType> type = bm.createAnnotatedType(clazz);
InjectionTarget> it = bm.createInjectionTarget(type);
CreationalContext> ctx = bm.createCreationalContext(null);
it.inject(task, ctx);
it.postConstruct(task);
}
@Override
@SuppressWarnings({ "unchecked" })
public void onPostExecute(Callable task) {
try {
BeanManager bm = BeanManagerProvider.getInstance().getBeanManager();
Class> clazz = (Class>) task.getClass();
AnnotatedType> type = bm.createAnnotatedType(clazz);
InjectionTarget> it = bm.createInjectionTarget(type);
it.preDestroy(task);
it.dispose(task);
} finally {
ContextInputCache.clean();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy