Search in sources :

Example 6 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, SingletonServiceConfiguratorFactory factory, ServiceName name, int quorum) {
    ServiceBuilder<?> builder = target.addService(name);
    SingletonElectionListenerService listenerService = new SingletonElectionListenerService(builder.provides(name));
    builder.setInstance(listenerService).install();
    factory.createSingletonServiceConfigurator(name.append("singleton")).electionPolicy(new PreferredSingletonElectionPolicy(new SimpleSingletonElectionPolicy(), new NamePreference(PREFERRED_NODE))).electionListener(listenerService).requireQuorum(quorum).build(target).install();
}
Also used : NamePreference(org.wildfly.clustering.singleton.election.NamePreference) SimpleSingletonElectionPolicy(org.wildfly.clustering.singleton.election.SimpleSingletonElectionPolicy) PreferredSingletonElectionPolicy(org.wildfly.clustering.singleton.election.PreferredSingletonElectionPolicy)

Example 7 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, SingletonServiceConfiguratorFactory factory, ServiceName name, String preferredNode) {
    ServiceBuilder<?> builder = target.addService(name);
    SingletonElectionListenerService listenerService = new SingletonElectionListenerService(builder.provides(name));
    builder.setInstance(listenerService).install();
    factory.createSingletonServiceConfigurator(name.append("singleton")).electionPolicy(new PreferredSingletonElectionPolicy(new SimpleSingletonElectionPolicy(), new NamePreference(preferredNode))).electionListener(listenerService).build(target).install();
}
Also used : SingletonElectionListenerService(org.jboss.as.test.clustering.cluster.singleton.service.SingletonElectionListenerService) NamePreference(org.wildfly.clustering.singleton.election.NamePreference) SimpleSingletonElectionPolicy(org.wildfly.clustering.singleton.election.SimpleSingletonElectionPolicy) PreferredSingletonElectionPolicy(org.wildfly.clustering.singleton.election.PreferredSingletonElectionPolicy)

Example 8 with NamePreference

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

the class NamePreferenceTestCase method test.

@Test
public void test() {
    Preference preference = new NamePreference("node1");
    Node node1 = mock(Node.class);
    Node node2 = mock(Node.class);
    when(node1.getName()).thenReturn("node1");
    when(node2.getName()).thenReturn("node2");
    assertTrue(preference.preferred(node1));
    assertFalse(preference.preferred(node2));
}
Also used : NamePreference(org.wildfly.clustering.singleton.election.NamePreference) NamePreference(org.wildfly.clustering.singleton.election.NamePreference) Preference(org.wildfly.clustering.singleton.election.Preference) Node(org.wildfly.clustering.group.Node) Test(org.junit.Test)

Example 9 with NamePreference

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

the class HATimerServiceActivator4 method activate.

@Override
public void activate(ServiceActivatorContext context) {
    log.info("HATimerService 4 will be installed!");
    HATimerService4 service = new HATimerService4();
    ServiceName factoryServiceName = SingletonServiceName.BUILDER.getServiceName("server", "default");
    ServiceController<?> factoryService = context.getServiceRegistry().getRequiredService(factoryServiceName);
    SingletonServiceBuilderFactory factory = (SingletonServiceBuilderFactory) factoryService.getValue();
    factory.createSingletonServiceBuilder(HATimerService4.SINGLETON_SERVICE_NAME4, 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 10 with NamePreference

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

the class HATimerServiceActivator2 method activate.

@Override
public void activate(ServiceActivatorContext context) {
    log.info("HATimerService 2 will be installed!");
    HATimerService2 service = new HATimerService2();
    ServiceName factoryServiceName = SingletonServiceName.BUILDER.getServiceName("server", "default");
    ServiceController<?> factoryService = context.getServiceRegistry().getRequiredService(factoryServiceName);
    SingletonServiceBuilderFactory factory = (SingletonServiceBuilderFactory) factoryService.getValue();
    factory.createSingletonServiceBuilder(HATimerService2.SINGLETON_SERVICE_NAME2, 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)

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