How to use the scheduler service

Create a job class

Create a job class (i.e. DummyJob) in package your.package. This class must extend org.apache.jetspeed.scheduler.ScheduledJob.

import org.apache.jetspeed.scheduler.JobEntry;
import org.apache.jetspeed.scheduler.ScheduledJob;

public class DummyJob extends ScheduledJob {

    public void run(JobEntry arg0) throws Exception {
        System.out.println("executing the dummy job");
    }
}

Create the scheduler config file

Create the config file WEB-INF/conf/scheduler.properties.

jobs=your.package.DummyJob

job.your.package.DummyJob.ID=1
job.your.package.DummyJob.SECOND=1
job.your.package.DummyJob.MINUTE=1
job.your.package.DummyJob.HOUR=-1
job.your.package.DummyJob.WEEKDAY=-1
job.your.package.DummyJob.DAY_OF_MONTH=-1

Executes the DummyJob every minute.

To define more than one job, do it like this:

jobs=your.package.DummyJob1,your.package.DummyJob2

job.your.package.DummyJob1.ID=1
job.your.package.DummyJob1.SECOND=-1
...

job.your.package.DummyJob2.ID=1
job.your.package.DummyJob2.SECOND=-1
...

Create the spring configuration

Create the spring configuration file WEB-INF/assembly/scheduler.xml.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<!--
    Copyright 2004 The Apache Software Foundation
    
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
    
    http://www.apache.org/licenses/LICENSE-2.0
    
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<beans>
    <!-- Scheduler Configuration Implementation -->
    <bean id="scheduler_configuration" class="org.apache.commons.configuration.PropertiesConfiguration">
        <constructor-arg>
            <value>${applicationRoot}/WEB-INF/conf/scheduler.properties</value>
        </constructor-arg>
    </bean>

    <!-- Scheduler Implementation -->
    <bean id="PortalScheduler" 
        class="org.apache.jetspeed.scheduler.MemoryBasedScheduler"
    	init-method="start"
    	destroy-method="stop"
          >
      	<constructor-arg index='0'><ref bean="scheduler_configuration" /></constructor-arg>
	</bean>
</beans>

Rebuild/Restart Jetspeed

You know how.

  • No labels