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

org.wildfly.clustering.context.CompositeContextualizer Maven / Gradle / Ivy

/*
 * Copyright The WildFly Authors
 * SPDX-License-Identifier: Apache-2.0
 */

package org.wildfly.clustering.context;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.function.Supplier;

import org.wildfly.common.function.ExceptionRunnable;
import org.wildfly.common.function.ExceptionSupplier;

/**
 * A {@link Contextualizer} decorator that creates contextual tasks from a multiple contextualizers.
 * @author Paul Ferraro
 */
public class CompositeContextualizer implements Contextualizer {

    private final List contextualizers;

    public CompositeContextualizer(Contextualizer... contextualizers) {
        this(Arrays.asList(contextualizers));
    }

    public CompositeContextualizer(List contextualizers) {
        this.contextualizers = contextualizers;
    }

    @Override
    public Runnable contextualize(Runnable runner) {
        Runnable result = runner;
        for (Contextualizer context : this.contextualizers) {
            result = context.contextualize(result);
        }
        return result;
    }

    @Override
    public  ExceptionRunnable contextualize(ExceptionRunnable runner) {
        ExceptionRunnable result = runner;
        for (Contextualizer context : this.contextualizers) {
            result = context.contextualize(result);
        }
        return result;
    }

    @Override
    public  Callable contextualize(Callable caller) {
        Callable result = caller;
        for (Contextualizer context : this.contextualizers) {
            result = context.contextualize(result);
        }
        return result;
    }

    @Override
    public  Supplier contextualize(Supplier supplier) {
        Supplier result = supplier;
        for (Contextualizer context : this.contextualizers) {
            result = context.contextualize(result);
        }
        return result;
    }

    @Override
    public  ExceptionSupplier contextualize(ExceptionSupplier supplier) {
        ExceptionSupplier result = supplier;
        for (Contextualizer context : this.contextualizers) {
            result = context.contextualize(result);
        }
        return result;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy