我正在学习 twitter 的 RPC 异步系统,使用过滤器和服务处理逻辑任务很重要。我已经阅读了https://twitter.github.io/finagle/guide/ServicesAndFilters.html的论文并尝试编写一个简单的代码来制作真的,我知道。但是有一些问题:
import com.twitter.util.Future
trait Service[Req, Rep] extends (Req => Future[Rep])
abstract class Filter[-ReqIn, +RepOut, +ReqOut, -RepIn]
extends ((ReqIn, Service[ReqOut, RepIn]) => Future[RepOut])
trait SimpleFilter[Req, Rep] extends Filter[Req, Rep, Req, Rep]
class DoubleFilter(times: Int) extends SimpleFilter[(Int,Int), Int] {
def apply(request: (Int,Int), service: Service[(Int,Int), Int]): Future[Int] = {
service((request._1 * times, request._2 * times))
}
}
class AddFilter(count: Int) extends SimpleFilter[(Int, Int), Int] {
def apply(request: (Int, Int), service: Service[(Int, Int),Int]): Future[Int] = {
service((request._1 + count, request._2 + count))
}
}
object Test extends App {
val doubleFilter = new DoubleFilter(2)
val addFilter = new AddFilter(10)
//req is tuple, rep is added count of int
val addELemsService = new Service[(Int,Int), Int] {
def apply(req: (Int,Int)) = {
Future {
req._1 + req._2
}
}
}
val serviceWithDoble = doubleFilter andThen addELemsService
val doubleWithAddFilter = doubleFilter andThen addFilter
}
结果有两个编译错误:value 和Then 不是DoubleFilter 的成员!
我想念什么明白吗?我直认为医生忽略了一些东西,但我误导了。