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?
The simplest implementation I can image is the following architecture:
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.
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.
Here's my org.springframework.scheduling.quartz.SchedulerFactoryBean extension that makes it happen:
@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();
}
Please, let me know if I am missing something Big and if this can be done.
I have added the two files to github. Here's the RAMJobStore extension:
https://github.com/mufumbo/quartz-hazelcast/blob/master/src/main/java/com/mufumbo/server/scheduler/hazelcast/HazelcastRAMJobStore.java
And here's the Spring SchedulerFactoryBean extension:
https://github.com/mufumbo/quartz-hazelcast/blob/master/src/main/java/com/mufumbo/server/scheduler/hazelcast/SchedulerFactoryBean.java
I was thinking about the same concept some time ago. You can actually integrate Hazelcast
with quartz-scheduler
easily by implementing JobStore
SPI interface. Check out RAMJobStore
for reference on how to implement job store based on in-memory data structures and JobStoreTX
- clustered, database-backed store.
This interface is quite large, but it should be the only place required to switch from RAM or Terracotta to Hazelcast. The latter library already provides distrubuted storage and locks so it should be rather straightforward.
Would be awesome if you could share your implemention (GitHub?), guess it would be a viable alternative to Terracotta cluster for many people.
Starting with the version 3.8
you can simply use distributed Scheduled Executor Service
:
scheduleOnMember()
scheduleOnKeyOwner()
scheduleOnAllMembers()
scheduleOnAllMembers()
See Scheduled Executor Service and IScheduledExecutorService
for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With