@Override public void localParallelism(int localParallelism) { this.localParallelism = Vertex.checkLocalParallelism(localParallelism); }
/** * Sets the number of processors corresponding to this vertex that will be * created on each member. * <p> * If the value is {@value #LOCAL_PARALLELISM_USE_DEFAULT}, Jet will * determine the vertex's local parallelism during job initialization * from the global default and processor meta-supplier's preferred value. */ @Nonnull public Vertex localParallelism(int localParallelism) { this.localParallelism = checkLocalParallelism(localParallelism); return this; }
/** * Sets the local parallelism of the sink. On each member of the cluster * Jet will create this many parallel processors for the sink. To identify * each processor instance, your {@code createFn} can consult {@link * Processor.Context#totalParallelism() procContext.totalParallelism()} and {@link * Processor.Context#globalProcessorIndex() procContext.globalProcessorIndex()}. * Jet calls {@code createFn} exactly once with each {@code * globalProcessorIndex} from 0 to {@code totalParallelism - 1}. * <p> * The default value of this property is 1. */ @Nonnull public SinkBuilder<W, T> preferredLocalParallelism(int preferredLocalParallelism) { Vertex.checkLocalParallelism(preferredLocalParallelism); this.preferredLocalParallelism = preferredLocalParallelism; return this; }
private static int determineParallelism(Vertex vertex, int preferredLocalParallelism, int defaultParallelism) { int localParallelism = vertex.getLocalParallelism(); Vertex.checkLocalParallelism(preferredLocalParallelism); Vertex.checkLocalParallelism(localParallelism); return localParallelism != LOCAL_PARALLELISM_USE_DEFAULT ? localParallelism : preferredLocalParallelism != LOCAL_PARALLELISM_USE_DEFAULT ? min(preferredLocalParallelism, defaultParallelism) : defaultParallelism; }
/** * Factory method that creates a {@link ProcessorMetaSupplier} from the * supplied function that maps a cluster member address to a {@link * ProcessorSupplier}. * * @param addressToSupplier the mapping from address to ProcessorSupplier * @param preferredLocalParallelism the value to return from {@link #preferredLocalParallelism()} */ @Nonnull static ProcessorMetaSupplier of( @Nonnull DistributedFunction<? super Address, ? extends ProcessorSupplier> addressToSupplier, int preferredLocalParallelism ) { Vertex.checkLocalParallelism(preferredLocalParallelism); return new ProcessorMetaSupplier() { @Override public int preferredLocalParallelism() { return preferredLocalParallelism; } @Nonnull @Override public Function<? super Address, ? extends ProcessorSupplier> get(@Nonnull List<Address> addresses) { return addressToSupplier; } }; }