DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Trending

  • Hyperion Essbase Technical Functionality
  • Measuring Service Performance: The Whys and Hows
  • Batch Request Processing With API Gateway
  • Execution Type Models in Node.js
  1. DZone
  2. Coding
  3. Languages
  4. Scala and Quartz DSL

Scala and Quartz DSL

Slim Ouertani user avatar by
Slim Ouertani
·
May. 19, 11 · Interview
Like (0)
Save
Tweet
Share
8.02K Views

Join the DZone community and get the full member experience.

Join For Free

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/

Domain-Specific Language Scala (programming language) Quartz (scheduler)

Opinions expressed by DZone contributors are their own.

Trending

  • Hyperion Essbase Technical Functionality
  • Measuring Service Performance: The Whys and Hows
  • Batch Request Processing With API Gateway
  • Execution Type Models in Node.js

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: