Platinum Partner
java,dsl,scala,quartz 2.0

Scala and Quartz DSL

Quartz 2.0 introduces a Domain Specific Language (DSL) for working with the core entities (jobs and triggers).

As a Scala fan boy, this is my first translation of the first sample

I - Define implicits conversions to skip build method

implicit def toJobDetail(jb :JobBuilder): JobDetail= jb.build
implicit def toTrigger(tb :TriggerBuilder[org.quartz.Trigger]):Trigger = tb.build

II- Pinp Scheduler class

class RichScheduler(s: Scheduler){
def <-> (job:JobDetail , trigger:Trigger)=  s.scheduleJob(job, trigger)
def ->> (job:JobDetail , trigger:Trigger)=  {(<-> (job:JobDetail , trigger:Trigger)); +this}
def unary_+ = s start
def << =  s shutdown
def unary_-  = s shutdown true
}
implicit def toScheduler (sf:SchedulerFactory):RichScheduler = new RichScheduler(sf.getScheduler())

III- Enjoy

 val sched = new StdSchedulerFactory()
val runTime = evenMinuteDate(new Date())
val job = newJob(classOf[HelloJob]) withIdentity ("job1", "group1")
val trigger = newTrigger() withIdentity ("trigger1", "group1") startAt runTime

// ->> or this
//  sched <-> (job ,  trigger)
// +sched

sched ->> (job ,  trigger)
sleep
-sched


From http://ouertani.com/2011/05/scala-and-quartz-dsl/

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}