Creato da pastuweb.com
Share My Page
My Social Accounts
Account FaceBook Account LinkedIn Account Twitter Account Google Plus Account Git Hub
Liferay, because it's a platform, contains functionality for running various jobs on a schedule. You can make these jobs do pretty much anything you want, because they have the same access to all of Liferay's APIs as any other plugin.
 
Depending on the application, there can be any number of use cases that require a scheduler. Liferay's Calendar portlet uses it to send event notifications. Some enterprises use it to import users from other systems. Of course, you can use Liferay's scheduler to run whatever jobs you may need to run on a regular basis.
 
The jobs are MessageListener classes, just like the ones you'd write to receive a message sent across the message bus. All the scheduler does is kick off one of those MessageListener classes on the schedule you define.
 
The schedule is set up declaratively in the liferay-portlet.xml file, in <schedulerentry> tags inside the <portlet> tag:
 
<scheduler-entry>
<scheduler-event-listener-class>
com.appuntivari.scheduler.MyScheduledJobListener
</scheduler-event-listener-class>
<trigger>
<simple>
<simple-trigger-value>1</simple-trigger-value>
<time-unit>day</time-unit>
</simple>
</trigger>
</scheduler-entry>
 
You declare the listener you want to trigger, and how often you want to trigger it.
 
You have the option of using simple values as in this example; or if you're a 1337 Unixhead, you can use <cron> and <cron-trigger-value> tags and specify cron values for the schedule instead of the simple ones. You'll need to do this if you want to set specific times, like midnight on Monday morning.
 
For instance:
 
<trigger>
<cron>
<cron-trigger-value>0 0 18 * * ? *</cron-trigger-value>
</cron>
</trigger>
 
Liferay's scheduler is remarkably easy to use, but it gives you a powerful facility for running jobs at a frequency you define.
 
 
package com.appuntivari.scheduler;
import com.liferay.portal.kernel.messaging.Message;
import com.liferay.portal.kernel.messaging.MessageListener;
import com.liferay.portal.kernel.messaging.MessageListenerException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
 
public class MyScheduledJobListener implements MessageListener
{
private static final Log LOGGER =
LogFactoryUtil.getLog(MyScheduledJobListener.class);
 
/**
* Job that we need to run on scheduler
*/
public void receive(Message arg0) throws MessageListenerException {
 
LOGGER.info("Scheduler: receive()");
//write your logic.
 
}
}