Posts

Showing posts with the label cron

Reading the scheduler value from the properties file

In liferay if we want to schedule,then we  write the enries in the liferay-portlet.xml Here we are hard code the value. What if cronValue is retreving the from the portlet.properties Yes we can reterive the value from the propeties , here is the code snippets, liferay-portlet.xml scheduler entry com.sample.scheduler.SchedulerClass cronValue Create the properties file in the /your-portlet/docroot/WEB-INF/src/ Portlet.properties ##cron value ## cronValue = 0/1 1/1 * 1* Here in liferay-portlet.xml we have set the key  " cronValue " in the element of property-key

Creating the scheduler dynamically in liferay

We can create the scheduler by defining the entries in the liferay-portlet.xml with specfying the only particular entries. what if scheduler what to change based on the user input. so here is the code, String cron = "0 0/1 * 1/1 * ? *"; Portlet portlet = PortletLocalServiceUtil.getPortletById("new_WAR_UserSearchportlet"); Trigger trigger = null; try { trigger = TriggerFactoryUtil.buildTrigger(TriggerType.CRON, Scheduler.class.getName(), Scheduler.class.getName(), new Date(), null, cron); } catch (SchedulerException e) { e.printStackTrace(); } Message message = new Message(); message.put(SchedulerEngine.CONTEXT_PATH, portlet.getContextPath()); message.put(SchedulerEngine.MESSAGE_LISTENER_CLASS_NAME, Scheduler.class.getName()); message.put(SchedulerEngine.PORTLET_ID, portlet.getPortletId()); try { SchedulerEngineUtil.schedule(trigger, StorageType.PERSISTED, "", "liferay/scheduler_dispatch", mes...

Creating scheduler in Liferay

  To create scheduler in liferay is easy just adding an entry in liferay-portal.xml and adding your custom logic in do receive method. 1.Add the following entry in liferay-portlet.xml after icon tag and before instansable tag.    " <scheduler-description> " tag you can give your custom description   " <scheduler-event-listener-class> " tag write your custom class where you write your custom scheduler  logic. " cron trigger class " tag , it identifies at what scheduler runs , here scheduler runs at 12 clock at sunday.             <scheduler-entry>            <scheduler-description>scheduler entry</scheduler-description>              <scheduler-event-listener-class>                 com.sample.scheduler.Sch...