org.wildfly.clustering.singleton.server.AbstractSingletonServiceBuilder Maven / Gradle / Ivy
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/
package org.wildfly.clustering.singleton.server;
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.wildfly.clustering.singleton.election.SingletonElectionListener;
import org.wildfly.clustering.singleton.election.SingletonElectionPolicy;
import org.wildfly.clustering.singleton.service.SingletonServiceBuilder;
import org.wildfly.clustering.singleton.service.SingletonServiceController;
/**
* @author Paul Ferraro
*/
public abstract class AbstractSingletonServiceBuilder extends DelegatingServiceBuilder implements SingletonServiceBuilder {
private final SingletonServiceBuilderContext context;
public AbstractSingletonServiceBuilder(ServiceBuilder builder, SingletonServiceBuilderContext context) {
super(builder);
context.getCommandDispatcherFactoryDependency().accept(builder);
context.getServiceProviderRegistrarDependency().accept(builder);
this.context = context;
}
@Override
public abstract SingletonServiceBuilder setInstance(Service service);
@Override
public abstract SingletonServiceController install();
@Override
public SingletonServiceBuilder requireQuorum(int quorum) {
this.context.setQuorum(quorum);
return this;
}
@Override
public SingletonServiceBuilder withElectionPolicy(SingletonElectionPolicy policy) {
this.context.setElectionPolicy(policy);
return this;
}
@Override
public SingletonServiceBuilder withElectionListener(SingletonElectionListener listener) {
this.context.setElectionListener(listener);
return this;
}
@Override
public SingletonServiceBuilder addListener(LifecycleListener listener) {
this.getDelegate().addListener(listener);
return this;
}
@Override
public SingletonServiceBuilder setInitialMode(ServiceController.Mode mode) {
this.getDelegate().setInitialMode(mode);
return this;
}
}