RE: Scheduling tasks
Could anyone post some code showing how to implement this? yes, of course: first, the usage example: package ch.bmw.jobscheduler.test; __ import java.util.Date; import junit.framework.TestCase; import org.apache.hivemind.Registry; import org.apache.hivemind.impl.RegistryBuilder; import org.quartz.Job; import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.SchedulerException; import org.quartz.SchedulerFactory; import org.quartz.Trigger; import org.quartz.TriggerUtils; import com.javaforge.honeycomb.RegistryAccessor; public class JobSchedulerServiceTest extends TestCase { private Registry reg; private SchedulerFactory sf; protected void setUp() throws Exception { reg = RegistryBuilder.constructDefaultRegistry(); ((RegistryAccessor)reg.getService(RegistryAccessor.class)) .setRegistry(reg); } public void testSimple() throws SchedulerException, InterruptedException { Scheduler s = (Scheduler) reg.getService( Scheduler.class ); JobDetail jobDetail = new JobDetail(myJob, null, Job.class, true, false, false ); Trigger trigger = TriggerUtils.makeSecondlyTrigger(3); trigger.setName( testTrigger ); trigger.setStartTime( new Date() ); trigger.setVolatility( true ); s.scheduleJob( jobDetail, trigger ); Thread.sleep(1); } } _ the hivemodule looks like this (autowiring used): ___ module id=scheduler version=1.0.0 package=ch.bmw.jobscheduler Defines services for the JobScheduler-Application. service-point interface=org.quartz.Scheduler id=Scheduler invoke-factory service-id=SchedulerFactoryForHivemind model=singleton/ /service-point service-point id=SchedulerFactoryForHivemind parameters-occurs=0..1 interface=org.apache.hivemind.ServiceImplementationFactory A wrapper around the quartz standard SchedulerFactory (see below). Provides schedulers with a hivemind-aware JobFactory and starts them. invoke-factory model=singleton construct class=SchedulerFactoryForHivemind/ /invoke-factory interceptor service-id=hivemind.LoggingInterceptor/ /service-point service-point id=SchedulerFactory interface=org.quartz.SchedulerFactory A raw quartz SchedulerFactory as configured in the config-file given. Usually wrapped by a SchedulerFactoryForHiveMind - see above. invoke-factory construct class=org.quartz.impl.StdSchedulerFactory string${quartz.config.file}/string /construct /invoke-factory interceptor service-id=hivemind.LoggingInterceptor/ /service-point contribution configuration-id=hivemind.FactoryDefaults default symbol=quartz.config.file value=quartz.properties/ /contribution /module ___ package ch.bmw.jobscheduler; import java.util.Iterator; import org.apache.hivemind.ApplicationRuntimeException; import org.apache.hivemind.Registry; import org.apache.hivemind.ServiceImplementationFactory; import org.apache.hivemind.ServiceImplementationFactoryParameters; import org.apache.hivemind.events.RegistryShutdownListener; import org.apache.hivemind.internal.RegistryInfrastructure; import org.apache.hivemind.internal.ser.ServiceSerializationHelper; import org.quartz.Scheduler; import org.quartz.SchedulerException; import org.quartz.SchedulerFactory; import com.javaforge.honeycomb.RegistryAccessor; public class SchedulerFactoryForHivemind implements ServiceImplementationFactory, RegistryShutdownListener{ private SchedulerFactory schedulerFactory; public SchedulerFactoryForHivemind( SchedulerFactory sf ) { schedulerFactory = sf; } public Object createCoreServiceImplementation( ServiceImplementationFactoryParameters factoryParameters) { try { if ( ! factoryParameters.getServiceInterface().equals( Scheduler.class ) ) throw new ApplicationRuntimeException(this factory can't make + factoryParameters.getServiceInterface() ); String name = (String)
Re: Scheduling tasks
I'm trying to figure out how to integrate quartz with my tapestry app based on Marcus' explanation but I'm missing some key points. Could anyone post some code showing how to implement this? -- View this message in context: http://www.nabble.com/Scheduling-tasks-tf1963494.html#a5504499 Sent from the Tapestry - User forum at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Scheduling tasks
I can't comment on Quartz but I did use the Oracle scheduler until someone scheduled a query that ran for hours and made the database useless. It was difficult to recover from because you could not login to stop the task. If you schedule * * * * * wget http://localhost/cronjob then you don't have any machine dependencies although I generally schedule a shell script because I want an email if it fails which leads to Quartz only works when the JVM is running. I've seen enough JVM crashes to have a cronjob that restarts Tomcat. I don't recall cron ever crashing. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Scheduling tasks
any oracle developer or dba could tell you: alter system kill session 'sid,serial'; Kills any session. In Oracle you can allways kill session that have gone astray. And even if it doesn't work from sql+, you can always look op the OS-pid (in v$session) and kill the process on the os level. (Be sure that you set job_queue_processes to 0, because if you don't Oracle sometimes restarts the job). Martijn Original Message From: [EMAIL PROTECTED] To: users@tapestry.apache.org Subject: Re: Scheduling tasks Date: Thu, 20 Jul 2006 07:28:42 -0500 I can't comment on Quartz but I did use the Oracle scheduler until someone scheduled a query that ran for hours and made the database useless. It was difficult to recover from because you could not login to stop the task. If you schedule * * * * * wget http://localhost/cronjob then you don't have any machine dependencies although I generally schedule a shell script because I want an email if it fails which leads to Quartz only works when the JVM is running. I've seen enough JVM crashes to have a cronjob that restarts Tomcat. I don't recall cron ever crashing. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Scheduling tasks
Using Quartz is not very difficult. I did it in the following steps - write a HivemindServiceJobFactory which takes HiveMind-Services implementing Job or Runnable and wrap them into an adapter taking care of calling setupThread and cleanupThread on the registry. The service-id is taken from the JobDetail's data-map unless there's only one Job configured as a hivemind service. - write a ServiceImplementationFactory which retrieves the Scheduler from the corresp. Quartz factory and replaces the Standard JobFactory with the above one (attention: needs access to the registry - you'll need to override tap's application servlet to accomplish that) marcus
Re: Scheduling tasks
I looked at Quartz but decided to schedule a wget from a cron job instead. I think it's better to schedule via an external event since it makes it easier to turn them off when things go bad. Also cron is simple and reliable.
Re: Scheduling tasks
Thanks Marcus, that was pretty straighforward. Instead of overriding ApplicationServlet, I injected WebContext and got the Hivemind Registry from there. Since I'd like to start the scheduler on application startup, I also added it to hivemind.EagerLoad. But, at that time the servlet hasn't been initialized so there's no Hivemind Registry in the WebContext. Any suggestions on how to work around this? Perhaps I can make the scheduler start after the application has been initialized? Martin On Wed, 19 Jul 2006 08:41:25 +0200, Schulte Marcus [EMAIL PROTECTED] wrote: Using Quartz is not very difficult. I did it in the following steps - write a HivemindServiceJobFactory which takes HiveMind-Services implementing Job or Runnable and wrap them into an adapter taking care of calling setupThread and cleanupThread on the registry. The service-id is taken from the JobDetail's data-map unless there's only one Job configured as a hivemind service. - write a ServiceImplementationFactory which retrieves the Scheduler from the corresp. Quartz factory and replaces the Standard JobFactory with the above one (attention: needs access to the registry - you'll need to override tap's application servlet to accomplish that) marcus - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Scheduling tasks
Oh cron is the path of ev-il. I used to use it as well but found the dependency on physical machine setup to be very annoying and easy to forget. Quartz has proven very reliable for me so far. (Probably even more so than cron, since it has all manner of built-in error handling tactics ) On 7/19/06, Barry Books [EMAIL PROTECTED] wrote: I looked at Quartz but decided to schedule a wget from a cron job instead. I think it's better to schedule via an external event since it makes it easier to turn them off when things go bad. Also cron is simple and reliable. -- Jesse Kuhnert Tacos/Tapestry, team member/developer Open source based consulting work centered around dojo/tapestry/tacos/hivemind.
Re: Scheduling tasks
+1 on quartz On 7/19/06, Jesse Kuhnert [EMAIL PROTECTED] wrote: I would use quartz. It took me about half an hour to integrate with hivemind. On 7/18/06, Martin Strand [EMAIL PROTECTED] wrote: Hi guys. How can I schedule a task with Hivemind? I want something similar to crond in Linux - a service should be notified every n minutes. Ideally the service would implement Runnable and the scheduler would invoke run(). I've heard of Quartz, but I've never used it before and I'm not sure how to use it together with Hivemind. What other options are there? Thanks for any help, Martin - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Jesse Kuhnert Tacos/Tapestry, team member/developer Open source based consulting work centered around dojo/tapestry/tacos/hivemind.