Hello,
I am setting up a quartz job to run in the background of my application. I can get the simple job to run just fine until I need to do anything generally conversation scoped in Seam. Here are my files:
@Name( "statusScheduleController" )
@Scope( ScopeType.APPLICATION )
@Startup( depends =
{
"quartzDispatcher"
} )
@AutoCreate
public class StatusScheduleController
{
private QuartzTriggerHandle quartzTriggerHandle;
@In( value = "statusSheduleProcessor")
private StatusScheduleProcessor processor;
private static final String KEY_STATUS_SCHEDULE_CRON_INTERVAL = "status.schedule.cron.interval";
@Create
public void startup()
{
String cronInterval = PropertyUtil.getProperty( KEY_STATUS_SCHEDULE_CRON_INTERVAL );
quartzTriggerHandle = processor.createQuartzTriggerHandle( new Date(), cronInterval );
}
}
@Name("statusScheduleProcessor")
@Scope(ScopeType.APPLICATION)
@AutoCreate
public class StatusScheduleProcessor
{
@Asynchronous
@Transactional
public QuartzTriggerHandle createQuartzTriggerHandle( @Expiration Date when, @IntervalCron String interval )
{
MyEntity ent = new MyEntity();
ent.setProperty("asdf");
EntityManager entityManager = (EntityManager) Component.getInstance("entityManager");
entityManager.persist(ent);
// just return null, seam will intercept and return appropriate QuartzTriggerHandle automatically.
return null;
}
}
Executing the code above throws:
IllegalStateException: No active application scope
This is expected but my question is how do I work around this? How do I work generally done in conversation scoped context from an Application Scope?
Thanks for the help. Sorry if anything is unclear or sounds stupid, I'm new to Seam.