Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
parth barot
Liferay 6-Scheduler Engine design change...
September 28, 2010 10:38 PM
Answer

parth barot

Rank: Junior Member

Posts: 42

Join Date: April 30, 2010

Recent Posts

Hi all,

This is regarding how Liferay 6 has changed the design of scheduler engine and handling of jobs. This might helpful because its totally different then previous, and i gone through it for my work. I thought of sharing so many of you can check and easily migrate...

In Liferay 5.2.x, we had com.liferay.portal.kernel.job.IntervalJob as a Quartz scheduler job, which needs to be implemented for different jobs we need for Quartz trigger execution.

In Liferay 6, the design pf scheduler engine has been changed and introduced combination with JMS. I have prepared the small class cum collaboration diagram, which can help understanding how we need to make triggers now onwards.

Basically, they made use of messaging with Quartz. The Job class for liferay is now fixed which is com.liferay.portal.scheduler.job.MessageSenderJob .

I have made entry in my blog, please check the link below for full.


http://javalibs.blogspot.com/2010/09/liferay-6-scheduler-engine-design.html

thanks,
Parth.
Sandeep Nair
RE: Liferay 6-Scheduler Engine design change...
September 29, 2010 5:40 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1721

Join Date: November 5, 2008

Recent Posts

Awesome. thanks for sharing
gianluca maranzana
RE: Liferay 6-Scheduler Engine design change...
November 19, 2010 8:07 AM
Answer

gianluca maranzana

Rank: Junior Member

Posts: 26

Join Date: July 30, 2008

Recent Posts

Good and useful, thanks to you.

So I've prepared this "dummy" step-by-step job's migration from 5.x to 6.0:

1) implement your com.liferay.portal.scheduler.job.MessageSenderJob (was com.liferay.portal.kernel.job.IntervalJob)
2) implement your com.liferay.portal.kernel.scheduler.SchedulerEngine (was com.liferay.portal.kernel.job.Scheduler,
that was contain an org.quartz.Scheduler)
3) previously, you put your custom Schedulerxxx.java in liferay-portlet(-ext).xml under <scheduler-class> tag,
now to go live your job class, put a bean in scheduler-spring(-ext).xml (not recommended, see 3-a) )

ALSO take a look to theese points:

2-a) implement a class that uses IntervalTrigger or use the trigger that you prefer, and
instantiate for use in your SchedulerEnginexxx.schedule() call (the one used for IntervalJob was IntervalTrigger...
but CronTrigger it's a good thing too)

3-a) as you can see, in public class QuartzSchedulerEngineImpl implements SchedulerEngine:
1....
2schedulerFactory.initialize(PropsUtil.getProperties("org.quartz.", false));
3...


It Get out jobs from somewhere properties, so you can put simply in portal-ext.properties
your custom scheduler (NOT recommended, for me):
1....
2org.quartz.scheduler.instanceName=QuartzSchedulerEngineInstance
3....


(RECOMMENDED, 'cause this way adds your schedulers to default one..)
Add your custom Job(s) under (don't worry about wrong class path in comment,
the right one is like above: com.liferay.portal.kernel.scheduler.SchedulerEngine):
1
2... #
3    # Input a list of comma delimited class names that implement
4    # com.liferay.portal.kernel.job.Scheduler. These classes allow jobs to be
5    # scheduled on startup. These classes are not associated to any one portlet.
6    #
7    scheduler.classes= com.ext.liferay.portal.kernel.scheduler.SchedulerEnginexxx, ....
Miguel Coxo
RE: Liferay 6-Scheduler Engine design change...
December 29, 2010 11:11 AM
Answer

Miguel Coxo

Rank: New Member

Posts: 16

Join Date: March 1, 2010

Recent Posts

Hello there,

So i was trying to use the scheduler in liferay and i couldn't understand the steps described here. I went to the IRC channel and jhf helped me figure out how to schedule a job in liferay 6.

So here is what you need to do to make a job and schedule it.

First you need to implement your class:

 1
 2package ...;
 3
 4import com.liferay.portal.kernel.messaging.Message;
 5import com.liferay.portal.kernel.messaging.MessageListener;
 6
 7public class IndexJob implements MessageListener {
 8
 9    @Override
10    public void receive(Message arg0) {
11       
12        System.out.println("I'm Running !!!");
13
14    }
15
16}

Then you need to tell liferay to run this job. So you add the following to your liferay-portlet.xml:

 1
 2<liferay-portlet-app>
 3    <portlet>
 4        <portlet-name>Portlet</portlet-name>
 5        <icon>/icon.png</icon>
 6
 7        <scheduler-entry>
 8            <scheduler-event-listener-class>com.schedulers.IndexJob</scheduler-event-listener-class>
 9            <trigger>
10                <simple>
11                    <simple-trigger-value>1</simple-trigger-value>
12                    <time-unit>minute</time-unit>
13                </simple>
14            </trigger>
15        </scheduler-entry>
16...
17</liferay-portlet-app>

From the dtd:


<!--
The time-unit value is the unit of measure for the time specified in
property-key or simple-trigger-value. Valid values for this element are "day",
"hour", "minute", "second", or "week". The default value is "second".
-->

<!--
The simple element specifies an interval trigger for a scheduler.
-->

Note that you need an actual portlet to attach this "scheduler-entry" to. So you also need the portlet.xml:

 1
 2<portlet-app version="2.0">
 3<portlet>
 4        <portlet-name>Portlet</portlet-name>
 5        <display-name>Portlet</display-name>
 6        <portlet-class>PortletClass</portlet-class>
 7...
 8</portlet>
 9</portlet-app>


And when you deploy your portlet it will run the job at the beginning and then periodically according to the time-unit specified.

Thats all =).

