/** * Returns a copy of this {@link ContextFactory} with the * <em>shareLocally</em> flag set. If the pipeline doesn't have grouping, * there will be: * <ul> * <li>one context object per local processor, if flag is disabled * <li>one context object per member, if flag is enabled. Make * sure the context object is <em>thread-safe</em> in this case. * </ul> * * @return a copy of this factory with the {@code isSharedLocally} flag set. */ @Nonnull public ContextFactory<C> shareLocally() { return new ContextFactory<>(createFn, destroyFn, isCooperative, true, maxPendingCallsPerProcessor, orderedAsyncResponses); }
/** * Returns a copy of this {@link ContextFactory} with the * <em>isCooperative</em> flag set to {@code false}. The context factory is * cooperative by default. Call this method if your transform function * doesn't follow the {@linkplain Processor#isCooperative() cooperative * processor contract}, that is if it waits for IO, blocks for * synchronization, takes too long to complete etc. If you intend to use * the factory for an async operation, you also typically can use a * cooperative processor. Cooperative processors offer higher performance. * * @return a copy of this factory with the {@code isCooperative} flag set * to {@code false}. */ @Nonnull public ContextFactory<C> nonCooperative() { return new ContextFactory<>(createFn, destroyFn, false, isSharedLocally, maxPendingCallsPerProcessor, orderedAsyncResponses); }
return new ContextFactory<>(createFn, destroyFn, isCooperative, isSharedLocally, maxPendingCallsPerProcessor, false);
/** * Returns a copy of this {@link ContextFactory} with the destroy-function * replaced with the given function. * <p> * The destroy function is called at the end of the job to destroy all * created context objects. * * @param destroyFn the function to destroy user-defined context * @return a copy of this factory with the supplied destroy-function */ @Nonnull public ContextFactory<C> withDestroyFn(@Nonnull DistributedConsumer<? super C> destroyFn) { checkSerializable(destroyFn, "destroyFn"); return new ContextFactory<>(createFn, destroyFn, isCooperative, isSharedLocally, maxPendingCallsPerProcessor, orderedAsyncResponses); }
/** * Returns a copy of this {@link ContextFactory} with the * <em>maxPendingCallsPerProcessor</em> property set to the given value. Jet * will execute at most this many concurrent async operations per processor * and will apply backpressure to the upstream. * <p> * If you use the same context factory on multiple pipeline stages, each * stage will count the pending calls independently. * <p> * This value is ignored when the {@code ContextFactory} is used in a * synchronous transformation. * <p> * Default value is {@value #MAX_PENDING_CALLS_DEFAULT}. * * @return a copy of this factory with the {@code maxPendingCallsPerProcessor} * property set. */ @Nonnull public ContextFactory<C> maxPendingCallsPerProcessor(int maxPendingCallsPerProcessor) { checkPositive(maxPendingCallsPerProcessor, "maxPendingCallsPerProcessor must be >= 1"); return new ContextFactory<>(createFn, destroyFn, isCooperative, isSharedLocally, maxPendingCallsPerProcessor, orderedAsyncResponses); }
/** * Creates a new {@link ContextFactory} with the given create-function. * * @param createContextFn the function to create new context object, given * a JetInstance * @param <C> the user-defined context object type * @return a new factory instance */ @Nonnull public static <C> ContextFactory<C> withCreateFn( @Nonnull DistributedFunction<JetInstance, ? extends C> createContextFn ) { checkSerializable(createContextFn, "createContextFn"); return new ContextFactory<>( createContextFn, DistributedConsumer.noop(), COOPERATIVE_DEFAULT, SHARE_LOCALLY_DEFAULT, MAX_PENDING_CALLS_DEFAULT, ORDERED_ASYNC_RESPONSES_DEFAULT); }