Wednesday, November 09, 2011

Basic Scheduler

For a basic scheduler we need following files :
  1. schedular-context.xml
  2. TaskScheduler.java
1.schedular-context.xml

<?xml version='1.0' encoding='UTF-8'?>

<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>

 <bean id="TaskTrigger"

class="org.alfresco.util.CronTriggerBean">

 <property name="jobDetail">

 <bean id="completeTaskTriggerJobDetail"

 class="org.springframework.scheduling.quartz.JobDetailBean">

 <property name="jobClass">

 <value>

 org.alfresco.repo.importer.ImporterJob

 </value>

 </property>

 <property name="jobDataAsMap">

 <map>

 <entry key="bean">

 <ref bean="TaskScheduler" />

 </entry>

 </map>

 </property>

 </bean>

 </property>

 <property name="cronExpression">

 <value>0 0/2 * * * ?</value>

 </property>

 <property name="scheduler">

 <ref bean="schedulerFactory" />

 </property>

 </bean>

 <bean id="TaskScheduler" class="com.company.core.scheduler.TaskScheduler"> <property name="serviceRegistry">

 <ref bean="ServiceRegistry" />

 </property>

 </bean>

</beans>
==============================
2.TaskScheduler.java
package com.company.core.scheduler;
import org.alfresco.repo.importer.ImporterJobSPI;
import org.alfresco.service.ServiceRegistry;

public class TaskScheduler implements ImporterJobSPI
{
 ServiceRegistry serviceRegistry;


 public ServiceRegistry getServiceRegistry()
 {
 return serviceRegistry;
 }
 public void setServiceRegistry(ServiceRegistry serviceRegistry)
 {
 this.serviceRegistry = serviceRegistry;
 }
 public void doImport()
 {
 // Do your task here
 }
}
You need to place these two files in tomcat/shared/classes/alfresco/extension
This scheduler runs every 2 minutes.

1 comment: