org.jboss.as.clustering.controller.CompositeServiceBuilder 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.
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/
package org.jboss.as.clustering.controller;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.jboss.msc.Service;
import org.jboss.msc.service.DelegatingServiceBuilder;
import org.jboss.msc.service.LifecycleListener;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
/**
* A {@link ServiceBuilder} facade for installing a set of {@link ServiceBuilder} instances.
* @author Paul Ferraro
*/
public class CompositeServiceBuilder extends DelegatingServiceBuilder {
private final Iterable> builders;
public CompositeServiceBuilder(Iterable> builders) {
super(null);
this.builders = builders;
}
@Override
public ServiceBuilder setInitialMode(ServiceController.Mode mode) {
for (ServiceBuilder> builder : this.builders) {
builder.setInitialMode(mode);
}
return this;
}
@Override
public ServiceBuilder addListener(LifecycleListener listener) {
for (ServiceBuilder> builder : this.builders) {
builder.addListener(listener);
}
return this;
}
@SuppressWarnings("unchecked")
@Override
public ServiceController install() {
List> controllers = new LinkedList<>();
for (ServiceBuilder> builder : this.builders) {
controllers.add(builder.install());
}
return !controllers.isEmpty() ? (ServiceController) controllers.get(0) : null;
}
@Override
public Supplier requires(ServiceName name) {
throw new UnsupportedOperationException();
}
@Override
public Consumer provides(ServiceName... names) {
throw new UnsupportedOperationException();
}
@Override
public ServiceBuilder setInstance(Service service) {
throw new UnsupportedOperationException();
}
}