[jboss-user] [EJB 3.0 Users] - Re: Client calls Timer only once
Fuchs
do-not-reply at jboss.com
Tue Oct 27 02:43:11 EDT 2009
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
More information about the jboss-user
mailing list