我正在使用JDK 9 Flow API创建用户事件系统,所以我有一个房间(扩展了上面的UserSubscriver
类),它可能有很多用户,每个用户都可以提供(调度)随时更新。
public abstract class UserSubscriver implements Flow.Subscriber<Notification> {
private Flow.Subscription subscription;
@Override
public void onSubscribe(final Flow.Subscription subscription) {
this.subscription = subscription;
subscription.request(1);
}
@Override
public void onError(final Throwable throwable) {
// ...
}
@Override
public void onNext(final Notification notification) {
// ...
subscription.request(1);
}
@Override
public void onComplete() {
// How can I know who was the publisher of this?
}
}
用户类:
public class User extends SubmissionPublisher<Notification> {
....
public int offer(Notification item) {
return super.offer(item, (sub, msg) -> false);
}
}
在onUpdate
我可以收到任何参数,因此我可以收到更新的发布者,但onComplete
上没有参数。
我如何知道谁是onComplete
活动的发布者?