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

org.jboss.as.clustering.controller.CompositeServiceBuilder Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 34.0.0.Final
Show newest version
/*
 * 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();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy