我正在使用Akka制作文件传输系统。我看文件已经有一段时间了。当前的进度状态是Actor2收到了Actor1发送的文件并将其写入Actor2的本地系统(Actor1 =发送者,Actor2 =接收者)。
但是我找不到一种方法来知道我在写时实时接收了多少字节。
我测试了它,事实证明,使用runWith
API,可以在本地编写文件。使用runForeach
API,可以实时传递多少字节。但是,如果同时创建这两个文件,则无法写入文件。
这是我的简单资料。请给我一些建议。
public static Behavior<Command> create() {
return Behaviors.setup(context -> {
context.getLog().info("Registering myself with receptionist");
context.getSystem().receptionist().tell(Receptionist.register(RECEIVER_SERVICE_KEY, context.getSelf().narrow()));
Materializer mat = Materializer.createMaterializer(context);
return Behaviors.receive(Command.class)
.onMessage(TransferFile.class, command -> {
command.sourceRef.getSource().runWith(FileIO.toPath(Paths.get("test.pptx")), mat);
//command.replyTo.tell(new FileTransfered("filename", 1024));
command.sourceRef.getSource().runForeach(f -> System.out.println(f.size()), mat);
return Behaviors.same();
}).build();
});
}
使用BroadcastHub
允许BroadcastHub
的多个使用者:
Source