Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala远程方法注入_Scala - Fatal编程技术网

Scala远程方法注入

Scala远程方法注入,scala,Scala,我有一个需求,我有一个方法,它接受另一个函数。我想在我的调用者中得到这个参数函数的结果。 我已经为这个场景创建了一个代码片段: class ProcessHandler { def executeInstructions(x:String=>Array[String]) { //print the resultant list here } } object ProcessHandlerMain { def main(args: Array[String])

我有一个需求,我有一个方法,它接受另一个函数。我想在我的调用者中得到这个参数函数的结果。 我已经为这个场景创建了一个代码片段:

class ProcessHandler {

  def executeInstructions(x:String=>Array[String])
  {
     //print the resultant list here

 } 
}

object ProcessHandlerMain {
  def main(args: Array[String]) {
  val handler = new ProcessHandler
  handler.executeInstructions(   instruction)
 }

 def instruction(x:String):Array[String] =
  {
  List("words", "from", "book").toArray
  }
}
此调用处理程序。executeInstructions(指令)将由另一个进程执行。这里我使用main方法来测试它

以下是我不知道的:

  • 如何打印参数函数的结果
  • 如果我必须向客户端公开这个方法executeInstructions(),那么最好的方法是什么?这里我们将不传递文本指令,而是传递一个类似于指令()的函数
谢谢

更新:根据收到的回复,我的代码更新为

class ProcessHandler {

 def executeInstructions(x:String=>Array[String])
 {
 //print the resultant list here
  val result = x("some string here")

//this array will be sent to another service
// dispatcher.dispatch(result)
} 
}
我的要求已更新:

  • 如何打印参数函数的结果:Done
  • 如果我必须向客户端公开这个方法executeInstructions(),那么最好的方法是什么?这里我们将不传递文本指令,而是传递一个类似于指令()的函数待定
客户端界面的工作方式如下: 1.客户端将远程调用executeInstructions(),并将函数作为参数传递。 2.指令ID将被传递给注入函数,生成的数组将被分派到另一个服务