我有一个程序结构如下:如何获取对运行函数的actor实例的引用?
abstract class OuterClass
{
class InnerClass extends Actor
{
loop
{
react
{
case m: T => someFunction(m)
}
}
def someFunction(m: T)
{
...search function map for specific function...
specificFunction()
}
...extra methods here...
}
var functionmap=scala.sollection.mutable.Map.empty[String,()=>String]
var actorpool: ArrayBuffer[Actor]=new ArrayBuffer(0)
def main(args: Array[String])
{
...create X actors and add them to the pool...
populatefunctionmap
}
def populatefunctionmap() //defined elsewhere
}
class RunMe extends OuterClass
{
def populatefunctionmap()
{
...add some functions to the map...
}
}
我的问题是,我想利用运行我functionmap
功能演员实例中可用的额外功能。当我尝试使用this
时,它指的是延伸RunMe
类。使用self
只会导致not found: value self
编译器错误。
是我想做的可能吗?如果是这样,怎么样?
谢谢你的回答。我想我的问题可能不够清楚。在'main'方法中创建了许多actor实例。在稍后的时间点,一条消息将被发送到这些实例中的一个或多个 - 此时它将从'functionmap'运行一个函数。我希望能够从运行的函数中访问特定的actor的方法。对不起,我的问题不够清楚。 – Gareth 2012-03-22 09:02:33