org.jboss.as.clustering.context.CompositeContextualizer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of wildfly-clustering-common Show documentation
Show all versions of wildfly-clustering-common Show documentation
The code in this module is not explicitly related to clustering, but rather contains resuable code used by clustering modules
and any modules that integrate with clustering.
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.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;
}
}