package com.atlassian.bitbucket.mesh.management;

import com.atlassian.bitbucket.mesh.gprc.SynchronizedStreamObserver;
import com.atlassian.bitbucket.mesh.rpc.v1.RpcSidebandFollowerFragment;
import io.grpc.stub.StreamObserver;

import javax.annotation.Nonnull;

class ObserverSidebandSender implements SidebandSender {

    private final StreamObserver<RpcSidebandFollowerFragment> responseObserver;

    ObserverSidebandSender(StreamObserver<RpcSidebandFollowerFragment> responseObserver) {
        this.responseObserver = new SynchronizedStreamObserver<>(responseObserver);
    }

    @Override
    public void close() {
        responseObserver.onCompleted();
    }

    @Override
    public void send(@Nonnull RpcSidebandFollowerFragment fragment) {
        responseObserver.onNext(fragment);
    }
}
