All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hazelcast.jet.aggregate.AggregateOperation2 Maven / Gradle / Ivy

There is a newer version: 5.5.0
Show newest version
/*
 * Copyright (c) 2008-2021, Hazelcast, Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.hazelcast.jet.aggregate;

import com.hazelcast.function.BiConsumerEx;
import com.hazelcast.function.FunctionEx;
import com.hazelcast.jet.core.Processor;

import javax.annotation.Nonnull;

/**
 * Specialization of {@code AggregateOperation} (refer to its {@linkplain
 * AggregateOperation extensive documentation}) to the "arity-2" case with
 * two data streams being aggregated over. {@link AggregateOperations}
 * contains factories for the built-in implementations and you can create
 * your own using the {@linkplain AggregateOperation#withCreate aggregate
 * operation builder}.
 * 

* This example constructs an operation that sums up {@code long} values * from two streams: *

{@code
 * AggregateOperation2 aggrOp = AggregateOperation
 *     .withCreate(LongAccumulator::new)
 *     .andAccumulate0(LongAccumulator::add)
 *     .andAccumulate1(LongAccumulator::add)
 *     .andFinish(LongAccumulator::get);
 * }
*

* All the functions must be stateless and {@linkplain * Processor#isCooperative() cooperative}. * * @param the type of item in stream-0 * @param the type of item in stream-1 * @param the type of the accumulator * @param the type of the aggregation result * * @since Jet 3.0 */ public interface AggregateOperation2 extends AggregateOperation { /** * A primitive that updates the accumulator state to account for a new * item coming from stream-0. *

* The consumer must be stateless and {@linkplain Processor#isCooperative() * cooperative}. */ @Nonnull BiConsumerEx accumulateFn0(); /** * A primitive that updates the accumulator state to account for a new * item coming from stream-1. *

* The consumer must be stateless and {@linkplain Processor#isCooperative() * cooperative}. */ @Nonnull BiConsumerEx accumulateFn1(); /** * Returns a copy of this aggregate operation, but with the {@code * accumulate} primitive at index 0 replaced with the one supplied here. *

* The consumer must be stateless and {@linkplain Processor#isCooperative() * cooperative}. */ @Nonnull AggregateOperation2 withAccumulateFn0( @Nonnull BiConsumerEx newAccFn0 ); /** * Returns a copy of this aggregate operation, but with the {@code * accumulate} primitive at index 1 replaced with the one supplied here. *

* The consumer must be stateless and {@linkplain Processor#isCooperative() * cooperative}. */ @Nonnull AggregateOperation2 withAccumulateFn1( @Nonnull BiConsumerEx newAccFn1 ); // Narrows the return type @Nonnull @Override AggregateOperation2 withIdentityFinish(); // Narrows the return type @Nonnull @Override AggregateOperation2 andThen(FunctionEx thenFn); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy