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

com.hazelcast.jet.impl.util.WrappingProcessorSupplier Maven / Gradle / Ivy

There is a newer version: 4.5.4
Show newest version
/*
 * Copyright (c) 2008-2018, 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.impl.util;

import com.hazelcast.jet.core.Processor;
import com.hazelcast.jet.core.ProcessorSupplier;
import com.hazelcast.jet.function.DistributedFunction;

import javax.annotation.Nonnull;
import java.util.Collection;

import static java.util.stream.Collectors.toList;

/**
 * A {@link ProcessorSupplier} which wraps another {@code ProcessorSupplier}
 * with one that will wrap its processors using {@code wrapperSupplier}.
 */
public final class WrappingProcessorSupplier implements ProcessorSupplier {
    private ProcessorSupplier wrapped;
    private DistributedFunction wrapperSupplier;

    public WrappingProcessorSupplier(ProcessorSupplier wrapped,
                                     DistributedFunction wrapperSupplier
    ) {
        this.wrapped = wrapped;
        this.wrapperSupplier = wrapperSupplier;
    }

    @Nonnull
    @Override
    public Collection get(int count) {
        Collection processors = wrapped.get(count);
        return processors.stream()
                         .map(wrapperSupplier)
                         .collect(toList());
    }

    @Override
    public void init(@Nonnull Context context) {
        wrapped.init(context);
    }

    @Override
    public void close(Throwable error) {
        wrapped.close(error);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy