Foren

Liferay 6-Scheduler Engine design change...

parth barot, geändert vor 13 Jahren.

Liferay 6-Scheduler Engine design change...

Junior Member Beiträge: 42 Beitrittsdatum: 30.04.10 Neueste Beiträge
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.
thumbnail
Sandeep Nair, geändert vor 13 Jahren.

RE: Liferay 6-Scheduler Engine design change...

Liferay Legend Beiträge: 1744 Beitrittsdatum: 06.11.08 Neueste Beiträge
Awesome. thanks for sharing
gianluca maranzana, geändert vor 13 Jahren.

RE: Liferay 6-Scheduler Engine design change...

Junior Member Beiträge: 26 Beitrittsdatum: 30.07.08 Neueste Beiträge
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:
....
schedulerFactory.initialize(PropsUtil.getProperties("org.quartz.", false));
...


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


(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):

... #
    # Input a list of comma delimited class names that implement
    # com.liferay.portal.kernel.job.Scheduler. These classes allow jobs to be
    # scheduled on startup. These classes are not associated to any one portlet.
    #
    scheduler.classes= com.ext.liferay.portal.kernel.scheduler.SchedulerEnginexxx, ....
Miguel Coxo, geändert vor 13 Jahren.

RE: Liferay 6-Scheduler Engine design change...

New Member Beiträge: 16 Beitrittsdatum: 01.03.10 Neueste Beiträge
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:


package ...;

import com.liferay.portal.kernel.messaging.Message;
import com.liferay.portal.kernel.messaging.MessageListener;

public class IndexJob implements MessageListener {

	@Override
	public void receive(Message arg0) {
		
		System.out.println("I'm Running !!!");

	}

}

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


<liferay-portlet-app>
	<portlet>
		<portlet-name>Portlet</portlet-name>
		<icon>/icon.png</icon>

		<scheduler-entry>
			<scheduler-event-listener-class>com.schedulers.IndexJob</scheduler-event-listener-class>
			<trigger>
				<simple>
					<simple-trigger-value>1</simple-trigger-value>
					<time-unit>minute</time-unit>
				</simple>
			</trigger>
		</scheduler-entry>
...
</portlet></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:


<portlet-app version="2.0">
<portlet>
		<portlet-name>Portlet</portlet-name>
		<display-name>Portlet</display-name>
		<portlet-class>PortletClass</portlet-class>
...
</portlet>
</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.
thumbnail
Binh Thanh Le, geändert vor 13 Jahren.

RE: Liferay 6-Scheduler Engine design change...

New Member Beiträge: 14 Beitrittsdatum: 01.08.10 Neueste Beiträge
works like a charm, thanks very much
Than u, Miguel and thank to jhf too.
gianluca maranzana, geändert vor 13 Jahren.

RE: Liferay 6-Scheduler Engine design change...

Junior Member Beiträge: 26 Beitrittsdatum: 30.07.08 Neueste Beiträge
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, geändert vor 12 Jahren.

RE: Liferay 6-Scheduler Engine design change...

New Member Beiträge: 7 Beitrittsdatum: 22.11.10 Neueste Beiträge
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
thumbnail
jelmer kuperus, geändert vor 12 Jahren.

RE: Liferay 6-Scheduler Engine design change...

Liferay Legend Beiträge: 1191 Beitrittsdatum: 10.03.10 Neueste Beiträge
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
thumbnail
Philippe CHEIPE, geändert vor 12 Jahren.

RE: Liferay 6-Scheduler Engine design change...

Junior Member Beiträge: 61 Beitrittsdatum: 12.08.10 Neueste Beiträge
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, geändert vor 12 Jahren.

RE: Liferay 6-Scheduler Engine design change...

New Member Beiträge: 7 Beitrittsdatum: 22.11.10 Neueste Beiträge
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
Khosro Asgharifard, geändert vor 13 Jahren.

RE: Liferay 6-Scheduler Engine design change...

New Member Beiträge: 3 Beitrittsdatum: 29.08.08 Neueste Beiträge
Thanks for sharing.

Khosro.
Ratheesh Kamoor, geändert vor 12 Jahren.

RE: Liferay 6-Scheduler Engine design change...

New Member Beiträge: 2 Beitrittsdatum: 01.02.12 Neueste Beiträge
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, geändert vor 11 Jahren.

RE: Liferay 6-Scheduler Engine design change...

New Member Beiträge: 14 Beitrittsdatum: 05.09.11 Neueste Beiträge
hi

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