Search in sources :

Example 1 with SourceBufferConsumerSide

use of com.hazelcast.jet.impl.connector.ConvenientSourceP.SourceBufferConsumerSide in project hazelcast by hazelcast.

the class SourceProcessors method convenientSourceP.

/**
 * Returns a supplier of processors for a source that the user can create
 * using the {@link SourceBuilder}. This variant creates a source that
 * emits items without timestamps.
 *
 * @param createFn function that creates the source's context object
 * @param fillBufferFn function that fills Jet's buffer with items to emit
 * @param createSnapshotFn function that returns a snapshot of the context object's state
 * @param restoreSnapshotFn function that restores the context object's state from a snapshot
 * @param destroyFn function that cleans up the resources held by the context object
 * @param preferredLocalParallelism preferred local parallelism of the source vertex. Special values:
 *                                  {@value Vertex#LOCAL_PARALLELISM_USE_DEFAULT} -> use the cluster's
 *                                  default local parallelism;
 *                                  0 -> create a single processor for the entire cluster (total parallelism = 1)
 * @param isBatch true, if the fillBufferFn will call {@code buffer.close()}, that is whether
 *                the source reads a bounded or unbounded set of data
 *
 * @param <C> type of the source's context object
 * @param <T> type of items the source emits
 * @param <S> type of object saved to state snapshot
 */
@Nonnull
@SuppressWarnings("unchecked")
public static <C, T, S> ProcessorMetaSupplier convenientSourceP(@Nonnull FunctionEx<? super Context, ? extends C> createFn, @Nonnull BiConsumerEx<? super C, ? super SourceBuffer<T>> fillBufferFn, @Nonnull FunctionEx<? super C, ? extends S> createSnapshotFn, @Nonnull BiConsumerEx<? super C, ? super List<S>> restoreSnapshotFn, @Nonnull ConsumerEx<? super C> destroyFn, int preferredLocalParallelism, boolean isBatch, @Nullable Permission permission) {
    checkSerializable(createFn, "createFn");
    checkSerializable(fillBufferFn, "fillBufferFn");
    checkSerializable(destroyFn, "destroyFn");
    checkSerializable(createSnapshotFn, "createSnapshotFn");
    checkSerializable(restoreSnapshotFn, "restoreSnapshotFn");
    checkNotNegative(preferredLocalParallelism + 1, "preferredLocalParallelism must >= -1");
    ProcessorSupplier procSup = ProcessorSupplier.of(() -> new ConvenientSourceP<>(createFn, (BiConsumer<? super C, ? super SourceBufferConsumerSide<?>>) fillBufferFn, createSnapshotFn, restoreSnapshotFn, destroyFn, new SourceBufferImpl.Plain<>(isBatch), null));
    return preferredLocalParallelism != 0 ? ProcessorMetaSupplier.of(preferredLocalParallelism, permission, procSup) : ProcessorMetaSupplier.forceTotalParallelismOne(procSup, permission);
}
Also used : SourceBufferConsumerSide(com.hazelcast.jet.impl.connector.ConvenientSourceP.SourceBufferConsumerSide) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) BiConsumer(java.util.function.BiConsumer) Nonnull(javax.annotation.Nonnull)

Example 2 with SourceBufferConsumerSide

use of com.hazelcast.jet.impl.connector.ConvenientSourceP.SourceBufferConsumerSide in project hazelcast by hazelcast.

the class SourceProcessors method convenientTimestampedSourceP.

/**
 * Returns a supplier of processors for a source that the user can create
 * using the {@link SourceBuilder}. This variant creates a source that
 * emits timestamped events.
 *
 * @param createFn function that creates the source's context object
 * @param fillBufferFn function that fills Jet's buffer with items to emit
 * @param eventTimePolicy parameters for watermark generation
 * @param createSnapshotFn function that returns a snapshot of the context object's state
 * @param restoreSnapshotFn function that restores the context object's state from a snapshot
 * @param destroyFn function that cleans up the resources held by the context object
 * @param preferredLocalParallelism preferred local parallelism of the source vertex. Special values:
 *                                  {@value Vertex#LOCAL_PARALLELISM_USE_DEFAULT} ->
 *                                  use the cluster's default local parallelism;
 *                                  0 -> create a single processor for the entire cluster (total parallelism = 1)
 *
 * @param <C> type of the context object
 * @param <T> type of items the source emits
 * @param <S> type of the object saved to state snapshot
 */
@Nonnull
@SuppressWarnings("unchecked")
public static <C, T, S> ProcessorMetaSupplier convenientTimestampedSourceP(@Nonnull FunctionEx<? super Context, ? extends C> createFn, @Nonnull BiConsumerEx<? super C, ? super TimestampedSourceBuffer<T>> fillBufferFn, @Nonnull EventTimePolicy<? super T> eventTimePolicy, @Nonnull FunctionEx<? super C, ? extends S> createSnapshotFn, @Nonnull BiConsumerEx<? super C, ? super List<S>> restoreSnapshotFn, @Nonnull ConsumerEx<? super C> destroyFn, int preferredLocalParallelism) {
    checkSerializable(createFn, "createFn");
    checkSerializable(fillBufferFn, "fillBufferFn");
    checkSerializable(destroyFn, "destroyFn");
    checkSerializable(createSnapshotFn, "createSnapshotFn");
    checkSerializable(restoreSnapshotFn, "restoreSnapshotFn");
    checkNotNegative(preferredLocalParallelism + 1, "preferredLocalParallelism must >= -1");
    ProcessorSupplier procSup = ProcessorSupplier.of(() -> new ConvenientSourceP<>(createFn, (BiConsumer<? super C, ? super SourceBufferConsumerSide<?>>) fillBufferFn, createSnapshotFn, restoreSnapshotFn, destroyFn, new SourceBufferImpl.Timestamped<>(), eventTimePolicy));
    return preferredLocalParallelism > 0 ? ProcessorMetaSupplier.of(preferredLocalParallelism, procSup) : ProcessorMetaSupplier.forceTotalParallelismOne(procSup);
}
Also used : SourceBufferConsumerSide(com.hazelcast.jet.impl.connector.ConvenientSourceP.SourceBufferConsumerSide) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) BiConsumer(java.util.function.BiConsumer) Nonnull(javax.annotation.Nonnull)

Aggregations

ProcessorSupplier (com.hazelcast.jet.core.ProcessorSupplier)2 SourceBufferConsumerSide (com.hazelcast.jet.impl.connector.ConvenientSourceP.SourceBufferConsumerSide)2 BiConsumer (java.util.function.BiConsumer)2 Nonnull (javax.annotation.Nonnull)2