I have the flip side of this change available as well.
In this version, activation is done directly from BeanManager instead of the secondary context object. I'm also thinking with this commit that ManagedContext should actually be "UnmanagedContext" to clarify that its not being handled in the container.
PS - One of the use cases I put in the JIRA ticket was around quartz integration. This is what the resulting integration looks like
public class CDIJobListener implements JobListener {
public static final String CONTEXT_NAME = "CDIJobListener.cdi_context";
@Override
public String getName() {
return "cdi";
}
@Override
public void jobToBeExecuted(JobExecutionContext jobExecutionContext) {
BeanManager beanManager = CDI.current().getBeanManager();
ManagedContext requestContext = beanManager.activateContext(RequestScoped.class);
jobExecutionContext.getMergedJobDataMap().put(CONTEXT_NAME, requestContext);
}
@Override
public void jobExecutionVetoed(JobExecutionContext jobExecutionContext) {
ManagedContext managedContext = (ManagedContext)jobExecutionContext.getMergedJobDataMap().get(CONTEXT_NAME);
managedContext.deactivate();
}
@Override
public void jobWasExecuted(JobExecutionContext jobExecutionContext, JobExecutionException e) {
jobExecutionVetoed(jobExecutionContext);
}
}