I see. I understand this is a very conservative approach (better not create 
a new singleton until 100% sure it's not running). Are these values you are 
suggesting sensible enough? 
Thanks

On Wednesday, January 15, 2014 1:06:08 PM UTC-5, Patrik Nordwall wrote:
>
> Hi Giovanni,
>
> You were 5 seconds from seeing the expected result.
> Increase the last sleep to 25 seconds.
>
> You can reduce this timeout by using the following parameter to 
> ClusterSingletonManager.props:
> maxHandOverRetries = 10,
> maxTakeOverRetries = 5
>
> The default timeouts for the retries are too conservative in 2.2.3 
> (residue from first impl, which did not run the singleton on the oldest 
> node).
> In 2.3-M2 the default values for these settings have been reduced.
>
> Regards,
> Patrik
>
> On Wed, Jan 15, 2014 at 4:55 PM, Giovanni Botta 
> <[email protected]<javascript:>
> > wrote:
>
>> I am really struggling with this one. I tried to follow the (quite 
>> fragmented) examples about the cluster singleton pattern (for akka 2.2.3) 
>> and I came up with the following code to play around with it:
>>
>> import org.scalatest.{Matchers, WordSpecLike}
>> import akka.actor._
>> import akka.testkit.TestKit
>> import akka.cluster.Cluster
>> import akka.contrib.pattern.ClusterSingletonManager
>> import com.typesafe.config.ConfigFactory
>> import scala.concurrent.duration._
>> import scala.concurrent.{Await, Future}
>>
>> class ClusterSingletonSpec extends TestKit(ActorSystem("SingletonTest")) 
>> with WordSpecLike with Matchers {
>>
>>   val ports = "2551" :: "2552" :: "2553" :: "2554" :: Nil
>>   val systems = ports.map(new SingletonSystem(_))
>>
>>   "the cluster singleton" should {
>>     "be reachable using actor selection" in {
>>       new SingletonSystem("2555") {
>>
>>         Cluster(system).registerOnMemberUp {
>>           import system.dispatcher
>>
>>           // let's wait for the singleton to be created...
>>           Thread.sleep(5000)
>>
>>           val timeout = 5.seconds
>>
>>           val resolved = Future.sequence(
>>             ("2555" :: ports).map(
>>               port =>
>>                 
>> system.actorSelection(s"akka.tcp://[email protected]:$port/user/singleton/singletonService").resolveOne(timeout).map(Some(_)).recover
>>  
>> {
>>                   case e =>
>>                     println(s"Ooops: $e")
>>                     None
>>                 }
>>             )
>>           ).map(_.flatten)
>>
>>           println(Await.result(resolved, 10 seconds))
>>         }
>>       }
>>       // let's sit on this for a little while
>>       Thread.sleep(20000)
>>     }
>>   }
>> }
>>
>> class SingletonSystem(name: String, port: String) extends 
>> TestKit(ActorSystem(name,
>>   
>> ConfigFactory.parseString(s"akka.remote.netty.tcp.port=$port").withFallback(ConfigFactory.parseString(SingletonSystem.cfg))))
>>  
>> {
>>
>>   def this(port: String) = this("SingletonSystem", port)
>>
>>   def this() = this("0")
>>
>>   Cluster(system).registerOnMemberUp {
>>     system.actorOf(ClusterSingletonManager.props(
>>       singletonProps = _ ⇒ Props[SingletonService],
>>       singletonName = "singletonService",
>>       terminationMessage = PoisonPill,
>>       role = None),
>>       name = "singleton")
>>   }
>> }
>>
>> class SingletonService extends Actor {
>>   println("Service created")
>>
>>   import context.dispatcher
>>
>>   context.system.scheduler.schedule(500 milliseconds, 500 milliseconds, 
>> self, "I am the service")
>>
>>   def receive: Actor.Receive = {
>>     case msg => println(s"Service received: $msg")
>>   }
>> }
>>
>> object SingletonSystem {
>>   val cfg = """akka {
>>               |
>>               |  loglevel = INFO
>>               |
>>               |  cluster {
>>               |    seed-nodes = [
>>               |      "akka.tcp://[email protected]:2551",
>>               |      "akka.tcp://[email protected]:2552"
>>               |      ]
>>               |
>>               |    auto-down-unreachable-after = 10s
>>               |
>>               |    min-nr-of-members = 2
>>               |  }
>>               |
>>               |  actor.provider = "akka.cluster.ClusterActorRefProvider"
>>               |
>>               |  remote {
>>               |    log-remote-lifecycle-events = off
>>               |    netty.tcp {
>>               |      hostname = "127.0.0.1"
>>               |      port = 0
>>               |    }
>>               |  }
>>               |}
>>             """.stripMargin
>> }
>>
>> The problem is that it doesn't work at all: the singleton doesn't even 
>> get created and the log shows (among others) the following lines:
>>
>> [INFO] [01/15/2014 10:50:01.512] 
>> [SingletonSystem-akka.actor.default-dispatcher-19] 
>> [akka://SingletonSystem/user/singleton] ClusterSingletonManager state 
>> change [Start -> BecomingOldest]
>> [INFO] [01/15/2014 10:50:01.886] 
>> [SingletonSystem-akka.actor.default-dispatcher-2] 
>> [akka://SingletonSystem/user/singleton] ClusterSingletonManager state 
>> change [Start -> Younger]
>> [INFO] [01/15/2014 10:50:02.529] 
>> [SingletonSystem-akka.actor.default-dispatcher-19] 
>> [akka://SingletonSystem/user/singleton] Retry [1], sending HandOverToMe to 
>> [None]
>> [INFO] [01/15/2014 10:50:03.545] 
>> [SingletonSystem-akka.actor.default-dispatcher-8] 
>> [akka://SingletonSystem/user/singleton] Retry [2], sending HandOverToMe to 
>> [None]
>> [INFO] [01/15/2014 10:50:04.566] 
>> [SingletonSystem-akka.actor.default-dispatcher-7] 
>> [akka://SingletonSystem/user/singleton] Retry [3], sending HandOverToMe to 
>> [None]
>> [INFO] [01/15/2014 10:50:05.586] 
>> [SingletonSystem-akka.actor.default-dispatcher-18] 
>> [akka://SingletonSystem/user/singleton] Retry [4], sending HandOverToMe to 
>> [None]
>> [INFO] [01/15/2014 10:50:06.484] 
>> [SingletonSystem-akka.actor.default-dispatcher-19] 
>> [akka://SingletonSystem/user/singleton] ClusterSingletonManager state 
>> change [Start -> Younger]
>> [INFO] [01/15/2014 10:50:06.605] 
>> [SingletonSystem-akka.actor.default-dispatcher-3] 
>> [akka://SingletonSystem/user/singleton] Retry [5], sending HandOverToMe to 
>> [None]
>> [INFO] [01/15/2014 10:50:06.614] 
>> [SingletonSystem-akka.actor.default-dispatcher-6] 
>> [akka://SingletonSystem/user/singleton] ClusterSingletonManager state 
>> change [Start -> Younger]
>> [INFO] [01/15/2014 10:50:06.669] 
>> [SingletonSystem-akka.actor.default-dispatcher-20] 
>> [akka://SingletonSystem/user/singleton] ClusterSingletonManager state 
>> change [Start -> Younger]
>> [INFO] [01/15/2014 10:50:07.626] 
>> [SingletonSystem-akka.actor.default-dispatcher-16] 
>> [akka://SingletonSystem/user/singleton] Retry [6], sending HandOverToMe to 
>> [None]
>> [INFO] [01/15/2014 10:50:08.646] 
>> [SingletonSystem-akka.actor.default-dispatcher-5] 
>> [akka://SingletonSystem/user/singleton] Retry [7], sending HandOverToMe to 
>> [None]
>> [INFO] [01/15/2014 10:50:09.665] 
>> [SingletonSystem-akka.actor.default-dispatcher-8] 
>> [akka://SingletonSystem/user/singleton] Retry [8], sending HandOverToMe to 
>> [None]
>> [INFO] [01/15/2014 10:50:10.686] 
>> [SingletonSystem-akka.actor.default-dispatcher-16] 
>> [akka://SingletonSystem/user/singleton] Retry [9], sending HandOverToMe to 
>> [None]
>> [INFO] [01/15/2014 10:50:11.706] 
>> [SingletonSystem-akka.actor.default-dispatcher-3] 
>> [akka://SingletonSystem/user/singleton] Retry [10], sending HandOverToMe to 
>> [None]
>> [INFO] [01/15/2014 10:50:12.726] 
>> [SingletonSystem-akka.actor.default-dispatcher-16] 
>> [akka://SingletonSystem/user/singleton] Retry [11], sending HandOverToMe to 
>> [None]
>> [INFO] [01/15/2014 10:50:13.746] 
>> [SingletonSystem-akka.actor.default-dispatcher-20] 
>> [akka://SingletonSystem/user/singleton] Retry [12], sending HandOverToMe to 
>> [None]
>> [INFO] [01/15/2014 10:50:14.766] 
>> [SingletonSystem-akka.actor.default-dispatcher-3] 
>> [akka://SingletonSystem/user/singleton] Retry [13], sending HandOverToMe to 
>> [None]
>> [INFO] [01/15/2014 10:50:15.785] 
>> [SingletonSystem-akka.actor.default-dispatcher-17] 
>> [akka://SingletonSystem/user/singleton] Retry [14], sending HandOverToMe to 
>> [None]
>> [INFO] [01/15/2014 10:50:16.806] 
>> [SingletonSystem-akka.actor.default-dispatcher-3] 
>> [akka://SingletonSystem/user/singleton] Retry [15], sending HandOverToMe to 
>> [None]
>> [INFO] [01/15/2014 10:50:17.825] 
>> [SingletonSystem-akka.actor.default-dispatcher-6] 
>> [akka://SingletonSystem/user/singleton] Retry [16], sending HandOverToMe to 
>> [None]
>> [INFO] [01/15/2014 10:50:18.846] 
>> [SingletonSystem-akka.actor.default-dispatcher-19] 
>> [akka://SingletonSystem/user/singleton] Retry [17], sending HandOverToMe to 
>> [None]
>> [INFO] [01/15/2014 10:50:19.866] 
>> [SingletonSystem-akka.actor.default-dispatcher-2] 
>> [akka://SingletonSystem/user/singleton] Retry [18], sending HandOverToMe to 
>> [None]
>> [INFO] [01/15/2014 10:50:20.885] 
>> [SingletonSystem-akka.actor.default-dispatcher-17] 
>> [akka://SingletonSystem/user/singleton] Retry [19], sending HandOverToMe to 
>> [None]
>>
>> And my println statements:
>>
>> Ooops: akka.actor.ActorNotFound: Actor not found for: 
>> ActorSelection[Actor[akka://SingletonSystem/]/user/singleton/singletonService]
>> Ooops: akka.actor.ActorNotFound: Actor not found for: 
>> ActorSelection[Actor[akka.tcp://
>> [email protected]:2551/]/user/singleton/singletonService<http://[email protected]:2551/%5D/user/singleton/singletonService>
>> ]
>> Ooops: akka.actor.ActorNotFound: Actor not found for: 
>> ActorSelection[Actor[akka.tcp://
>> [email protected]:2553/]/user/singleton/singletonService<http://[email protected]:2553/%5D/user/singleton/singletonService>
>> ]
>> Ooops: akka.actor.ActorNotFound: Actor not found for: 
>> ActorSelection[Actor[akka.tcp://
>> [email protected]:2552/]/user/singleton/singletonService<http://[email protected]:2552/%5D/user/singleton/singletonService>
>> ]
>> Ooops: akka.actor.ActorNotFound: Actor not found for: 
>> ActorSelection[Actor[akka.tcp://
>> [email protected]:2554/]/user/singleton/singletonService<http://[email protected]:2554/%5D/user/singleton/singletonService>
>> ]
>> List()
>>
>> I can't figure out what I'm doing wrong. Is it because I'm running in a 
>> single JVM? If so, is this a bug?
>>
>> I appreciate any help, I've been banging my head against this for two 
>> days with no luck.
>>  
>> -- 
>> >>>>>>>>>> Read the docs: http://akka.io/docs/
>> >>>>>>>>>> Check the FAQ: http://akka.io/faq/
>> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "Akka User List" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected]<javascript:>
>> .
>> Visit this group at http://groups.google.com/group/akka-user.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>
>
> -- 
>
> Patrik Nordwall
> Typesafe <http://typesafe.com/> -  Reactive apps on the JVM
> Twitter: @patriknw
>
> 

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: http://akka.io/faq/
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to