Thanks again to jhf for the help.
Binh Thanh Le
RE: Liferay 6-Scheduler Engine design change...
January 10, 2011 4:35 AM
Answer

Binh Thanh Le

Rank: New Member

Posts: 14

Join Date: August 1, 2010

Recent Posts

works like a charm, thanks very much
Than u, Miguel and thank to jhf too.
Khosro Asgharifard
RE: Liferay 6-Scheduler Engine design change...
January 10, 2011 6:27 AM
Answer

Khosro Asgharifard

Rank: New Member

Posts: 3

Join Date: August 29, 2008

Recent Posts

Thanks for sharing.

Khosro.
gianluca maranzana
RE: Liferay 6-Scheduler Engine design change...
April 22, 2011 2:56 AM
Answer

gianluca maranzana

Rank: Junior Member

Posts: 26

Join Date: July 30, 2008

Recent Posts

Miguel Coxo wrote: <<...So i was trying to use the scheduler in liferay and i couldn't understand the steps described here. I went to the IRC channel and jhf helped me figure out how to schedule a job in liferay 6....>>

Opened a Jira ( http://issues.liferay.com/browse/LPS-16714 ): it is (or was) not necessary to have a portlet (or separate war) to schedule a job, but in documentation of 6.0.x using of "scheduler.classes" property is still mentioned (but doesn't work for now).

G.
Neha Goel
RE: Liferay 6-Scheduler Engine design change...
September 27, 2011 9:16 AM
Answer

Neha Goel

Rank: New Member

Posts: 7

Join Date: November 22, 2010

Recent Posts

Hi all,

I am facing problem with job.I made the portlet for job as suggested by you all and it runs fine on my windows machine but when I move to our server that are linux it does not run at all.

I see property in portal-ext which I dont have in my local

scheduler.enables =false


Does it matter?


PLease let me know

Regards
Neha
Jelmer Kuperus
RE: Liferay 6-Scheduler Engine design change...
September 27, 2011 9:58 AM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1192

Join Date: March 10, 2010

Recent Posts

from portal.properties

#
# Set this to false to disable all scheduler classes defined in
# liferay-portlet.xml and in the property "scheduler.classes".
#
scheduler.enabled=true
Philippe CHEIPE
RE: Liferay 6-Scheduler Engine design change...
September 28, 2011 12:09 AM
Answer

Philippe CHEIPE

Rank: Junior Member

Posts: 61

Join Date: August 12, 2010

Recent Posts

Yes it should solve your problem.

If it does not, verify that your job is well registered in the database: in some cases jobs are not well registered at portlet deployment.

In that case, you have to clean the database and redeploy your portlet to solve the problem.
Neha Goel
RE: Liferay 6-Scheduler Engine design change...
September 28, 2011 3:33 AM
Answer

Neha Goel

Rank: New Member

Posts: 7

Join Date: November 22, 2010

Recent Posts

Thanks for your answers.I figured out that we ar eusing MS SQL and the scheduler is not getting initialised and hence it is not working .Do not know it works fine with MySQL


Regards
Neha
Ratheesh Kamoor
RE: Liferay 6-Scheduler Engine design change...
February 28, 2012 3:05 PM
Answer

Ratheesh Kamoor

Rank: New Member

Posts: 2

Join Date: January 31, 2012

Recent Posts

How do I configure this scheduled batch to get hold of SpringContext. I dont want to use FileSystemContext.
I want to load the same web spring resource from WEB-INF
Cristian Serban
RE: Liferay 6-Scheduler Engine design change...
June 19, 2012 12:47 AM
Answer

Cristian Serban

Rank: New Member

Posts: 14

Join Date: September 5, 2011

Recent Posts

hi

did you figure it out how to hold the context in the implemented Scheduler class