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);
}
}
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);
}
}
Aggregations