Package org.wildfly.clustering.group

Examples of org.wildfly.clustering.group.Node


            List<String> nodes = new ArrayList<>(responses.size());
            for (CommandResponse<String> response: responses) {
                nodes.add(response.get());
            }

            Node localNode = this.factory.getGroup().getLocalNode();
            System.out.println("Executing command on node: " + localNode);
            String local = this.dispatcher.executeOnNode(this.command, localNode).get();

            System.out.println("Executing command on cluster excluding node: " + localNode);
            responses = this.dispatcher.executeOnCluster(this.command, localNode).values();
View Full Code Here


    @Override
    public String locate(String sessionId) {
        Map.Entry<String, Void> entry = null;
        Address location = this.locatePrimaryOwner(sessionId);
        if (location != null) {
            Node node = this.factory.createNode(location);
            entry = this.registry.getEntry(node);
        }
        if (entry == null) {
            // Accommodate mod_cluster's lazy route auto-generation
            entry = this.registry.getLocalEntry();
View Full Code Here

        InetSocketAddress otherAddress1 = new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 2);
        InetSocketAddress otherAddress2 = new InetSocketAddress(InetAddress.getByName("127.0.0.2"), 1);

        Preference preference = new SocketAddressPreference(preferredAddress);

        Node preferredNode = mock(Node.class);
        Node otherNode1 = mock(Node.class);
        Node otherNode2 = mock(Node.class);

        when(preferredNode.getSocketAddress()).thenReturn(preferredAddress);
        when(otherNode1.getSocketAddress()).thenReturn(otherAddress1);
        when(otherNode2.getSocketAddress()).thenReturn(otherAddress2);

        assertTrue(preference.preferred(preferredNode));
        assertFalse(preference.preferred(otherNode1));
        assertFalse(preference.preferred(otherNode2));
    }
View Full Code Here

public class NamePreferenceTestCase {
    @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));
    }
View Full Code Here

* @author Paul Ferraro
*/
public class SimpleSingletonElectionPolicyTestCase {
    @Test
    public void elect() {
        Node node1 = mock(Node.class);
        Node node2 = mock(Node.class);
        Node node3 = mock(Node.class);
        List<Node> nodes = Arrays.asList(node1, node2, node3);

        assertSame(node1, new SimpleSingletonElectionPolicy().elect(nodes));
        assertSame(node1, new SimpleSingletonElectionPolicy(0).elect(nodes));
        assertSame(node2, new SimpleSingletonElectionPolicy(1).elect(nodes));
View Full Code Here

    public void elect() {
        SingletonElectionPolicy policy = mock(SingletonElectionPolicy.class);
        Preference preference1 = mock(Preference.class);
        Preference preference2 = mock(Preference.class);

        Node node1 = mock(Node.class);
        Node node2 = mock(Node.class);
        Node node3 = mock(Node.class);
        Node node4 = mock(Node.class);

        when(preference1.preferred(same(node1))).thenReturn(true);
        when(preference1.preferred(same(node2))).thenReturn(false);
        when(preference1.preferred(same(node3))).thenReturn(false);
        when(preference1.preferred(same(node4))).thenReturn(false);
View Full Code Here

    private void executeOnPrimaryOwner(final ImmutableSession session, final Command<Void, Scheduler> command) throws Exception {
        Callable<Void> task = new Callable<Void>() {
            @Override
            public Void call() throws Exception {
                // This should only go remote following a failover
                Node node = InfinispanSessionManager.this.locatePrimaryOwner(session);
                return InfinispanSessionManager.this.dispatcher.executeOnNode(command, node).get();
            }
        };
        this.invoker.invoke(task);
    }
View Full Code Here

    private void executeOnPrimaryOwner(final Bean<G, I, T> bean, final Command<Void, Scheduler<I>> command) throws Exception {
        Callable<Void> task = new Callable<Void>() {
            @Override
            public Void call() throws Exception {
                // This should only go remote following a failover
                Node node = InfinispanBeanManager.this.locatePrimaryOwner(bean.getId());
                return InfinispanBeanManager.this.dispatcher.executeOnNode(command, node).get();
            }
        };
        this.invoker.invoke(task);
    }
View Full Code Here

    @Override
    public ServiceProviderRegistration createRegistration(final Object service, Listener listener) {
        if (this.listeners.putIfAbsent(service, listener) != null) {
            throw new IllegalArgumentException(service.toString());
        }
        final Node node = this.group.getLocalNode();
        Set<Node> nodes = new HashSet<>(Collections.singleton(node));
        try (Batch batch = this.batcher.createBatch()) {
            Set<Node> existing = this.cache.getAdvancedCache().withFlags(Flag.FORCE_SYNCHRONOUS).putIfAbsent(service, nodes);
            if (existing != null) {
                if (existing.add(node)) {
                    this.cache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES).replace(service, existing);
                }
            }
        }
        return new AbstractServiceProviderRegistration(service, this) {
            @Override
            public void close() {
                if (CacheServiceProviderRegistrationFactory.this.listeners.remove(service) != null) {
                    final Node node = CacheServiceProviderRegistrationFactory.this.getGroup().getLocalNode();
                    try (Batch batch = CacheServiceProviderRegistrationFactory.this.batcher.createBatch()) {
                        Set<Node> nodes = CacheServiceProviderRegistrationFactory.this.cache.get(service);
                        if ((nodes != null) && nodes.remove(node)) {
                            Cache<Object, Set<Node>> cache = CacheServiceProviderRegistrationFactory.this.cache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES);
                            if (nodes.isEmpty()) {
View Full Code Here

    @Override
    public void close() {
        this.cache.removeListener(this);
        this.listeners.clear();
        final Node node = this.getGroup().getLocalNode();
        try (Batch batch = this.batcher.createBatch()) {
            this.cache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES).remove(node);
        }
    }
View Full Code Here

TOP

Related Classes of org.wildfly.clustering.group.Node

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.