[jboss-user] [JBoss Seam] - using raiseTimedEvent / TimerSchedule

brian.cole01 do-not-reply at jboss.com
Wed Dec 12 05:40:10 EST 2007


I couldn't find a working example on the forums, so now I've got one, I thought I'd do the right thing and post.
Note: 
1. I'm using a POJO here, and didn't change my components.xml at all. If I was in a EJB component, I guess I could have used the EJB (or quartz?) timer service, but what I have here is all I needed. 
2. Seam 2.0 and JBoss 4.2.2.
3. The event stuff in Seam is great. Thanks Seam people!


  | import java.util.Date;
  |  
  | import javax.ejb.Remove;
  |  
  | import org.jboss.seam.ScopeType;
  | import org.jboss.seam.annotations.Create;
  | import org.jboss.seam.annotations.Name;
  | import org.jboss.seam.annotations.Observer;
  | import org.jboss.seam.annotations.Scope;
  | import org.jboss.seam.annotations.Startup;
  | import org.jboss.seam.annotations.async.Asynchronous;
  | import org.jboss.seam.async.TimerSchedule;
  | import org.jboss.seam.core.Events;
  | import org.jboss.seam.log.Log;
  | import org.jboss.seam.log.Logging;
  |  
  | @Name("scheduleProcessor")
  | @Scope(ScopeType.APPLICATION)
  | @Startup
  | public class ScheduleProcessor {
  |  
  |  private final Log log = Logging.getLog(ScheduleProcessor.class);
  |  
  |  @Create
  |  public void init() {
  |   log.info("init at " + new Date());
  |   Events.instance().raiseEvent("test1");
  |   Events.instance().raiseAsynchronousEvent("test2");
  |   Events.instance().raiseTimedEvent("test3", TimerSchedule.ONCE_IMMEDIATELY);
  |   Events.instance().raiseTimedEvent("test4", new TimerSchedule(3000L, 8000L));  // delay of 3 secs, then run every 8 secs
  |  }
  |   
  |  @Remove
  |  public void remove() {
  |   }
  |  
  |  @Observer("test1")
  |  @Asynchronous
  |  public void test1() {
  |   log.info("test 1");
  |  }
  |  
  |  @Observer("test2")
  |  @Asynchronous
  |  public void test2() {
  |   log.info("test 2");
  |  }
  |  
  |  @Observer("test3")
  |  @Asynchronous
  |  public void test3() {
  |   log.info("test 3");
  |  }
  |  
  |  @Observer("test4")
  |  @Asynchronous
  |  public void test4() {
  |   log.info("test 4");
  |  }
  |  
  | }


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4112213#4112213

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4112213



More information about the jboss-user mailing list