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;
}
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();
}
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;
}
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();
}
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();
}
Aggregations