Search in sources :

Example 16 with JChannel

use of org.jgroups.JChannel in project JGroups by belaban.

the class ConfiguratorTest method testProgrammaticCreationAndVariableSubstitution.

/**
 * Tests that vars are substituted correctly when creating a channel programmatically (https://issues.jboss.org/browse/JGRP-1908)
 */
public void testProgrammaticCreationAndVariableSubstitution() throws Exception {
    System.setProperty(Global.EXTERNAL_PORT, "10000");
    System.setProperty(Global.BIND_ADDR, "127.0.0.1");
    JChannel channel = new JChannel(new SHARED_LOOPBACK()).name("A");
    TP tp = channel.getProtocolStack().getTransport();
    assert tp.getValue("external_port").equals(10000);
    assert tp.getValue("bind_addr").equals(InetAddress.getByName("127.0.0.1"));
}
Also used : JChannel(org.jgroups.JChannel)

Example 17 with JChannel

use of org.jgroups.JChannel in project JGroups by belaban.

the class ForkProtocolStack method up.

public Object up(Message msg) {
    FORK.ForkHeader hdr = msg.getHeader(FORK.ID);
    if (hdr == null)
        return null;
    String forkId = hdr.getForkChannelId();
    if (forkId == null)
        throw new IllegalArgumentException("header has a null fork_channel_id");
    JChannel fork_channel = get(forkId);
    if (fork_channel == null) {
        return this.unknownForkHandler.handleUnknownForkChannel(msg, forkId);
    }
    return fork_channel.up(msg);
}
Also used : JChannel(org.jgroups.JChannel) FORK(org.jgroups.protocols.FORK)

Example 18 with JChannel

use of org.jgroups.JChannel in project JGroups by belaban.

the class PartitionedHashMap method start.

@ManagedOperation
public void start() throws Exception {
    hash_function = new ConsistentHashFunction<>();
    addMembershipListener((MembershipListener) hash_function);
    ch = new JChannel(props);
    Marshaller m = new CustomMarshaller();
    disp = new RpcDispatcher(ch, this).setMarshaller(m).setMethodLookup(methods::get).setMembershipListener(this);
    ch.connect(cluster_name);
    local_addr = ch.getAddress();
    view = ch.getView();
}
Also used : JChannel(org.jgroups.JChannel) ManagedOperation(org.jgroups.annotations.ManagedOperation)

Example 19 with JChannel

use of org.jgroups.JChannel in project fabric8 by jboss-fuse.

the class PingTestBase method doTestCluster.

protected void doTestCluster() throws Exception {
    Util.waitUntilAllChannelsHaveSameSize(10000, 1000, channels);
    // Tests unicasts from the first to the last
    JChannel first = channels[0], last = channels[NUM - 1];
    for (int i = 1; i <= 10; i++) {
        first.send(last.getAddress(), i);
    }
    List<Integer> msgs = receivers[NUM - 1].getList();
    Util.waitUntilListHasSize(msgs, 10, 10000, 1000);
    System.out.println("msgs = " + msgs);
    for (int i = 1; i < 10; i++) {
        Assert.assertTrue(msgs.contains(i));
    }
    clearReceivers();
    // Tests multicasts
    for (int i = 0; i < NUM; i++) {
        JChannel ch = channels[i];
        int num = (i + 1) * 10;
        for (int j = 0; j <= 5; j++) {
            ch.send(null, num + j);
        }
    }
    final int expected_size = NUM * 6;
    final List<Integer> expected_numbers = new ArrayList<>(expected_size);
    for (int i = 0; i < NUM; i++) {
        int num = (i + 1) * 10;
        for (int j = 0; j <= 5; j++) {
            expected_numbers.add(num + j);
        }
    }
    for (int i = 0; i < NUM; i++) {
        List<Integer> list = receivers[i].getList();
        Util.waitUntilListHasSize(list, expected_size, 10000, 1000);
        System.out.println("list[" + i + "]: " + list);
    }
    for (int i = 0; i < NUM; i++) {
        List<Integer> list = receivers[i].getList();
        for (int num : expected_numbers) {
            Assert.assertTrue(list.contains(num));
        }
    }
    clearReceivers();
}
Also used : JChannel(org.jgroups.JChannel) ArrayList(java.util.ArrayList)

Example 20 with JChannel

use of org.jgroups.JChannel in project fabric8 by jboss-fuse.

the class TestBase method setUp.

@Before
public void setUp() throws Exception {
    for (int i = 0; i < NUM; i++) {
        Protocol ping = createPing();
        channels[i] = new JChannel(new TCP(), ping, new NAKACK2(), new UNICAST3(), new STABLE(), new GMS());
        channels[i].setName(Character.toString((char) ('A' + i)));
        channels[i].connect(CLUSTER_NAME);
        channels[i].setReceiver(receivers[i] = new MyReceiver());
    }
}
Also used : TCP(org.jgroups.protocols.TCP) NAKACK2(org.jgroups.protocols.pbcast.NAKACK2) JChannel(org.jgroups.JChannel) STABLE(org.jgroups.protocols.pbcast.STABLE) Protocol(org.jgroups.stack.Protocol) GMS(org.jgroups.protocols.pbcast.GMS) UNICAST3(org.jgroups.protocols.UNICAST3) Before(org.junit.Before)

Aggregations

JChannel (org.jgroups.JChannel)119 GMS (org.jgroups.protocols.pbcast.GMS)22 NAKACK2 (org.jgroups.protocols.pbcast.NAKACK2)21 Protocol (org.jgroups.stack.Protocol)18 STABLE (org.jgroups.protocols.pbcast.STABLE)15 View (org.jgroups.View)14 Message (org.jgroups.Message)10 ArrayList (java.util.ArrayList)9 Address (org.jgroups.Address)7 IOException (java.io.IOException)6 Test (org.testng.annotations.Test)5 InetSocketAddress (java.net.InetSocketAddress)4 HashMap (java.util.HashMap)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)4 LockService (org.jgroups.blocks.locking.LockService)4 Test (org.junit.Test)4 BeforeMethod (org.testng.annotations.BeforeMethod)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 ChannelBroadcastEndpointFactory (org.apache.activemq.artemis.api.core.ChannelBroadcastEndpointFactory)3