Search in sources :

Example 1 with NamePreference

use of org.wildfly.clustering.singleton.election.NamePreference in project wildfly by wildfly.

the class ElectionPolicyBuilder method configure.

@Override
public Builder<SingletonElectionPolicy> configure(OperationContext context, ModelNode model) throws OperationFailedException {
    this.preferences.clear();
    this.dependencies.clear();
    ModelNodes.optionalList(SOCKET_BINDING_PREFERENCES.resolveModelAttribute(context, model)).ifPresent(bindings -> {
        bindings.stream().map(ModelNode::asString).forEach(bindingName -> {
            InjectedValueDependency<OutboundSocketBinding> binding = new InjectedValueDependency<>(CommonUnaryRequirement.OUTBOUND_SOCKET_BINDING.getServiceName(context, bindingName), OutboundSocketBinding.class);
            this.preferences.add(new OutboundSocketBindingPreference(binding));
            this.dependencies.add(binding);
        });
    });
    ModelNodes.optionalList(NAME_PREFERENCES.resolveModelAttribute(context, model)).ifPresent(names -> {
        names.stream().map(ModelNode::asString).forEach(name -> this.preferences.add(new NamePreference(name)));
    });
    return this;
}
Also used : OutboundSocketBindingPreference(org.wildfly.extension.clustering.singleton.election.OutboundSocketBindingPreference) NamePreference(org.wildfly.clustering.singleton.election.NamePreference) OutboundSocketBinding(org.jboss.as.network.OutboundSocketBinding) InjectedValueDependency(org.wildfly.clustering.service.InjectedValueDependency)

Example 2 with NamePreference

use of org.wildfly.clustering.singleton.election.NamePreference in project wildfly by wildfly.

the class SingletonServiceActivator method install.

private static void install(ServiceTarget target, SingletonServiceBuilderFactory factory, ServiceName name, String preferredNode) {
    InjectedValue<Group> group = new InjectedValue<>();
    NodeService service = new NodeService(group);
    factory.createSingletonServiceBuilder(name, service).electionPolicy(new PreferredSingletonElectionPolicy(new SimpleSingletonElectionPolicy(), new NamePreference(preferredNode))).build(target).addDependency(ServiceName.JBOSS.append("clustering", "group", "default"), Group.class, group).install();
}
Also used : InjectedValue(org.jboss.msc.value.InjectedValue) Group(org.wildfly.clustering.group.Group) NamePreference(org.wildfly.clustering.singleton.election.NamePreference) NodeService(org.jboss.as.test.clustering.cluster.singleton.service.NodeService) SimpleSingletonElectionPolicy(org.wildfly.clustering.singleton.election.SimpleSingletonElectionPolicy) PreferredSingletonElectionPolicy(org.wildfly.clustering.singleton.election.PreferredSingletonElectionPolicy)

Example 3 with NamePreference

use of org.wildfly.clustering.singleton.election.NamePreference in project wildfly by wildfly.

the class ElectionPolicyServiceConfigurator method configure.

@Override
public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException {
    List<ModelNode> socketBindingPreferences = SOCKET_BINDING_PREFERENCES.resolveModelAttribute(context, model).asListOrEmpty();
    List<ModelNode> namePreferences = NAME_PREFERENCES.resolveModelAttribute(context, model).asListOrEmpty();
    List<Preference> preferences = new ArrayList<>(socketBindingPreferences.size() + namePreferences.size());
    List<Dependency> dependencies = new ArrayList<>(socketBindingPreferences.size());
    for (ModelNode preference : socketBindingPreferences) {
        SupplierDependency<OutboundSocketBinding> binding = new ServiceSupplierDependency<>(CommonUnaryRequirement.OUTBOUND_SOCKET_BINDING.getServiceName(context, preference.asString()));
        preferences.add(new OutboundSocketBindingPreference(binding));
        dependencies.add(binding);
    }
    for (ModelNode preference : namePreferences) {
        preferences.add(new NamePreference(preference.asString()));
    }
    this.dependencies = dependencies;
    this.preferences = preferences;
    return this;
}
Also used : OutboundSocketBindingPreference(org.wildfly.extension.clustering.singleton.election.OutboundSocketBindingPreference) NamePreference(org.wildfly.clustering.singleton.election.NamePreference) OutboundSocketBinding(org.jboss.as.network.OutboundSocketBinding) OutboundSocketBindingPreference(org.wildfly.extension.clustering.singleton.election.OutboundSocketBindingPreference) Preference(org.wildfly.clustering.singleton.election.Preference) NamePreference(org.wildfly.clustering.singleton.election.NamePreference) ArrayList(java.util.ArrayList) SupplierDependency(org.wildfly.clustering.service.SupplierDependency) ServiceSupplierDependency(org.wildfly.clustering.service.ServiceSupplierDependency) Dependency(org.wildfly.clustering.service.Dependency) ServiceSupplierDependency(org.wildfly.clustering.service.ServiceSupplierDependency) ModelNode(org.jboss.dmr.ModelNode)

