title: Hazelcast scheduled jobs (Quartz support?)
body: <p>I know it's unfair with the terracotta guys, but has anyone tried to use Hazelcast in order to use scheduled jobs in a clustered environment?</p>
  
  <p>The simplest implementation I can image is the following architecture:</p>
  
  <ol>
  <li>A global Hazelcast lock for ensuring <strong>only one server</strong> has startup the Quartz config.</li>
  <li>Running the actual tasks as DistributedTask. (this can be done later, for the moment the heavy scheduled tasks will need to take care of triggering DistributedTask)</li>
  <li>As soon as the server holding the lock is down, another server gets the lock.</li>
  </ol>
  
  <p>I believe this would be a great advantage for people who already has the Hazelcast, since they won't require the whole dev-environment hassle by opening the terracotta stuff all the time.</p>
  
  <p>For the moment I have coded the simplest solution of making only one node to be in charge of executing Quartz triggers. Since I only use Cron-like triggers, it could be an acceptable solution if I take care of creating DistributedTasks for the heavy trigger tasks.</p>
  
  <p>Here's my org.springframework.scheduling.quartz.SchedulerFactoryBean extension that makes it happen:</p>
  
  <pre><code>@Override
  public void start() throws SchedulingException {
      new Thread(new Runnable() {
          @Override
          public void run() {
              final Lock lock = getLock();
              lock.lock();
              log.warn("This node is the master Quartz");
              SchedulerFactoryBean.super.start();
          }
      }).start();
      log.info("Starting..");
  }
  
  @Override
  public void destroy() throws SchedulerException {
      super.destroy();
      getLock().unlock();
  }
  </code></pre>
  
  <p>Please, let me know if I am missing something Big and if this can be done.</p>
  
  <p>I have added the two files to github. Here's the RAMJobStore extension:</p>
  
  <p><a href="https://github.com/mufumbo/quartz-hazelcast/blob/master/src/main/java/com/mufumbo/server/scheduler/hazelcast/HazelcastRAMJobStore.java" rel="noreferrer">https://github.com/mufumbo/quartz-hazelcast/blob/master/src/main/java/com/mufumbo/server/scheduler/hazelcast/HazelcastRAMJobStore.java</a></p>
  
  <p>And here's the Spring SchedulerFactoryBean extension:</p>
  
  <p><a href="https://github.com/mufumbo/quartz-hazelcast/blob/master/src/main/java/com/mufumbo/server/scheduler/hazelcast/SchedulerFactoryBean.java" rel="noreferrer">https://github.com/mufumbo/quartz-hazelcast/blob/master/src/main/java/com/mufumbo/server/scheduler/hazelcast/SchedulerFactoryBean.java</a></p>