Search in sources :

Example 1 with BroadcastGroupImpl

use of org.apache.activemq.artemis.core.server.cluster.impl.BroadcastGroupImpl in project activemq-artemis by apache.

the class DiscoveryTest method testSimpleBroadcastJGropus.

@Test
public void testSimpleBroadcastJGropus() throws Exception {
    final String nodeID = RandomUtil.randomString();
    bg = new BroadcastGroupImpl(new FakeNodeManager(nodeID), "broadcast", 100, null, new JGroupsFileBroadcastEndpointFactory().setChannelName("tst").setFile(TEST_JGROUPS_CONF_FILE));
    bg.start();
    TransportConfiguration live1 = generateTC();
    bg.addConnector(live1);
    dg = new DiscoveryGroup(nodeID + "1", "broadcast", 5000L, new JGroupsFileBroadcastEndpointFactory().setChannelName("tst").setFile(TEST_JGROUPS_CONF_FILE), null);
    dg.start();
    verifyBroadcast(bg, dg);
    List<DiscoveryEntry> entries = dg.getDiscoveryEntries();
    assertEqualsDiscoveryEntries(Arrays.asList(live1), entries);
}
Also used : DiscoveryGroup(org.apache.activemq.artemis.core.cluster.DiscoveryGroup) DiscoveryEntry(org.apache.activemq.artemis.core.cluster.DiscoveryEntry) BroadcastGroupImpl(org.apache.activemq.artemis.core.server.cluster.impl.BroadcastGroupImpl) JGroupsFileBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Test(org.junit.Test)

Example 2 with BroadcastGroupImpl

use of org.apache.activemq.artemis.core.server.cluster.impl.BroadcastGroupImpl in project activemq-artemis by apache.

the class DiscoveryStayAliveTest method testDiscoveryRunning.

@Test
public void testDiscoveryRunning() throws Throwable {
    final InetAddress groupAddress = InetAddress.getByName(address1);
    final int groupPort = getUDPDiscoveryPort();
    final int timeout = 500;
    final DiscoveryGroup dg = newDiscoveryGroup(RandomUtil.randomString(), RandomUtil.randomString(), InetAddress.getByName("localhost"), groupAddress, groupPort, timeout);
    final AtomicInteger errors = new AtomicInteger(0);
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                dg.internalRunning();
            } catch (Throwable e) {
                e.printStackTrace();
                errors.incrementAndGet();
            }
        }
    };
    t.start();
    BroadcastGroupImpl bg = null;
    try {
        bg = new BroadcastGroupImpl(new FakeNodeManager("test-nodeID"), RandomUtil.randomString(), 1, scheduledExecutorService, new UDPBroadcastEndpointFactory().setGroupAddress(address1).setGroupPort(groupPort));
        bg.start();
        bg.addConnector(generateTC());
        for (int i = 0; i < 10; i++) {
            BroadcastEndpointFactory factoryEndpoint = new UDPBroadcastEndpointFactory().setGroupAddress(address1).setGroupPort(groupPort).setLocalBindAddress("localhost");
            sendBadData(factoryEndpoint);
        }
        Thread.sleep(100);
        assertTrue(t.isAlive());
        assertEquals(0, errors.get());
    } finally {
        if (bg != null) {
            bg.stop();
        }
        if (dg != null) {
            dg.stop();
        }
        t.join(1000);
        // it will retry for a limited time only
        for (int i = 0; t.isAlive() && i < 100; i++) {
            t.interrupt();
            Thread.sleep(100);
        }
    }
}
Also used : DiscoveryGroup(org.apache.activemq.artemis.core.cluster.DiscoveryGroup) BroadcastGroupImpl(org.apache.activemq.artemis.core.server.cluster.impl.BroadcastGroupImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InetAddress(java.net.InetAddress) UDPBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory) BroadcastEndpoint(org.apache.activemq.artemis.api.core.BroadcastEndpoint) UDPBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory) BroadcastEndpointFactory(org.apache.activemq.artemis.api.core.BroadcastEndpointFactory) Test(org.junit.Test)

Example 3 with BroadcastGroupImpl

use of org.apache.activemq.artemis.core.server.cluster.impl.BroadcastGroupImpl in project activemq-artemis by apache.

the class ClusterManager method createBroadcastGroup.

private BroadcastGroup createBroadcastGroup(BroadcastGroupConfiguration config) throws Exception {
    BroadcastGroup group = broadcastGroups.get(config.getName());
    if (group == null) {
        group = new BroadcastGroupImpl(nodeManager, config.getName(), config.getBroadcastPeriod(), scheduledExecutor, config.getEndpointFactory());
        for (String connectorInfo : config.getConnectorInfos()) {
            TransportConfiguration connector = configuration.getConnectorConfigurations().get(connectorInfo);
            if (connector == null) {
                logWarnNoConnector(connectorInfo, config.getName());
                return null;
            }
            group.addConnector(connector);
        }
    }
    if (group.size() == 0) {
        logWarnNoConnector(config.getConnectorInfos().toString(), group.getName());
        return null;
    }
    broadcastGroups.put(config.getName(), group);
    return group;
}
Also used : BroadcastGroupImpl(org.apache.activemq.artemis.core.server.cluster.impl.BroadcastGroupImpl) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString)

Example 4 with BroadcastGroupImpl

use of org.apache.activemq.artemis.core.server.cluster.impl.BroadcastGroupImpl in project activemq-artemis by apache.

the class DiscoveryTest method testSimpleBroadcast.

@Test
public void testSimpleBroadcast() throws Exception {
    final InetAddress groupAddress = InetAddress.getByName(address1);
    final int groupPort = getUDPDiscoveryPort();
    final int timeout = 500;
    final String nodeID = RandomUtil.randomString();
    bg = new BroadcastGroupImpl(new FakeNodeManager(nodeID), RandomUtil.randomString(), 0, null, new UDPBroadcastEndpointFactory().setGroupAddress(address1).setGroupPort(groupPort));
    bg.start();
    TransportConfiguration live1 = generateTC();
    bg.addConnector(live1);
    dg = newDiscoveryGroup(RandomUtil.randomString(), RandomUtil.randomString(), null, groupAddress, groupPort, timeout);
    dg.start();
    verifyBroadcast(bg, dg);
    List<DiscoveryEntry> entries = dg.getDiscoveryEntries();
    assertEqualsDiscoveryEntries(Arrays.asList(live1), entries);
}
Also used : DiscoveryEntry(org.apache.activemq.artemis.core.cluster.DiscoveryEntry) BroadcastGroupImpl(org.apache.activemq.artemis.core.server.cluster.impl.BroadcastGroupImpl) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) InetAddress(java.net.InetAddress) UDPBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory) BroadcastEndpoint(org.apache.activemq.artemis.api.core.BroadcastEndpoint) Test(org.junit.Test)

Aggregations

BroadcastGroupImpl (org.apache.activemq.artemis.core.server.cluster.impl.BroadcastGroupImpl)4 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)3 Test (org.junit.Test)3 InetAddress (java.net.InetAddress)2 BroadcastEndpoint (org.apache.activemq.artemis.api.core.BroadcastEndpoint)2 UDPBroadcastEndpointFactory (org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory)2 DiscoveryEntry (org.apache.activemq.artemis.core.cluster.DiscoveryEntry)2 DiscoveryGroup (org.apache.activemq.artemis.core.cluster.DiscoveryGroup)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 BroadcastEndpointFactory (org.apache.activemq.artemis.api.core.BroadcastEndpointFactory)1 JGroupsFileBroadcastEndpointFactory (org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory)1