CodeGuru
CodeGuru

Reputation: 746

Running akka scheduler only once in a cluster

I have configured a Akka scheduler in my play application. It works fine but now the problem is I have two instances of same application running in a cluster. So scheduler is also running twice. I want it to run only once for the overall application. Is there some provision in akka to achieve this. Also java related help will be appreciable.

Upvotes: 5

Views: 741

Answers (1)

hveiga
hveiga

Reputation: 6915

For this you will need to use the module Akka Cluster Singleton: http://doc.akka.io/docs/akka/snapshot/java/cluster-singleton.html

This module provides the capability to have only one actor within a whole cluster. The following code explains how to do it in Scala, I think for Java it should be pretty similar:

context.actorOf(ClusterSingletonManager.props(YourScheduler.props, PoisonPill, ClusterSingletonManagerSettings(context.system)), "singletonScheduler")
val singletonScheduler = system.actorOf(ClusterSingletonProxy.props(
  singletonManagerPath = "/user/app/singletonScheduler",
  settings = ClusterSingletonProxySettings(system)),
  name = "singletonSchedulerProxy")

Upvotes: 4

Related Questions