The Bean class:

  | @Stateless
  | @Remote (CustomerArchivTimerBean.class)
  | public class CustomerArchivTimerBean implements CustomerArchivTimerProxy
  | {
  |    private @Resource SessionContext ctx;
  |    
  |    public void scheduleTimer(Date expiration, Serializable info)
  |    {
  |       System.out.println("Create single action timer [info=" + info + "]");
  |       ctx.getTimerService().createTimer(expiration, info);
  |    }
  |    
  |    public void scheduleTimer(long initialDuration, long intervalDuration, 
Serializable info)
  |    {
  |       System.out.println("Create initial+interval timer [info=" + info + 
"]");
  |       ctx.getTimerService().createTimer(initialDuration, intervalDuration, 
info);
  |    }
  |    
  |    public void cancelTimer(Serializable info)
  |    {
  |       System.out.println("Cancel timer [info=" + info + "]");
  |       Collection<Timer> timers = ctx.getTimerService().getTimers();
  |       for (Timer timer : timers)
  |       {      
  |                  if (timer.getInfo().equals(info))
  |                   {
  |                      System.out.println("Timer[info=" + info + "] found, 
cancelling...");
  |                      timer.cancel();
  |                      System.out.println("Timer[info=" + info + "] 
cancelled");
  |                   }
  |       }
  |       
  |    }
  |    
  |    @Timeout
  |    public void timeoutHandler(Timer timer) throws Exception
  |    {
  |             System.out.println("Received timer event: " + timer.getInfo());
  |             Date date = new Date(System.currentTimeMillis());
  |             System.out.println("Current time is: " + date  + ", origin: 
timeoutHandler");
  |                     cancelTimer("CustomerArchivTimer");
  |     }
  | 
  | }
  | 

The interface of the Bean:

  | public interface CustomerArchivTimerProxy
  | {
  |   
  |    public void scheduleTimer(Date expiration, Serializable info);
  |    
  |    public void scheduleTimer(long initialDuration, long intervalDuration, 
Serializable info); 
  |  
  |    public void cancelTimer(Serializable info);
  |    
  |    public void timeoutHandler(Timer timer) throws Exception;
  | 
  | }
  | 

The client methods are:

  |       public static void main(String[] args) throws Exception
  |       {
  | 
  |               testClusterScheduleIntervalTimer();
  |               System.out.println("Timer scheduled to trigger after 10 
seconds");
  |       }
  |     
  |        public static void testClusterScheduleIntervalTimer() throws 
Exception
  |        {
  |           InitialContext ctx = new InitialContext();
  |           CustomerArchivTimerProxy timer = (CustomerArchivTimerProxy) 
ctx.lookup("CustomerArchivTimerBean/remote");
  |           timer.scheduleTimer(10000, 5000, "CustomerArchivTimer");
  |        }
  | 

The jndi properties:

  | java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
  | java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
  | java.naming.provider.url=localhost
  | 


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

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4262319
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to