RemoteActor.select-结果确定吗? [英] RemoteActor.select - result deterministic?

查看:77
本文介绍了RemoteActor.select-结果确定吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在调用val委托= RemoteActor.select()时是否有任何确定性。
之所以这样问,是因为当我通过网络发送代表时,我注意到该程序并未终止。

I wonder if there is any determinism when calling val delegate = RemoteActor.select(). I'm asking this, because I noticed that the program doesn't terminate, when I'm sending delegates over the net.

还有其他副作用吗,具体取决于委托人吗?

Are there any other side effects, which depend on the delegate?

有什么规则,当RemoteActor.select会为相同的参数返回相同的委托吗?

Are there any rules, when RemoteActor.select will return the same delegate for the same arguments?

一些示例代码演示了RemoteActor.select问题:

Here's some example code which demonstrates the RemoteActor.select problem:

package test

import scala.actors.Actor, Actor._
import scala.actors.remote._, RemoteActor._

object DelegateTest {
  def main(args :Array[String]) {
    val actor = new Actorlein("localhost", 63000, 'first)
    actor ! 'eval
  }
}

class Actorlein(val host: String, val port: Int, val symbol: Symbol) extends Actor {
  val preProxy1 = select(node, symbol)
  val preProxy2 = select(node, symbol)

  val node = Node(host,port)
  this.start
  alive(port)
  register(symbol, this)

  val initProxy1 = select(node, symbol)
  val initProxy2 = select(node, symbol)

  override def act = { 
    val actProxy1 = select(node, symbol)
    val actProxy2 = select(node, symbol)
    react {
      case 'eval => {
        val reactProxy1 = select(node, symbol)
        val reactProxy2 = select(node, symbol)
        //all true
        println("pProxy equal? "+(preProxy1 == preProxy2))
        println("iProxy equal? "+(initProxy1 == initProxy2))
        println("aProxy equal? "+(actProxy1 == actProxy2))
        println("rProxy equal? "+(reactProxy1 == reactProxy2))
        //all true()
        println("i equal p? "+(initProxy1 == preProxy1)) //false
        println("r equal p? "+(reactProxy1 == preProxy1))//false
        println("a equal p? "+(actProxy1 == preProxy1))  //false
        println("i equal a? "+(initProxy1 == actProxy1)) //false
        println("r equal a? "+(reactProxy1 == actProxy1))//true
      }
      case any => println("Unkown Msg: "+any)
    } 
  }
}


推荐答案

您的问题让我感到好奇,因此我快速查看了源代码...这是我发现的东西:

Your question got me curious so I had a quick look at the source ... here's what I found:

select返回的内容似乎取决于处理TCP连接的对象。正如此NetKernel记住以前创建的代理一样,只要当前Netkernel相同,这些代理就是相同的。当前的Netkernel取决于Actor.self的当前值,该值可能(在我之前没有深入探讨)在当前线程上。对我来说,这解释了为什么r = a但p和i与此不同。

What select returns seems to depend on an object that handles the TCP connections. As this NetKernel remembers previously created proxies, the proxies are the same as long as the "current Netkernel" is the same. The current Netkernel depends on the current value of Actor.self, which might (I didn't dig that deep) on the current thread. For me that explains why r=a but p and i are different from that.

我想,p和我不同的原因是,通过alive(port)调用将新的NetKernel与actor关联(actor的内核需要使用指定的端口,而不是随机端口)。

I guess, the reason for p and i being different is that a new NetKernel is associated with the actor by the alive(port) call (the actor's kernel needs to use the specified port, and not a random one).

这篇关于RemoteActor.select-结果确定吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