Tuesday 23 August 2016

How to create a schedular in lifery 7

How to create a scheduler in liferay7

Prior to liferay7 we use to create a scheduler using the liferay-portlet.xml entry. But in Liferay 7 we are not having liferay-portlet.xml and hence we need to look into some other option. In Liferay 7 we can create a schedular using the BaseSchedulerEntryMessageListener class.
The baseSchedularEntryMessageListener class will be used to register a scheduler listener, which will in turn utilize the SchedularEngineHelper to register the scheduler.
To create a scheduler in liferay 7 use the following steps.
First create a class in any of the project module previously created.
Register this class as a component using the @Component annotation.
Override the doReceive(Message message) method. This method will actually run the business logic.
To register the scheduler we need to register the scheduler using the @activate annotation. This annotation's method will be called while activating the module and hence this can be used to register the scheduler in SchedularEngineHelper.
Also to deactivate this scheduler we will use the @Deactivate annotation. This will be called when we want to uninstall this module and hence this can be use to unregister this scheduler.
To define a trigger we will be using the class TriggerFactoryUtil. We can create two type of triggers - SIMPLE and CRON. Here we are going to create a simple trigger.



TriggerFactoryUtil.createTrigger(getEventListenerClass(), getEventListenerClass(),5, TimeUnit.SECOND);
The above scheduler will run every 5 seconds.

The complete code for the scheduler is given below. 



For more details on the above topic please go through the below video on my youtube channel.


RELATED POSTS

j\

1 comments:


  1. No matter if some one searches for his essential thing, so he/she desires to be available that in detail, therefore that thing is maintained over here. facebook log in

    ReplyDelete

 

Copyright @ 2016 LiferayRevisited.