Willem
Willem

Reputation: 927

How do I kill a RemoteActor?

Not sure whether I am missing something. When making an actor remote, the main method does not terminate.

Here is a snippet that demonstrates the problem.

import scala.actors._
import scala.actors.remote._
object TestMe {
  def main(args : Array[String]) : Unit = {
      object jim extends DaemonActor {
          // comment out these two lines and the application will terminate
          RemoteActor.alive(12345)
          RemoteActor.register('jim,this)         
          def act {
              loop {
                  receive {
                      case 'quit =>
                       println("\nquiting")
                        exit('normal)
                      case any => 
                        println(any)
                  }
              }
          }
      }
      jim.start
      jim ! "hello"
      jim ! 'quit
  }
}

Upvotes: 4

Views: 413

Answers (1)

Magnus
Magnus

Reputation: 1153

Put your .alive and .register calls inside act() and your code successfully terminates.

Upvotes: 4

Related Questions