Monday 10 September 2012

Scheduler in liferay Using cron scheduler



In so many cases we need to execute some again and again after some specific time of the duration. At that time scheduler makes our life easy.
In the liferay the have supporting quartz scheduler and the cron scheduler.

Here is the example to run the quartz scheduler in the lifrray.

First of we need to make the entry into the liferay-portlet.xml

<scheduler-entry>
            <scheduler-event-listener-class>com.aalap.mom.util.DailyTasksCreateScheduler</scheduler-event-listener-class>
            <trigger>
                  <cron>
                    <cron-trigger-value>     0 0/15 * 1/1 * ? *</cron-trigger-value>
                </cron> 
            </trigger>
<scheduler-entry>
In the above example the scheduler going to execute after every 15 mins. Ths site http://www.cronmaker.com . helps to get the expression to run the scheduler at the specific time.

If we want to run the scheduler at some time point like two am in the morning we have to give the expression 0 0 2 1/1 * ? * in the <cron-trigger-value> tag.

In the <scheduler-event-listener-class> we are defining the event listener class which define the logic of the scheduler.
In this we have DailyTasksCreateScheduler we have put our logic to create dailytasks.


public class DailyTasksCreateScheduler implements MessageListener {
    private static Log log = LogFactoryUtil.getLog("com.radisson.mom.util.DailyTasksCreateScheduler");
  
    public void receive(Message paramMessage) throws MessageListenerException {
 NEED TO PUT THE LOIC FOR THE SCHEDULER HERE.
}
}