Hazelcast scheduled tasks (quartz support?)

I know this is unfair to the terracotta guys, but has anyone tried to use Hazelcast to use scheduled tasks in a cluster environment?

The simplest implementation I can imagine is the following architecture:

  • Hazelcast's global lock to provide only one server triggers the Quartz configuration.
  • Performing actual tasks like DistributedTask. (this can be done later, for the time being, the heavy scheduled tasks will have to take care of starting DistributedTask)
  • As soon as the server holding the lock shuts down, the other server receives the lock.

I believe that this would be a great advantage for people who already have Hazelcast, as they will not require all the environmental problems by revealing terracotta material all the time.

At the moment, I have encoded the simplest solution to make only one node, which will be responsible for the execution of Quartz triggers. Since I only use triggers like Cron, this might be an acceptable solution if I take care of creating DistributedTasks for heavy trigger tasks.

Here is my org.springframework.scheduling.quartz.SchedulerFactoryBean extension that does this:

@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 it can be done.

I added two files to github. Here is the RAMJobStore extension:

https://github.com/mufumbo/quartz-hazelcast/blob/master/src/main/java/com/mufumbo/server/scheduler/hazelcast/HazelcastRAMJobStore.java

And here is the Spring SchedulerFactoryBean extension:

https://github.com/mufumbo/quartz-hazelcast/blob/master/src/main/java/com/mufumbo/server/scheduler/hazelcast/SchedulerFactoryBean.java

+6
source share
2 answers

I was thinking about the same concept a while ago. In fact, you can easily integrate Hazelcast with quartz-scheduler by implementing the JobStore SPI interface. Check out RAMJobStore for help on how to implement a job repository based on in-memory data structures and JobStoreTX -based cluster repository.

This interface is quite large, but it should be the only place that is required to switch from RAM or Terracotta to Hazelcast. The latter library already provides distributed storages and locks, so it should be fairly simple.

It would be great if you could share your implementation (GitHub?), Suppose this would be a viable alternative to the Terracotta cluster for many people.

+8
source

Starting with version 3.8 you can simply use the distributed Scheduled Executor Service :

  • scheduleOnMember()
  • scheduleOnKeyOwner()
  • scheduleOnAllMembers()
  • scheduleOnAllMembers()

See Scheduled Executor Service and IScheduledExecutorService for more details.

+3
source

Source: https://habr.com/ru/post/918615/


All Articles