Class EjbScheduler

java.lang.Object
io.smint.clapi.consumer.integration.core.services.impl.AbstractScheduler<J2eeSchedulerJobData>
io.smint.clapi.consumer.integration.j2ee.EjbScheduler
All Implemented Interfaces:
io.smint.clapi.consumer.integration.core.services.IPlatformScheduler

@Singleton public class EjbScheduler extends io.smint.clapi.consumer.integration.core.services.impl.AbstractScheduler<J2eeSchedulerJobData> implements io.smint.clapi.consumer.integration.core.services.IPlatformScheduler
Implements a scheduler based on TimerService to be used with Enterprise Java Beans.

This scheduler relies on creation upon startup of the servlet/container. As soon as the instance is created by the container, startup() is called, which stores a reference to this bean to a static variable. Its value can be retrieved with #getSchedulerBean() to acquire access to the scheduler as created by the J2EE container.

See Also:
  • Constructor Details

    • EjbScheduler

      public EjbScheduler()
  • Method Details

    • getSchedulerBean

      public static EjbScheduler getSchedulerBean()
      Returns the singleton scheduler bean as created by the J2EE container and stored with startup().
      Returns:
      the scheduler bean as saved after creation by the J2EE container or null if the bean has not been created yet.
    • startup

      @PostConstruct public void startup()
      Stores a reference to this, which can be retrieved with getSchedulerBean().

      In case a second instance of this class is created, the reference to these additional instances are not stored. Only a singleton is supported.

    • shutdown

      @PreDestroy public void shutdown()
      Cancels all timers.

      With EJB timers are persistent and resurrect in case the application is stopped and started again. This would not work with this class, as the actual code to execute with the timer is stored as Runnable inside a big Map. This data will get lost in application unload from memory. Hence it will not be available upon next start of the application. Therefore there is no use in persistent timers and so all timers are cancelled prior to shutting down the application.

    • timerFired

      public void timerFired(Timer timer)
    • scheduleAtFixedRate

      public String scheduleAtFixedRate(Runnable job, long period)
      Specified by:
      scheduleAtFixedRate in interface io.smint.clapi.consumer.integration.core.services.IPlatformScheduler
    • stopSchedule

      public io.smint.clapi.consumer.integration.core.services.IPlatformScheduler stopSchedule(String jobKey)
      Specified by:
      stopSchedule in interface io.smint.clapi.consumer.integration.core.services.IPlatformScheduler
    • cancel

      public io.smint.clapi.consumer.integration.core.services.IPlatformScheduler cancel()
      Specified by:
      cancel in interface io.smint.clapi.consumer.integration.core.services.IPlatformScheduler
    • scheduleForImmediateExecution

      public io.smint.clapi.consumer.integration.core.services.IPlatformScheduler scheduleForImmediateExecution(Runnable job)
      Specified by:
      scheduleForImmediateExecution in interface io.smint.clapi.consumer.integration.core.services.IPlatformScheduler