Example usage for com.google.common.graph Network adjacentNodes

List of usage examples for com.google.common.graph Network adjacentNodes

Introduction

In this page you can find the example usage for com.google.common.graph Network adjacentNodes.

Prototype

@Override
Set<N> adjacentNodes(Object node);

Source Link

Document

Returns the nodes which have an #incidentEdges(Object) incident edge in common with node in this graph.

Usage

From source file:org.apache.beam.runners.dataflow.worker.BeamFnMapTaskExecutorFactory.java

private Function<Node, Node> createOperationTransformForGrpcPortNodes(final Network<Node, Edge> network,
        final FnDataService beamFnDataService, final OperationContext context) {
    return new TypeSafeNodeFunction<RemoteGrpcPortNode>(RemoteGrpcPortNode.class) {
        @Override/* w  w w. j a  v a  2s  .  c  om*/
        public Node typedApply(RemoteGrpcPortNode input) {
            RegisterAndProcessBundleOperation registerFnOperation = (RegisterAndProcessBundleOperation) Iterables
                    .getOnlyElement(Iterables.filter(network.adjacentNodes(input), OperationNode.class))
                    .getOperation();

            // The coder comes from the one and only adjacent output node
            Coder<?> coder = Iterables
                    .getOnlyElement(Iterables.filter(network.adjacentNodes(input), OutputReceiverNode.class))
                    .getCoder();
            // We figure out whether we are outputting some where if the output node is a
            // successor.
            Iterable<OutputReceiverNode> outputReceiverNodes = Iterables.filter(network.successors(input),
                    OutputReceiverNode.class);
            Operation operation;
            if (outputReceiverNodes.iterator().hasNext()) {
                Target target = Target.newBuilder()
                        .setPrimitiveTransformReference(input.getPrimitiveTransformId())
                        .setName(input.getOutputId()).build();
                OutputReceiver[] outputReceivers = new OutputReceiver[] {
                        Iterables.getOnlyElement(outputReceiverNodes).getOutputReceiver() };

                operation = new RemoteGrpcPortReadOperation<>(beamFnDataService, target,
                        registerFnOperation::getProcessBundleInstructionId, (Coder) coder, outputReceivers,
                        context);
            } else {
                Target target = Target.newBuilder()
                        .setPrimitiveTransformReference(input.getPrimitiveTransformId())
                        .setName(input.getInputId()).build();

                operation = new RemoteGrpcPortWriteOperation<>(beamFnDataService, target,
                        registerFnOperation::getProcessBundleInstructionId, (Coder) coder, context);
            }
            return OperationNode.create(operation);
        }
    };
}