Search in sources :

Example 1 with BeamFnDataGrpcMultiplexer

use of org.apache.beam.sdk.fn.data.BeamFnDataGrpcMultiplexer in project beam by apache.

the class GrpcDataService method data.

@Override
public StreamObserver<BeamFnApi.Elements> data(final StreamObserver<BeamFnApi.Elements> outboundElementObserver) {
    LOG.info("Beam Fn Data client connected.");
    BeamFnDataGrpcMultiplexer multiplexer = new BeamFnDataGrpcMultiplexer(null, outboundObserverFactory, inbound -> outboundElementObserver);
    // First client that connects completes this future.
    if (!connectedClient.set(multiplexer)) {
        additionalMultiplexers.offer(multiplexer);
    }
    try {
        // incoming messages are sent to the single multiplexer instance.
        return connectedClient.get().getInboundObserver();
    } catch (InterruptedException | ExecutionException e) {
        throw new RuntimeException(e);
    }
}
Also used : BeamFnDataGrpcMultiplexer(org.apache.beam.sdk.fn.data.BeamFnDataGrpcMultiplexer) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with BeamFnDataGrpcMultiplexer

use of org.apache.beam.sdk.fn.data.BeamFnDataGrpcMultiplexer in project beam by apache.

the class BeamFnDataGrpcService method data.

@Override
public StreamObserver<Elements> data(final StreamObserver<Elements> outboundObserver) {
    String sdkWorkerId = headerAccessor.getSdkWorkerId();
    LOG.info("Beam Fn Data client connected for clientId {}", sdkWorkerId);
    BeamFnDataGrpcMultiplexer multiplexer = new BeamFnDataGrpcMultiplexer(apiServiceDescriptor, OutboundObserverFactory.trivial(), (StreamObserver<BeamFnApi.Elements> inboundObserver) -> streamObserverFactory.apply(outboundObserver));
    // First client that connects completes this future
    getClientFuture(sdkWorkerId).complete(multiplexer);
    try {
        // incoming messages are sent to the single multiplexer instance.
        return getClientFuture(sdkWorkerId).get().getInboundObserver();
    } catch (InterruptedException | ExecutionException e) {
        throw new RuntimeException(e);
    }
}
Also used : StreamObserver(org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver) BeamFnDataGrpcMultiplexer(org.apache.beam.sdk.fn.data.BeamFnDataGrpcMultiplexer) BeamFnApi(org.apache.beam.model.fnexecution.v1.BeamFnApi) ByteString(org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

ExecutionException (java.util.concurrent.ExecutionException)2 BeamFnDataGrpcMultiplexer (org.apache.beam.sdk.fn.data.BeamFnDataGrpcMultiplexer)2 BeamFnApi (org.apache.beam.model.fnexecution.v1.BeamFnApi)1 ByteString (org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString)1 StreamObserver (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver)1