and my @Startup components:
| @Startup(depends="manager")
| @Name("controller")
| @Scope(ScopeType.APPLICATION)
| public class Controller {
|
| @In(create=true)
| private Manager manager;
|
| @Create
| public void create() throws Exception {
| manager.schedule();
| }
| }
|
|
| @Name("manager")
| @Scope(ScopeType.APPLICATION)
| public class Manager {
|
| private static Date MIDNIGHT = null;
|
| @In(create = true)
| Job sendNotificationsToScheduledTasks;
|
| public void schedule() {
| Calendar calendar = GregorianCalendar.getInstance();
| calendar.set(Calendar.HOUR_OF_DAY, 0);
| calendar.set(Calendar.MINUTE, 1);
| calendar.set(Calendar.SECOND, 1);
| MIDNIGHT = calendar.getTime();
| System.out.print(MIDNIGHT);
| sendNotificationsToScheduledTasks.execute(new Date(),
Frequency.EVERY_MINUTE.getInterval());
| }
|
| }
|
| package org.bit.etask.scheduler.job;
|
| import java.util.Date;
| import java.util.List;
|
| import javax.ejb.Stateless;
| import javax.ejb.Timer;
| import javax.persistence.EntityManager;
|
| import org.bit.etask.TaskHelper;
| import org.bit.etask.domain.Task;
| import org.bit.etask.home.ActorHome;
| import org.bit.etask.home.MessageHome;
| import org.bit.etask.home.TaskHome;
| import org.bit.etask.query.TaskList;
| import org.bit.etask.scheduler.Job;
| import org.jboss.seam.annotations.Asynchronous;
| import org.jboss.seam.annotations.In;
| import org.jboss.seam.annotations.Logger;
| import org.jboss.seam.annotations.Name;
| import org.jboss.seam.annotations.Transactional;
| import org.jboss.seam.log.Log;
|
| @Stateless
| @Name("sendNotificationsToScheduledTasks")
| public class SendNotificationsToScheduledTasksBean implements Job {
|
| @In
| Timer timer;
|
| @In
| EntityManager entityManager;
|
| @In(create = true)
| ActorHome actorHome;
|
| @In(create = true)
| TaskHome taskHome;
|
| @In(create = true)
| MessageHome messageHome;
|
| @In(create = true)
| TaskList taskList;
|
| @Logger
| Log log;
|
| @Asynchronous
| @Transactional
| public Timer execute(Date startDate, long interval) {
| log.info("Starting ...");
| List<Task> tasks = taskList.findScheduledTasksToNotifyToday();
| for (Task task : tasks) {
| task.setCurrentActivity(TaskHelper.getLastActivity(task));
| taskHome.setInstance(task);
| messageHome.send();
| }
| log.info("Finished");
| return timer;
| }
|
| }
|
|
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4047738#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...