littlecowk35 / eic-quan-ly-cong-van

Automatically exported from code.google.com/p/eic-quan-ly-cong-van
0 stars 0 forks source link

How to create a scheduler in Liferay 6.2 #3

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.
2.
3.

What is the expected output? What do you see instead?

Please use labels and text to provide additional information.

Original issue reported on code.google.com by ntanh...@gmail.com on 19 Jul 2014 at 9:03

GoogleCodeExporter commented 9 years ago
http://www.liferay.com/community/forums/-/message_boards/message/32851751

Original comment by ntanh...@gmail.com on 19 Jul 2014 at 9:03

GoogleCodeExporter commented 9 years ago
http://pmkathiria.blogspot.com/2013/06/how-to-write-simplecron-scheduler-in.html

Original comment by ntanh...@gmail.com on 19 Jul 2014 at 9:05

GoogleCodeExporter commented 9 years ago
http://liferayazam.wordpress.com/2012/06/10/create-a-scheduler-in-liferay-6/

Original comment by ntanh...@gmail.com on 19 Jul 2014 at 9:05

GoogleCodeExporter commented 9 years ago
https://www.liferay.com/community/forums/-/message_boards/message/11909972

Original comment by ntanh...@gmail.com on 19 Jul 2014 at 9:07

GoogleCodeExporter commented 9 years ago
http://liferay-blogging.blogspot.com/2011/02/how-to-create-scheduled-job-in-life
ray.html

Original comment by ntanh...@gmail.com on 19 Jul 2014 at 9:08

GoogleCodeExporter commented 9 years ago
http://shashantpanwar.blogspot.com/2013/08/liferay-scheduler-simplecron-setup.ht
ml

Original comment by ntanh...@gmail.com on 19 Jul 2014 at 9:10

GoogleCodeExporter commented 9 years ago
Following these steps to design a portlet using Liferay Scheduler.
The fisrt class will be used to implement to MessageListener class of Liferay 
kernel.
The method receive need to be overide to define the stuff of your job
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.messaging.Message;
import com.liferay.portal.kernel.messaging.MessageListener;
import com.liferay.portal.kernel.messaging.MessageListenerException;

public class DemoJob implements MessageListener{
    private static final Log LOG = LogFactoryUtil.getLog(DemoJob.class);

            @Override
            public void receive(Message message) throws MessageListenerException {
                LOG.info("Scheduled RUNS !!!");
                System.out.println("Run!");
            }
}

Original comment by ntanh...@gmail.com on 30 Jul 2014 at 2:04

GoogleCodeExporter commented 9 years ago
The second part complete with create an SchedulerEntry to set task information 
value and register it with SchedulerEngineUtil
 SchedulerEntry entry = new SchedulerEntryImpl();
             entry.setDescription("Scheduler portlet for incident submission to ITSM" );
             entry.setEventListenerClass(DemoJob.class.getName());
             entry.setTriggerType(TriggerType.CRON);
             //entry.setTriggerValue(1);
             //entry.setTimeUnit(TimeUnit.MINUTE);
             Calendar calendar = Calendar.getInstance(); 
            calendar.setTime(new Date());
            int seconds = 0;
            int minutes = 49;
            int hours = 17;
            int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
            int months = calendar.get(Calendar.MONTH);
            months++;//Month start from 0
            int years = calendar.get(Calendar.YEAR);//getYear return integer value minus 1900
            //Bieu thuc the hien thoi gian thuc hien
            String cronExpression = seconds+" "+minutes+" "+hours+" "+dayOfMonth+" "+months+" ? "+years;
             entry.setTriggerValue(cronExpression);

             try {
                 String portletId = (String) request.getAttribute(WebKeys.PORTLET_ID);
                 System.out.println("Id "+portletId);
             SchedulerEngineUtil.schedule(entry, StorageType.MEMORY,
             portletId, 0);
             } catch (SchedulerException e1) {
             e1.printStackTrace();
             System.out.println("exception");
             }

Original comment by ntanh...@gmail.com on 30 Jul 2014 at 2:05

GoogleCodeExporter commented 9 years ago
The whole source code of portlet on Liferay 6.2

Original comment by ntanh...@gmail.com on 30 Jul 2014 at 2:08

Attachments:

GoogleCodeExporter commented 9 years ago
Cron maker site helps to convert datetime values to cron expression
http://www.cronmaker.com/

Original comment by ntanh...@gmail.com on 30 Jul 2014 at 2:09