You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by ep...@apache.org on 2004/11/02 18:05:57 UTC
cvs commit: jakarta-turbine-fulcrum/quartz/src/test/org/apache/fulcrum/quartz/listener FooListener.java
epugh 2004/11/02 09:05:57
Added: quartz/xdocs index.xml changes.xml navigation.xml
quartz/src/java/org/apache/fulcrum/quartz/impl
DefaultQuartzScheduler.java
quartz/src/test/org/apache/fulcrum/quartz/test
NotSoSimpleJob.java SimpleJob.java
quartz/src/test/org/apache/fulcrum/quartz
DefaultQuartzSchedulerImplTest.java
BaseQuartzTestCase.java SchedulerShutDownTest.java
XStreamTest.java
quartz/src/java/org/apache/fulcrum/quartz/listener/impl
ServiceableJobListenerWrapper.java
quartz/src/test TestRoleConfig.xml TestComponentConfig.xml
quartz project.xml
quartz/src/java/org/apache/fulcrum/quartz/listener
ServiceableJobListener.java
quartz/src/java/org/apache/fulcrum/quartz
QuartzScheduler.java
quartz/src/test/org/apache/fulcrum/quartz/listener
FooListener.java
Log:
Import Avalon wrapper for Quartz.
Revision Changes Path
1.1 jakarta-turbine-fulcrum/quartz/xdocs/index.xml
Index: index.xml
===================================================================
<?xml version="1.0"?>
<document>
<properties>
<title>Quartz Scheduler Component</title>
<author email="epugh@opensourceconnections.com">Eric Pugh</author>
</properties>
<body>
<section name="Overview">
<p>
This Service functions as a wrapper around the Quartz Scheduler
</p>
<p>
It is written for use in any Avalon compatible container.
</p>
</section>
<section name="Configuration">
<p>
First, here is the role configuration.
</p>
<source>
<![CDATA[
<role
name="org.apache.fulcrum.quartz.QuartzService"
shorthand="quartz"
default-class="org.apache.fulcrum.quartz.DefaultQuartzService"/>
]]>
</source>
<p>
And here is the configuration:
</p>
<source>
<![CDATA[
<quartz>
<globalJobListener className="org.apache.fulcrum.quartz.listener.FooListener" />
<jobDetails>
<list>
<org.quartz.JobDetail>
<name>simpleJob</name>
<group>DEFAULT_GROUP</group>
<jobClass>org.apache.fulcrum.quartz.test.SimpleJob</jobClass>
<volatility>false</volatility>
<durability>false</durability>
<shouldRecover>false</shouldRecover>
<jobListeners/>
</org.quartz.JobDetail>
<org.quartz.JobDetail>
<name>notSoSimpleJob</name>
<group>DEFAULT_GROUP</group>
<jobClass>org.apache.fulcrum.quartz.test.NotSoSimpleJob</jobClass>
<volatility>false</volatility>
<durability>false</durability>
<shouldRecover>false</shouldRecover>
<jobListeners/>
</org.quartz.JobDetail>
</list>
</jobDetails>
<triggers>
<list>
<org.quartz.SimpleTrigger>
<name>simpleTrigger</name>
<group>DEFAULT_GROUP</group>
</org.quartz.SimpleTrigger>
<org.quartz.CronTrigger>
<name>cron</name>
<group>OTHER_GROUP</group>
</org.quartz.CronTrigger>
</list>
</triggers>
</quartz>
]]>
</source>
</section>
<section name="Usage">
<p>
Please look at the unit tests.
</p>
</section>
</body>
</document>
1.1 jakarta-turbine-fulcrum/quartz/xdocs/changes.xml
Index: changes.xml
===================================================================
<?xml version="1.0"?>
<document>
<properties>
<title>Fulcrum Quartz</title>
<author email="epugh@opensourceconnections.com">Eric Pugh</author>
</properties>
<body>
<release version="1.0.0" date="">
<action dev="epugh" type="add">
If you provide a jobName and jobGroup for a trigger it will autoschedule
that component.
</action>
<action dev="epugh" type="update">
Removed the component Factory for loading jobdetails and triggers
in favor of xstream
</action>
<action dev="epugh" type="update">
Initial import
</action>
</release>
</body>
</document>
1.1 jakarta-turbine-fulcrum/quartz/xdocs/navigation.xml
Index: navigation.xml
===================================================================
<?xml version="1.0" encoding="ISO-8859-1"?>
<project
name="cache"
href="http://jakarta.apache.org/turbine/fulcrum/cache/">
<body>
<links>
<item name="Turbine"
href="http://jakarta.apache.org/turbine/"/>
<item name="Fulcrum"
href="http://jakarta.apache.org/turbine/fulcrum/"/>
<item name="Quartz"
href="http://www.opensymphony.com/quartz"/>
</links>
<menu name="Overview">
<item name="Main" href="/index.html"/>
</menu>
</body>
</project>
1.1 jakarta-turbine-fulcrum/quartz/src/java/org/apache/fulcrum/quartz/impl/DefaultQuartzScheduler.java
Index: DefaultQuartzScheduler.java
===================================================================
/*
* Copyright 2001-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.
*/
package org.apache.fulcrum.quartz.impl;
//JDK
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfigurationSerializer;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.fulcrum.quartz.QuartzScheduler;
import org.apache.fulcrum.quartz.listener.ServiceableJobListener;
import org.apache.fulcrum.quartz.listener.impl.ServiceableJobListenerWrapper;
import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.JobListener;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.Trigger;
import org.quartz.impl.StdSchedulerFactory;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
/**
* Default implementation of QuartzScheduler
*
* @author <a href="mailto:leandro@ibnetwork.com.br">Leandro Rodrigo Saad Cruz
* </a>
* @author <a href="mailto:epughNOSPAM@opensourceconnections.com">Eric Pugh </a>
*
*/
public class DefaultQuartzScheduler implements QuartzScheduler, Configurable, Serviceable, Disposable, Initializable,
ThreadSafe {
private ServiceableJobListener wrapper;
private ServiceManager manager;
private String globalJobListenerClassName;
protected Log logger = LogFactory.getLog(DefaultQuartzScheduler.class.getName());
private Scheduler scheduler;
private Configuration jobDetailsConf;
private Configuration triggersConf;
private Configuration scheduledJobs;
private Map jobDetailsMap;
private Map triggersMap;
/**
* @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
*/
public void configure(Configuration conf) throws ConfigurationException {
jobDetailsConf = conf.getChild("jobDetails").getChild("list");
triggersConf = conf.getChild("triggers").getChild("list");
scheduledJobs = conf.getChild("scheduledJobs");
Configuration child = conf.getChild("globalJobListener", false);
if (child != null) {
globalJobListenerClassName = conf.getChild("globalJobListener").getAttribute("className");
}
}
/**
* @see org.apache.avalon.framework.component.Composable#compose(org.apache.avalon.framework.component.ComponentManager)
*/
public void service(ServiceManager manager) throws ServiceException {
this.manager = manager;
//factory = (FactoryService) manager.lookup(FactoryService.ROLE);
SchedulerFactory schedFact = new StdSchedulerFactory();
try {
scheduler = schedFact.getScheduler();
} catch (SchedulerException e) {
throw new ServiceException("Error composing scheduler instance", e);
}
}
/**
* @see org.apache.avalon.framework.activity.Initializable#initialize()
*/
public void initialize() throws Exception {
XStream xstream = new XStream(new DomDriver()); // does not require XPP3
// library
DefaultConfigurationSerializer serializer = new DefaultConfigurationSerializer();
try {
String xmlAsString = serializer.serialize(jobDetailsConf);
List jobDetails = (List) xstream.fromXML(xmlAsString);
jobDetailsMap = new HashMap(jobDetails.size());
for (Iterator i = jobDetails.iterator(); i.hasNext();) {
JobDetail jobDetail = (JobDetail) i.next();
jobDetailsMap.put(jobDetail.getFullName(), jobDetail);
}
xmlAsString = serializer.serialize(triggersConf);
List triggers = (List) xstream.fromXML(xmlAsString);
triggersMap = new HashMap(triggers.size());
for (Iterator i = triggers.iterator(); i.hasNext();) {
Trigger trigger = (Trigger) i.next();
triggersMap.put(trigger.getFullName(), trigger);
}
} catch (Exception e) {
throw new ConfigurationException(e.toString());
}
//add jobs to scheduler
for (Iterator iter = jobDetailsMap.keySet().iterator(); iter.hasNext();) {
String key = (String) iter.next();
JobDetail jobDetail = (JobDetail) jobDetailsMap.get(key);
logger.debug("Adding job detail [" + jobDetail + "] to scheduler");
scheduler.addJob(jobDetail, true);
}
//add job Listener
if (globalJobListenerClassName != null) {
JobListener configuredjobListener = (JobListener) Class.forName(globalJobListenerClassName).newInstance();
wrapper = new ServiceableJobListenerWrapper(configuredjobListener);
wrapper.service(manager);
scheduler.addGlobalJobListener(wrapper);
}
//schedule any triggers that have a job associated
for (Iterator iter = triggersMap.keySet().iterator(); iter.hasNext();) {
String key = (String) iter.next();
Trigger trigger = (Trigger) triggersMap.get(key);
if (trigger instanceof CronTrigger) {
if (trigger.getJobGroup() != null & trigger.getJobName() != null) {
logger.debug("Scheduling trigger [" + trigger.getFullName() + "] for job detail ["
+ trigger.getFullJobName() + "] to scheduler");
CronTrigger triggerToSchedule = new CronTrigger(trigger.getName(),trigger.getGroup(),trigger.getJobName(),trigger.getJobGroup(),((CronTrigger)trigger).getCronExpression());
triggerToSchedule.setDescription(trigger.getDescription());
// CronTrigger cronTrigger = new CronTrigger("someTriggerCron", Scheduler.DEFAULT_GROUP,
// "simpleJob","DEFAULT_GROUP" ,"* * * * * ?");
scheduler.scheduleJob(triggerToSchedule);
/* Trigger rightNow = new SimpleTrigger("someTrigger", Scheduler.DEFAULT_GROUP,
"notSoSimpleJob","DEFAULT_GROUP" ,new Date(), null, 0,0L);
scheduler.scheduleJob(rightNow);*/
}
}
}
scheduler.start();
logger.debug("Quartz scheduler started !");
}
/**
* @see org.apache.avalon.framework.activity.Disposable#dispose()
*/
public void dispose() {
try {
scheduler.shutdown();
} catch (SchedulerException e) {
logger.warn("Problem shuting down scheduler ", e);
}
wrapper.dispose();
scheduler = null;
manager = null;
}
/**
* @see org.apache.fulcrum.quartz.QuartzScheduler#getScheduler()
*/
public Scheduler getScheduler() {
return scheduler;
}
/**
* @see org.apache.fulcrum.quartz.QuartzScheduler#getJobDetailsMap()
*/
public Map getJobDetailsMap() {
return jobDetailsMap;
}
/*
* (non-Javadoc)
*
* @see br.com.ibnetwork.xingu.quartzscheduler.QuartzScheduler#getTriggersMap()
*/
public Map getTriggersMap() {
return triggersMap;
}
}
1.1 jakarta-turbine-fulcrum/quartz/src/test/org/apache/fulcrum/quartz/test/NotSoSimpleJob.java
Index: NotSoSimpleJob.java
===================================================================
/*
* Copyright 2001-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.
*/
package org.apache.fulcrum.quartz.test;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
/**
* @author <a href="mailto:leandro@ibnetwork.com.br">Leandro Rodrigo Saad Cruz</a>
*
*/
public class NotSoSimpleJob
implements Job,Serviceable
{
public static boolean executed = false;
public static boolean serviced = false;
private ServiceManager manager;
/**
*
*/
public NotSoSimpleJob()
{
super();
}
/**
* @see org.quartz.Job#execute(org.quartz.JobExecutionContext)
*/
public void execute(JobExecutionContext context)
throws JobExecutionException
{
executed = true;
}
/**
* This method is called by ComposableJobListenerWrapper.jobToBeExecuted
*
* @see org.apache.avalon.framework.component.Composable#compose(org.apache.avalon.framework.component.ComponentManager)
*/
public void service(ServiceManager manager)
throws ServiceException
{
this.manager = manager;
serviced = true;
}
}
1.1 jakarta-turbine-fulcrum/quartz/src/test/org/apache/fulcrum/quartz/test/SimpleJob.java
Index: SimpleJob.java
===================================================================
/*
* Copyright 2001-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.
*/
package org.apache.fulcrum.quartz.test;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
/**
* @author <a href="mailto:leandro@ibnetwork.com.br">Leandro Rodrigo Saad Cruz</a>
*
*/
public class SimpleJob
implements Job
{
public static boolean executed = false;
public static boolean composed = false;
/**
*
*/
public SimpleJob()
{
super();
}
/**
* @see org.quartz.Job#execute(org.quartz.JobExecutionContext)
*/
public void execute(JobExecutionContext context)
throws JobExecutionException
{
executed = true;
}
public static void reset(){
executed=false;
composed=false;
}
}
1.1 jakarta-turbine-fulcrum/quartz/src/test/org/apache/fulcrum/quartz/DefaultQuartzSchedulerImplTest.java
Index: DefaultQuartzSchedulerImplTest.java
===================================================================
/*
* Copyright 2001-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.
*/
package org.apache.fulcrum.quartz;
import java.util.Date;
import java.util.Map;
import org.apache.fulcrum.quartz.test.NotSoSimpleJob;
import org.apache.fulcrum.quartz.test.SimpleJob;
import org.quartz.CronTrigger;
import org.quartz.JobListener;
import org.quartz.Scheduler;
import org.quartz.SimpleTrigger;
import org.quartz.Trigger;
/**
* @author <a href="mailto:leandro@ibnetwork.com.br">Leandro Rodrigo Saad Cruz</a>
* @author <a href="mailto:epughNOSPAM@opensourceconnections.com">Eric Pugh </a>
*/
public class DefaultQuartzSchedulerImplTest extends BaseQuartzTestCase {
public void testGetJobs() throws Exception {
Scheduler sched = quartz.getScheduler();
assertNotNull(sched);
String[] jobNames = sched.getJobNames("DEFAULT_GROUP");
assertEquals(2, jobNames.length);
}
public void testJobListener() throws Exception {
Scheduler sched = quartz.getScheduler();
//ExecutionManager tb conta
assertEquals(2, sched.getGlobalJobListeners().size());
JobListener listener = (JobListener) sched.getGlobalJobListeners().get(1);
assertEquals("Foo", listener.getName());
}
public void testJobExecutionWithManager() throws Exception {
Scheduler sched = quartz.getScheduler();
Trigger rightNow = new SimpleTrigger("someTrigger", Scheduler.DEFAULT_GROUP, "notSoSimpleJob", "DEFAULT_GROUP",
new Date(), null, 0, 0L);
sched.scheduleJob(rightNow);
Thread.sleep(500);
assertTrue(NotSoSimpleJob.executed);
assertTrue(NotSoSimpleJob.serviced);
}
public void testJobExecution() throws Exception {
Scheduler sched = quartz.getScheduler();
Trigger rightNow = new SimpleTrigger("someTrigger", Scheduler.DEFAULT_GROUP, "simpleJob", "DEFAULT_GROUP",
new Date(), null, 0, 0L);
sched.scheduleJob(rightNow);
Thread.sleep(500);
assertTrue(SimpleJob.executed);
//can't compose
assertFalse(SimpleJob.composed);
}
public void testJobExecutionWithCron() throws Exception {
assertFalse(SimpleJob.executed);
Scheduler sched = quartz.getScheduler();
Trigger cronTrigger = new CronTrigger("someTriggerCron", Scheduler.DEFAULT_GROUP, "simpleJob", "DEFAULT_GROUP",
"* * * * * ?");
sched.scheduleJob(cronTrigger);
Thread.sleep(500);
assertTrue(SimpleJob.executed);
//can't compose
assertFalse(SimpleJob.composed);
}
public void testJobDetailMap() {
Map map = quartz.getJobDetailsMap();
assertEquals(2, map.size());
assertTrue(map.containsKey("DEFAULT_GROUP.simpleJob"));
assertTrue(map.containsKey("DEFAULT_GROUP.notSoSimpleJob"));
}
public void testTriggerMap() {
Map map = quartz.getTriggersMap();
assertEquals(2, map.size());
assertTrue(map.containsKey("DEFAULT_GROUP.simpleTrigger"));
SimpleTrigger simpleTrigger = (SimpleTrigger) map.get("DEFAULT_GROUP.simpleTrigger");
assertEquals("DEFAULT_GROUP", simpleTrigger.getGroup());
assertEquals("simpleTrigger", simpleTrigger.getName());
assertTrue(map.containsKey("OTHER_GROUP.cron"));
CronTrigger cronTrigger = (CronTrigger) map.get("OTHER_GROUP.cron");
assertEquals("0 0 12 * * ?", cronTrigger.getCronExpression());
}
public void testPreScheduled() throws Exception {
Trigger triggers[] = quartz.getScheduler().getTriggersOfJob("notSoSimpleJob", "DEFAULT_GROUP");
assertEquals(1, triggers.length);
}
}
1.1 jakarta-turbine-fulcrum/quartz/src/test/org/apache/fulcrum/quartz/BaseQuartzTestCase.java
Index: BaseQuartzTestCase.java
===================================================================
/*
* Copyright 2001-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.
*/
package org.apache.fulcrum.quartz;
import org.apache.fulcrum.quartz.impl.DefaultQuartzScheduler;
import org.apache.fulcrum.quartz.test.SimpleJob;
import org.apache.fulcrum.testcontainer.BaseUnitTest;
/**
* Handle looking up and then the icky cleanup of Quartz.
*
* @author <a href="mailto:epughNOSPAM@opensourceconnections.com">Eric Pugh </a>
*/
public class BaseQuartzTestCase extends BaseUnitTest {
protected QuartzScheduler quartz;
public BaseQuartzTestCase(String arg0) {
super(arg0);
}
public BaseQuartzTestCase() {
super("");
}
public void setUp() throws Exception {
quartz = (QuartzScheduler) lookup(QuartzScheduler.ROLE);
SimpleJob.reset();
}
public void tearDown() {
((DefaultQuartzScheduler)quartz).dispose();
release(QuartzScheduler.ROLE);
SimpleJob.reset();
super.tearDown();
}
}
1.1 jakarta-turbine-fulcrum/quartz/src/test/org/apache/fulcrum/quartz/SchedulerShutDownTest.java
Index: SchedulerShutDownTest.java
===================================================================
/*
* Copyright 2001-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.
*/
package org.apache.fulcrum.quartz;
import java.util.Date;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerListener;
import org.quartz.SimpleTrigger;
import org.quartz.Trigger;
/**
* @author <a href="mailto:leandro@ibnetwork.com.br">Leandro Rodrigo Saad Cruz</a>
* @author <a href="mailto:epughNOSPAM@opensourceconnections.com">Eric Pugh </a>
*
*/
public class SchedulerShutDownTest extends BaseQuartzTestCase implements SchedulerListener {
public void testAddRemoveTrigger() throws Exception {
QuartzScheduler quartz = (QuartzScheduler) lookup(QuartzScheduler.ROLE);
Scheduler sched = quartz.getScheduler();
Trigger someDay = new SimpleTrigger("someTrigger", "someGroup", "simpleJob", "DEFAULT_GROUP", new Date(3000, 1,
1), null, 0, 0L);
sched.scheduleJob(someDay);
Trigger trigger = sched.getTrigger("someTrigger", "someGroup");
assertNotNull(trigger);
sched.unscheduleJob("someTrigger", "someGroup");
trigger = sched.getTrigger("someTrigger", "someGroup");
assertNull(trigger);
}
/*
* (non-Javadoc)
*
* @see org.quartz.SchedulerListener#jobScheduled(org.quartz.Trigger)
*/
public void jobScheduled(Trigger arg0) {
}
/*
* (non-Javadoc)
*
* @see org.quartz.SchedulerListener#jobUnscheduled(java.lang.String,
* java.lang.String)
*/
public void jobUnscheduled(String arg0, String arg1) {
System.out.println("hi");
}
/*
* (non-Javadoc)
*
* @see org.quartz.SchedulerListener#triggerFinalized(org.quartz.Trigger)
*/
public void triggerFinalized(Trigger arg0) {
}
/*
* (non-Javadoc)
*
* @see org.quartz.SchedulerListener#triggersPaused(java.lang.String,
* java.lang.String)
*/
public void triggersPaused(String arg0, String arg1) {
}
/*
* (non-Javadoc)
*
* @see org.quartz.SchedulerListener#triggersResumed(java.lang.String,
* java.lang.String)
*/
public void triggersResumed(String arg0, String arg1) {
}
/*
* (non-Javadoc)
*
* @see org.quartz.SchedulerListener#jobsPaused(java.lang.String,
* java.lang.String)
*/
public void jobsPaused(String arg0, String arg1) {
}
/*
* (non-Javadoc)
*
* @see org.quartz.SchedulerListener#jobsResumed(java.lang.String,
* java.lang.String)
*/
public void jobsResumed(String arg0, String arg1) {
}
/*
* (non-Javadoc)
*
* @see org.quartz.SchedulerListener#schedulerError(java.lang.String,
* org.quartz.SchedulerException)
*/
public void schedulerError(String arg0, SchedulerException arg1) {
}
/*
* (non-Javadoc)
*
* @see org.quartz.SchedulerListener#schedulerShutdown()
*/
public void schedulerShutdown() {
System.out.println("ShutingDown scheduler !");
}
}
1.1 jakarta-turbine-fulcrum/quartz/src/test/org/apache/fulcrum/quartz/XStreamTest.java
Index: XStreamTest.java
===================================================================
/*
* Copyright 2001-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.
*/
package org.apache.fulcrum.quartz;
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
import org.apache.fulcrum.quartz.test.NotSoSimpleJob;
import org.apache.fulcrum.quartz.test.SimpleJob;
import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.SimpleTrigger;
import org.quartz.Trigger;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
/**
* Verify that XStream works properly. Also shows us what the XStream output
* will look like.
*
* @author <a href="mailto:epughNOSPAM@opensourceconnections.com">Eric Pugh</a>
*
*/
public class XStreamTest extends TestCase {
public XStreamTest(String arg0) {
super(arg0);
}
public void testSavingTwoTriggersWXstream() throws Exception
{
List triggers = new ArrayList();
XStream xstream = new XStream(new DomDriver()); // does not require XPP3 library
Trigger st = new SimpleTrigger("bob","jones");
String xml = xstream.toXML(st);
// System.out.println(xml);
SimpleTrigger st2 = (SimpleTrigger)xstream.fromXML(xml);
assertEquals(st,st2);
triggers.add(st2);
CronTrigger st3 = new CronTrigger("cron","jones","jobName","jobGroup","0 0 12 * * ?");
xml = xstream.toXML(st3);
System.out.println(xml);
CronTrigger st4 = (CronTrigger)xstream.fromXML(xml);
assertEquals(st3,st4);
triggers.add(st4);
xml = xstream.toXML(triggers);
//System.out.println(xml);
}
public void testSavingTwoJobsWXstream() throws Exception
{
List jobs = new ArrayList();
XStream xstream = new XStream(new DomDriver()); // does not require XPP3 library
JobDetail st = new JobDetail("bob","jones",SimpleJob.class);
String xml = xstream.toXML(st);
// System.out.println(xml);
JobDetail st2 = (JobDetail)xstream.fromXML(xml);
assertEquals(st.getFullName(),st2.getFullName());
jobs.add(st2);
JobDetail st3 = new JobDetail("bob2","jones2",NotSoSimpleJob.class);
xml = xstream.toXML(st3);
// System.out.println(xml);
JobDetail st4 = (JobDetail)xstream.fromXML(xml);
assertEquals(st3.getFullName(),st4.getFullName());
jobs.add(st4);
xml = xstream.toXML(jobs);
// System.out.println(xml);
}
}
1.1 jakarta-turbine-fulcrum/quartz/src/java/org/apache/fulcrum/quartz/listener/impl/ServiceableJobListenerWrapper.java
Index: ServiceableJobListenerWrapper.java
===================================================================
/*
* Copyright 2001-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.
*/
package org.apache.fulcrum.quartz.listener.impl;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.fulcrum.quartz.listener.ServiceableJobListener;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.JobListener;
/**
* Wrapper for listeners to call compose on job instances that implement Composable
*
* @author <a href="mailto:leandro@ibnetwork.com.br">Leandro Rodrigo Saad Cruz</a>
*
*/
public class ServiceableJobListenerWrapper
implements ServiceableJobListener
{
protected JobListener wrappedListener;
protected Log logger = LogFactory.getLog(ServiceableJobListener.class.getName());
protected ServiceManager manager;
/**
*
*/
public ServiceableJobListenerWrapper(JobListener listener)
{
wrappedListener = listener;
}
public void service(ServiceManager manager)
throws ServiceException
{
this.manager = manager;
}
/* (non-Javadoc)
* @see org.apache.avalon.framework.activity.Disposable#dispose()
*/
public void dispose()
{
manager = null;
logger = null;
}
/**
* Calls getName() on wrappedListener
*
* @see org.quartz.JobListener#getName()
*/
public String getName()
{
return wrappedListener.getName();
}
/**
* Calls compose() on Job instance if it implements Composable
* @see org.quartz.JobListener#jobToBeExecuted(org.quartz.JobExecutionContext)
*/
public void jobToBeExecuted(JobExecutionContext context)
{
Job job = context.getJobInstance();
logger.debug("Job to be executed [" + job+"] Wrapped Listener ["+wrappedListener+"]");
if(job instanceof Serviceable)
{
try
{
((Serviceable)job).service(manager);
}
catch (ServiceException e)
{
logger.error("Error composing Job["+job+"]",e);
}
}
wrappedListener.jobToBeExecuted(context);
}
/* (non-Javadoc)
* @see org.quartz.JobListener#jobWasExecuted(org.quartz.JobExecutionContext, org.quartz.JobExecutionException)
*/
public void jobWasExecuted(
JobExecutionContext context,
JobExecutionException ex)
{
Job job = context.getJobInstance();
logger.debug("Job that was executed [" + job+"] Wrapped Listener ["+wrappedListener+"]");
wrappedListener.jobWasExecuted(context,ex);
}
/* (non-Javadoc)
* @see org.quartz.JobListener#jobExecutionVetoed(org.quartz.JobExecutionContext)
*/
public void jobExecutionVetoed(JobExecutionContext context) {
Job job = context.getJobInstance();
logger.debug("Job that was executed [" + job+"] Wrapped Listener ["+wrappedListener+"]");
wrappedListener.jobExecutionVetoed(context);
}
}
1.1 jakarta-turbine-fulcrum/quartz/src/test/TestRoleConfig.xml
Index: TestRoleConfig.xml
===================================================================
<!-- This configuration file for Avalon components is used for testing the TestComponent -->
<role-list>
<role
name="org.apache.fulcrum.quartz.QuartzScheduler"
shorthand="quartz"
default-class="org.apache.fulcrum.quartz.impl.DefaultQuartzScheduler"/>
</role-list>
1.1 jakarta-turbine-fulcrum/quartz/src/test/TestComponentConfig.xml
Index: TestComponentConfig.xml
===================================================================
<componentConfig>
<quartz>
<globalJobListener className="org.apache.fulcrum.quartz.listener.FooListener" />
<scheduled jobName="simpleJob" jobGroup="DEFAULT_GROUP" triggerName="cron" triggerGroup="OTHER_GROUP"/>
<jobDetails>
<list>
<org.quartz.JobDetail>
<name>simpleJob</name>
<group>DEFAULT_GROUP</group>
<jobClass>org.apache.fulcrum.quartz.test.SimpleJob</jobClass>
<volatility>false</volatility>
<durability>false</durability>
<shouldRecover>false</shouldRecover>
<jobListeners/>
</org.quartz.JobDetail>
<org.quartz.JobDetail>
<name>notSoSimpleJob</name>
<group>DEFAULT_GROUP</group>
<jobClass>org.apache.fulcrum.quartz.test.NotSoSimpleJob</jobClass>
<volatility>false</volatility>
<durability>false</durability>
<shouldRecover>false</shouldRecover>
<jobListeners/>
</org.quartz.JobDetail>
</list>
</jobDetails>
<triggers>
<list>
<org.quartz.CronTrigger>
<name>cron</name>
<group>OTHER_GROUP</group>
<cronExpression>0 0 12 * * ?</cronExpression>
<description>test</description>
<jobName>notSoSimpleJob</jobName>
<jobGroup>DEFAULT_GROUP</jobGroup>
</org.quartz.CronTrigger>
<org.quartz.SimpleTrigger>
<name>simpleTrigger</name>
<group>DEFAULT_GROUP</group>
<description>test</description>
</org.quartz.SimpleTrigger>
</list>
</triggers>
</quartz>
</componentConfig>
1.1 jakarta-turbine-fulcrum/quartz/project.xml
Index: project.xml
===================================================================
<?xml version="1.0"?>
<project>
<extend>${basedir}/../project.xml</extend>
<id>fulcrum-quartz</id>
<name>Fulcrum Quartz Component</name>
<currentVersion>1.0-dev</currentVersion>
<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.0.2</version>
<url>http://xstream.codehaus.org/</url>
</dependency>
<!-- QUARTZ -->
<dependency>
<groupId>opensymphony</groupId>
<artifactId>quartz</artifactId>
<version>1.4.0</version>
</dependency>
<!-- Needed only for testing -->
<dependency>
<groupId>fulcrum</groupId>
<artifactId>fulcrum-testcontainer</artifactId>
<version>1.0.4-dev</version>
</dependency>
<dependency>
<groupId>fulcrum</groupId>
<artifactId>fulcrum-yaafi</artifactId>
<version>1.0.3-dev</version>
</dependency>
</dependencies>
</project>
1.1 jakarta-turbine-fulcrum/quartz/src/java/org/apache/fulcrum/quartz/listener/ServiceableJobListener.java
Index: ServiceableJobListener.java
===================================================================
/*
* Copyright 2001-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.
*/
package org.apache.fulcrum.quartz.listener;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.service.Serviceable;
import org.quartz.JobListener;
/*
* Created on Feb 6, 2004
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
/**
* @author <a href="mailto:leandro@ibnetwork.com.br">Leandro Rodrigo Saad Cruz</a>
*
*/
public interface ServiceableJobListener
extends JobListener,Serviceable,Disposable
{
}
1.1 jakarta-turbine-fulcrum/quartz/src/java/org/apache/fulcrum/quartz/QuartzScheduler.java
Index: QuartzScheduler.java
===================================================================
/*
* Copyright 2001-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.
*/
package org.apache.fulcrum.quartz;
import java.util.Map;
import org.quartz.Scheduler;
/**
* @author <a href="mailto:leandro@ibnetwork.com.br">Leandro Rodrigo Saad Cruz</a>
*
*/
public interface QuartzScheduler
{
/** avalon idion */
public static final String ROLE = QuartzScheduler.class.getName();
Scheduler getScheduler();
/**
* Map containing JobDetail objects. Key is group.name
* @return
*/
Map getJobDetailsMap();
/**
* Map containing Trigger objects. Key is group.name
* @return
*/
Map getTriggersMap();
}
1.1 jakarta-turbine-fulcrum/quartz/src/test/org/apache/fulcrum/quartz/listener/FooListener.java
Index: FooListener.java
===================================================================
/*
* Copyright 2001-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.
*/
package org.apache.fulcrum.quartz.listener;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.JobListener;
/**
* @author <a href="mailto:leandro@ibnetwork.com.br">Leandro Rodrigo Saad Cruz</a>
*
*/
public class FooListener
implements JobListener
{
/* (non-Javadoc)
* @see org.quartz.JobListener#jobExecutionVetoed(org.quartz.JobExecutionContext)
*/
public void jobExecutionVetoed(JobExecutionContext arg0) {
}
/* (non-Javadoc)
* @see org.quartz.JobListener#getName()
*/
public String getName()
{
return "Foo";
}
/* (non-Javadoc)
* @see org.quartz.JobListener#jobToBeExecuted(org.quartz.JobExecutionContext)
*/
public void jobToBeExecuted(JobExecutionContext arg0)
{
//System.out.println("Foo: before");
}
/* (non-Javadoc)
* @see org.quartz.JobListener#jobWasExecuted(org.quartz.JobExecutionContext, org.quartz.JobExecutionException)
*/
public void jobWasExecuted(JobExecutionContext arg0, JobExecutionException arg1)
{
//System.out.println("Foo: after");
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org