Example 4 with NamePreference

use of org.wildfly.clustering.singleton.election.NamePreference in project eap-additional-testsuite by jboss-set.

the class HATimerServiceActivator method activate.

@Override
public void activate(ServiceActivatorContext context) {
    log.info("HATimerService will be installed!");
    HATimerService service = new HATimerService();
    ServiceName factoryServiceName = SingletonServiceName.BUILDER.getServiceName("server", "default");
    ServiceController<?> factoryService = context.getServiceRegistry().getRequiredService(factoryServiceName);
    SingletonServiceBuilderFactory factory = (SingletonServiceBuilderFactory) factoryService.getValue();
    factory.createSingletonServiceBuilder(HATimerService.SINGLETON_SERVICE_NAME, service).electionPolicy(new PreferredSingletonElectionPolicy(new SimpleSingletonElectionPolicy(), new NamePreference("node1/singleton"))).build(new DelegatingServiceContainer(context.getServiceTarget(), context.getServiceRegistry())).setInitialMode(ServiceController.Mode.ACTIVE).install();
}
Also used : NamePreference(org.wildfly.clustering.singleton.election.NamePreference) SingletonServiceName(org.wildfly.clustering.singleton.SingletonServiceName) ServiceName(org.jboss.msc.service.ServiceName) SingletonServiceBuilderFactory(org.wildfly.clustering.singleton.SingletonServiceBuilderFactory) SimpleSingletonElectionPolicy(org.wildfly.clustering.singleton.election.SimpleSingletonElectionPolicy) PreferredSingletonElectionPolicy(org.wildfly.clustering.singleton.election.PreferredSingletonElectionPolicy) DelegatingServiceContainer(org.jboss.msc.service.DelegatingServiceContainer)

Example 5 with NamePreference

use of org.wildfly.clustering.singleton.election.NamePreference in project wildfly by wildfly.

the class NodeServiceActivator method install.

private static void install(ServiceTarget target, SingletonServiceBuilderFactory factory, ServiceName name, int quorum) {
    InjectedValue<Group> group = new InjectedValue<>();
    NodeService service = new NodeService(group);
    factory.createSingletonServiceBuilder(name, service).electionPolicy(new PreferredSingletonElectionPolicy(new SimpleSingletonElectionPolicy(), new NamePreference(PREFERRED_NODE))).requireQuorum(quorum).build(target).addDependency(ServiceName.parse("org.wildfly.clustering.default-group"), Group.class, group).install();
}
Also used : InjectedValue(org.jboss.msc.value.InjectedValue) Group(org.wildfly.clustering.group.Group) NamePreference(org.wildfly.clustering.singleton.election.NamePreference) SimpleSingletonElectionPolicy(org.wildfly.clustering.singleton.election.SimpleSingletonElectionPolicy) PreferredSingletonElectionPolicy(org.wildfly.clustering.singleton.election.PreferredSingletonElectionPolicy)

Aggregations

NamePreference (org.wildfly.clustering.singleton.election.NamePreference)11 PreferredSingletonElectionPolicy (org.wildfly.clustering.singleton.election.PreferredSingletonElectionPolicy)8 SimpleSingletonElectionPolicy (org.wildfly.clustering.singleton.election.SimpleSingletonElectionPolicy)8 DelegatingServiceContainer (org.jboss.msc.service.DelegatingServiceContainer)4 ServiceName (org.jboss.msc.service.ServiceName)4 SingletonServiceBuilderFactory (org.wildfly.clustering.singleton.SingletonServiceBuilderFactory)4 SingletonServiceName (org.wildfly.clustering.singleton.SingletonServiceName)4 OutboundSocketBinding (org.jboss.as.network.OutboundSocketBinding)2 InjectedValue (org.jboss.msc.value.InjectedValue)2 Group (org.wildfly.clustering.group.Group)2 Preference (org.wildfly.clustering.singleton.election.Preference)2 OutboundSocketBindingPreference (org.wildfly.extension.clustering.singleton.election.OutboundSocketBindingPreference)2 ArrayList (java.util.ArrayList)1 NodeService (org.jboss.as.test.clustering.cluster.singleton.service.NodeService)1 SingletonElectionListenerService (org.jboss.as.test.clustering.cluster.singleton.service.SingletonElectionListenerService)1 ModelNode (org.jboss.dmr.ModelNode)1 Test (org.junit.Test)1 Node (org.wildfly.clustering.group.Node)1 Dependency (org.wildfly.clustering.service.Dependency)1 InjectedValueDependency (org.wildfly.clustering.service.InjectedValueDependency)1