/** * Creates a vertex from a {@code ProcessorSupplier}. * * @param name the unique name of the vertex. This name identifies the vertex in the snapshot * @param processorSupplier the supplier of {@code Processor} instances which will be used on all members */ public Vertex(@Nonnull String name, @Nonnull ProcessorSupplier processorSupplier) { this(name, ProcessorMetaSupplier.of(processorSupplier)); }
/** * Factory method that wraps the given {@code Supplier<Processor>} * and uses it as the supplier of all {@code Processor} instances. * Specifically, returns a meta-supplier that will always return the * result of calling {@link ProcessorSupplier#of(DistributedSupplier)}. * The {@link #preferredLocalParallelism()} of the meta-supplier will be * {@link Vertex#LOCAL_PARALLELISM_USE_DEFAULT}. */ @Nonnull static ProcessorMetaSupplier of(@Nonnull DistributedSupplier<? extends Processor> procSupplier) { return of(procSupplier, Vertex.LOCAL_PARALLELISM_USE_DEFAULT); }
/** * Wraps the provided {@code ProcessorSupplier} into a meta-supplier that * will always return it. The {@link #preferredLocalParallelism()} of * the meta-supplier will be one, i.e., no local parallelization. * <p> * The parallelism will be overriden if the {@link Vertex#localParallelism(int)} is * set to a specific value. */ @Nonnull static ProcessorMetaSupplier preferLocalParallelismOne(@Nonnull ProcessorSupplier supplier) { return of(supplier, 1); }
/** * Factory method that wraps the given {@code ProcessorSupplier} and * returns the same instance for each given {@code Address}. * * @param procSupplier the processor supplier * @param preferredLocalParallelism the value to return from {@link #preferredLocalParallelism()} */ @Nonnull static ProcessorMetaSupplier of(@Nonnull ProcessorSupplier procSupplier, int preferredLocalParallelism) { return of((Address x) -> procSupplier, preferredLocalParallelism); }
/** * Wraps the provided {@code ProcessorSupplier} into a meta-supplier that * will always return it. The {@link #preferredLocalParallelism()} of * the meta-supplier will be {@link Vertex#LOCAL_PARALLELISM_USE_DEFAULT}. */ @Nonnull static ProcessorMetaSupplier of(@Nonnull ProcessorSupplier procSupplier) { return of(procSupplier, Vertex.LOCAL_PARALLELISM_USE_DEFAULT); }
/** * Factory method that creates a {@link ProcessorMetaSupplier} from the * supplied function that maps a cluster member address to a {@link * ProcessorSupplier}. The {@link #preferredLocalParallelism()} of * the meta-supplier will be {@link Vertex#LOCAL_PARALLELISM_USE_DEFAULT}. */ @Nonnull static ProcessorMetaSupplier of( @Nonnull DistributedFunction<? super Address, ? extends ProcessorSupplier> addressToSupplier ) { return of(addressToSupplier, Vertex.LOCAL_PARALLELISM_USE_DEFAULT); }
/** * Creates a vertex from a {@code Supplier<Processor>}. * <p> * This is useful for vertices where all the {@code Processor} instances * will be instantiated the same way. * <p> * <strong>NOTE:</strong> this constructor should not be abused with a stateful * implementation which produces a different processor each time. In such a * case the full {@code ProcessorSupplier} type should be implemented. * * @param name the unique name of the vertex. This name identifies the vertex in the snapshot * @param processorSupplier the simple, parameterless supplier of {@code Processor} instances */ public Vertex(@Nonnull String name, @Nonnull DistributedSupplier<? extends Processor> processorSupplier) { this(name, ProcessorMetaSupplier.of(processorSupplier)); }
/** * @param supplier a processor supplier create processor instances */ public static TestSupport verifyProcessor(@Nonnull ProcessorSupplier supplier) { return new TestSupport(ProcessorMetaSupplier.of(supplier)); }
/** * Returns a supplier of processors for * {@link KafkaSinks#kafka(Properties, DistributedFunction)}. */ public static <T, K, V> ProcessorMetaSupplier writeKafkaP( @Nonnull Properties properties, @Nonnull DistributedFunction<? super T, ? extends ProducerRecord<K, V>> toRecordFn ) { return ProcessorMetaSupplier.of(new WriteKafkaP.Supplier<T, K, V>(properties, toRecordFn), 2); } }
/** * Variant of {@link #preferLocalParallelismOne(ProcessorSupplier)} where * the supplied {@code DistributedSupplier<Processor>} will be * wrapped into a {@link ProcessorSupplier}. */ @Nonnull static ProcessorMetaSupplier preferLocalParallelismOne( @Nonnull DistributedSupplier<? extends Processor> procSupplier ) { return of(ProcessorSupplier.of(procSupplier), 1); }
/** * @param supplier a processor supplier create processor instances */ public static TestSupport verifyProcessor(@Nonnull DistributedSupplier<Processor> supplier) { return new TestSupport(ProcessorMetaSupplier.of(supplier)); }
/** * Returns a supplier of processors for * {@link KafkaSinks#kafka(Properties, DistributedFunction)}. */ public static <T, K, V> ProcessorMetaSupplier writeKafkaP( @Nonnull Properties properties, @Nonnull DistributedFunction<? super T, ? extends ProducerRecord<K, V>> toRecordFn ) { return ProcessorMetaSupplier.of(new WriteKafkaP.Supplier<T, K, V>(properties, toRecordFn), 2); } }
public PlannerVertex addVertex(Transform transform, String name, int localParallelism, DistributedSupplier<Processor> procSupplier) { return addVertex(transform, name, localParallelism, ProcessorMetaSupplier.of(procSupplier)); }
public PlannerVertex addVertex(Transform transform, String name, int localParallelism, ProcessorSupplier procSupplier) { return addVertex(transform, name, localParallelism, ProcessorMetaSupplier.of(procSupplier)); }
/** * Private API. Use {@link * com.hazelcast.jet.core.processor.SourceProcessors#streamFilesP} instead. */ @Nonnull public static ProcessorMetaSupplier metaSupplier( @Nonnull String watchedDirectory, @Nonnull String charset, @Nonnull String glob, boolean sharedFileSystem, @Nonnull DistributedBiFunction<? super String, ? super String, ?> mapOutputFn ) { return ProcessorMetaSupplier.of(() -> new StreamFilesP<>(watchedDirectory, Charset.forName(charset), glob, sharedFileSystem, mapOutputFn), 2); }
/** * Returns a supplier of processors for {@link Sources#jmsQueueBuilder}. */ @Nonnull public static <T> ProcessorMetaSupplier streamJmsQueueP( @Nonnull DistributedSupplier<? extends Connection> connectionSupplier, @Nonnull DistributedFunction<? super Connection, ? extends Session> sessionFn, @Nonnull DistributedFunction<? super Session, ? extends MessageConsumer> consumerFn, @Nonnull DistributedConsumer<? super Session> flushFn, @Nonnull DistributedFunction<? super Message, ? extends T> projectionFn, @Nonnull EventTimePolicy<? super T> eventTimePolicy) { return ProcessorMetaSupplier.of( StreamJmsP.supplier(connectionSupplier, sessionFn, consumerFn, flushFn, projectionFn, eventTimePolicy), StreamJmsP.PREFERRED_LOCAL_PARALLELISM); }
/** * Private API. Use {@link SourceProcessors#readFilesP} instead. */ public static <W, T> ProcessorMetaSupplier metaSupplier( @Nonnull String directory, @Nonnull String glob, boolean sharedFileSystem, @Nonnull DistributedFunction<? super Path, ? extends Stream<W>> readFileFn, @Nonnull DistributedBiFunction<? super String, ? super W, ? extends T> mapOutputFn ) { return ProcessorMetaSupplier.of(() -> new ReadFilesP<>( directory, glob, sharedFileSystem, readFileFn, mapOutputFn), 2); } }
/** * Factory method that wraps the given {@code Supplier<Processor>} * and uses it as the supplier of all {@code Processor} instances. * Specifically, returns a meta-supplier that will always return the * result of calling {@link ProcessorSupplier#of(DistributedSupplier)}. * * @param procSupplier the supplier of processors * @param preferredLocalParallelism the value to return from {@link #preferredLocalParallelism()} */ @Nonnull static ProcessorMetaSupplier of( @Nonnull DistributedSupplier<? extends Processor> procSupplier, int preferredLocalParallelism ) { return of(ProcessorSupplier.of(procSupplier), preferredLocalParallelism); }
/** * Private API. Use {@link SinkProcessors#writeJmsQueueP} or {@link * SinkProcessors#writeJmsTopicP} instead */ public static <T> ProcessorMetaSupplier supplier( DistributedSupplier<? extends Connection> connectionSupplier, DistributedFunction<? super Connection, ? extends Session> sessionF, DistributedBiFunction<? super Session, T, ? extends Message> messageFn, DistributedBiConsumer<? super MessageProducer, ? super Message> sendFn, DistributedConsumer<? super Session> flushFn, String name, boolean isTopic ) { return ProcessorMetaSupplier.of( new Supplier<>(connectionSupplier, sessionF, messageFn, sendFn, flushFn, name, isTopic), PREFERRED_LOCAL_PARALLELISM); }
/** * Creates and returns the {@link Sink} with the components you supplied to * this builder. */ @Nonnull public Sink<T> build() { Preconditions.checkNotNull(receiveFn, "receiveFn must be set"); DistributedSupplier<Processor> supplier = writeBufferedP(createFn, receiveFn, flushFn, destroyFn); return new SinkImpl<>(name, ProcessorMetaSupplier.of(supplier, preferredLocalParallelism)); } }