【发布时间】:2019-01-18 06:22:58
【问题描述】:
我有一个 akka 流,其中有一个 ADT 形式。
sealed trait Message
sealed trait ThisMessage extends Message
sealed trait ThatMessage extends Message
现在我有一个这个消息处理程序流和一个那个消息处理程序流。我有一个接受消息类型的入口流。
为了创建拆分,我有以下分区程序。我对分区函数有以下定义。
/**
* Creates a Partition stage that, given a type A, makes a decision to whether to partition to subtype B or subtype C
*
* @tparam A type of input
* @tparam B type of output on the first outlet.
* @tparam C type of output on the second outlet.
*
* @return A partition stage
*/
def binaryPartitionByType[A, B <: A, C <: A](): Graph[FanOutShape2[A, B, C], NotUsed] =
GraphDSL.create[FanOutShape2[A, B, C]]() { implicit builder =>
import GraphDSL.Implicits._
// This is wrong, but I have no idea how to write this.
val partitioner: UniformFanOutShape[A, A] = builder.add(Partition[A](2, {
case _: B => 0
case _: C => 1
}))
new FanOutShape2(partitioner.in, partitioner.out(0).outlet, partitioner.out(1).outlet)
}
我希望使用上述方法,并使用类型参数中的 ADT 来初始化分区器。
编译器会抛出此错误。
Error:(63, 7) type mismatch;
found : akka.stream.FanOutShape2[A,A,A]
required: akka.stream.FanOutShape2[A,B,C]
new FanOutShape2(partitioner.in, partitioner.out(0).outlet,
partitioner.out(1).outlet)
据我了解,分区对象只有 Inlet(在本例中为 A,参数化类型。
有人知道我该如何解决这个问题吗?
【问题讨论】:
标签: scala akka akka-stream