Java Flow.Subscriber - 如何获得onComplete的发布者?

时间:2018-03-01 13:53:55

标签: java publish-subscribe java-9 java.util.concurrent java-flow

我正在使用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活动的发布者?

0 个答案:

没有答案