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

io.dstream.support.AbstractPartitionedStreamProducingSourceSupplier Maven / Gradle / Ivy

/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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 io.dstream.support;

import java.util.Properties;
import java.util.stream.Stream;

/**
 * Primary goal of this implementation of {@link SourceSupplier} is to provide sub-classes with
 * current partition identifier enabling them to supply the correct {@link Stream}.
 * It does so by providing an additional {@link #doGet(int)} method which is called by
 * {@link #get()} after partition identifier is determined. It also makes {@link #get()}
 * 'final' ensuring there is no confusing which method must be implemented by sub-classes.
 *
 * @param  the type of elements in the returned {@link Stream}
 */
public abstract class AbstractPartitionedStreamProducingSourceSupplier extends SourceSupplier>{

	private static final long serialVersionUID = -7671596834377215486L;

	/**
	 *
	 */
	public AbstractPartitionedStreamProducingSourceSupplier(Properties executionConfig, String pipelineName) {
		super(executionConfig, pipelineName);
	}

	/**
	 * Returns the {@link Stream} representing current partition.
	 */
	@Override
	public final Stream get() {
		return this.doGet(PartitionIdHelper.getPartitionId());
	}

	/**
	 * Returns the {@link Stream} representing partition identified by the 'partitionId'.
	 * @param partitionId partition identifier
	 * @return {@link Stream} representing partition identified by the 'partitionId'.
	 */
	protected abstract Stream doGet(int partitionId) ;
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy