Search in sources :

Example 11 with JGroupsFileBroadcastEndpointFactory

use of org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory in project activemq-artemis by apache.

the class ConnectionFactoryURITest method testJGroupsFileURI.

@Test
public void testJGroupsFileURI() throws Exception {
    DiscoveryGroupConfiguration discoveryGroupConfiguration = new DiscoveryGroupConfiguration();
    JGroupsFileBroadcastEndpointFactory endpointFactory = new JGroupsFileBroadcastEndpointFactory().setChannelName("channel-name").setFile("channel-file.xml");
    discoveryGroupConfiguration.setName("foo").setRefreshTimeout(12345).setDiscoveryInitialWaitTimeout(5678).setBroadcastEndpointFactory(endpointFactory);
    ActiveMQConnectionFactory connectionFactoryWithHA = ActiveMQJMSClient.createConnectionFactoryWithHA(discoveryGroupConfiguration, JMSFactoryType.CF);
    URI tcp = parser.createSchema("jgroups", connectionFactoryWithHA);
    ActiveMQConnectionFactory factory = parser.newObject(tcp, null);
    DiscoveryGroupConfiguration dgc = factory.getDiscoveryGroupConfiguration();
    Assert.assertNotNull(dgc);
    BroadcastEndpointFactory befc = dgc.getBroadcastEndpointFactory();
    Assert.assertNotNull(befc);
    Assert.assertTrue(befc instanceof JGroupsFileBroadcastEndpointFactory);
    Assert.assertEquals(dgc.getName(), "foo");
    Assert.assertEquals(dgc.getDiscoveryInitialWaitTimeout(), 5678);
    Assert.assertEquals(dgc.getRefreshTimeout(), 12345);
    JGroupsFileBroadcastEndpointFactory fileBroadcastEndpointFactory = (JGroupsFileBroadcastEndpointFactory) befc;
    Assert.assertEquals(fileBroadcastEndpointFactory.getFile(), "channel-file.xml");
    Assert.assertEquals(fileBroadcastEndpointFactory.getChannelName(), "channel-name");
    BeanUtilsBean bean = new BeanUtilsBean();
    checkEquals(bean, connectionFactoryWithHA, factory);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) BeanUtilsBean(org.apache.commons.beanutils.BeanUtilsBean) JGroupsFileBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory) DiscoveryGroupConfiguration(org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration) URI(java.net.URI) JGroupsFileBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory) JGroupsPropertiesBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsPropertiesBroadcastEndpointFactory) UDPBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory) BroadcastEndpointFactory(org.apache.activemq.artemis.api.core.BroadcastEndpointFactory) Test(org.junit.Test)

Example 12 with JGroupsFileBroadcastEndpointFactory

use of org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory in project activemq-artemis by apache.

the class ConnectionFactoryURITest method testJGroupsFile.

@Test
public void testJGroupsFile() throws Exception {
    ActiveMQConnectionFactory factory = parser.newObject(new URI("jgroups://channel-name?file=/path/to/some/file/channel-file.xml&test=33"), null);
    Assert.assertTrue(ActiveMQJMSConnectionFactory.class.getName().equals(factory.getClass().getName()));
    JGroupsFileBroadcastEndpointFactory broadcastEndpointFactory = (JGroupsFileBroadcastEndpointFactory) factory.getDiscoveryGroupConfiguration().getBroadcastEndpointFactory();
    Assert.assertEquals(broadcastEndpointFactory.getFile(), "/path/to/some/file/channel-file.xml");
    Assert.assertEquals(broadcastEndpointFactory.getChannelName(), "channel-name");
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) JGroupsFileBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory) URI(java.net.URI) Test(org.junit.Test)

Example 13 with JGroupsFileBroadcastEndpointFactory

use of org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory in project activemq-artemis by apache.

the class DiscoveryTest method testStraightSendReceiveJGroups.

@Test
public void testStraightSendReceiveJGroups() throws Exception {
    BroadcastEndpoint broadcaster = null;
    BroadcastEndpoint client = null;
    try {
        JGroupsFileBroadcastEndpointFactory endpointFactory = new JGroupsFileBroadcastEndpointFactory().setChannelName("tst").setFile(TEST_JGROUPS_CONF_FILE);
        broadcaster = endpointFactory.createBroadcastEndpoint();
        broadcaster.openBroadcaster();
        client = endpointFactory.createBroadcastEndpoint();
        client.openClient();
        Thread.sleep(1000);
        byte[] randomBytes = "PQP".getBytes();
        broadcaster.broadcast(randomBytes);
        byte[] btreceived = client.receiveBroadcast(5, TimeUnit.SECONDS);
        System.out.println("BTReceived = " + Arrays.toString(btreceived));
        assertNotNull(btreceived);
        assertEquals(randomBytes.length, btreceived.length);
        for (int i = 0; i < randomBytes.length; i++) {
            assertEquals(randomBytes[i], btreceived[i]);
        }
    } finally {
        try {
            if (broadcaster != null)
                broadcaster.close(true);
            if (client != null)
                client.close(false);
        } catch (Exception ignored) {
            ignored.printStackTrace();
        }
    }
}
Also used : BroadcastEndpoint(org.apache.activemq.artemis.api.core.BroadcastEndpoint) JGroupsFileBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory) BroadcastEndpoint(org.apache.activemq.artemis.api.core.BroadcastEndpoint) Test(org.junit.Test)

Example 14 with JGroupsFileBroadcastEndpointFactory

use of org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory in project activemq-artemis by apache.

the class DiscoveryTest method testJGropusChannelReferenceCounting.

/**
 * Create one broadcaster and 100 receivers. Make sure broadcasting works.
 * Then stop 99 of the receivers, the last one could still be working.
 *
 * @throws Exception
 */
@Test
public void testJGropusChannelReferenceCounting() throws Exception {
    BroadcastEndpointFactory factory = new JGroupsFileBroadcastEndpointFactory().setChannelName("tst").setFile(TEST_JGROUPS_CONF_FILE);
    BroadcastEndpoint broadcaster = factory.createBroadcastEndpoint();
    broadcaster.openBroadcaster();
    try {
        int num = 100;
        BroadcastEndpoint[] receivers = new BroadcastEndpoint[num];
        for (int i = 0; i < num; i++) {
            receivers[i] = factory.createBroadcastEndpoint();
            receivers[i].openClient();
        }
        final byte[] data = new byte[] { 1, 2, 3, 4, 5 };
        broadcaster.broadcast(data);
        for (int i = 0; i < num; i++) {
            byte[] received = receivers[i].receiveBroadcast(5000, TimeUnit.MILLISECONDS);
            assertNotNull(received);
            assertEquals(5, received.length);
            assertEquals(1, received[0]);
            assertEquals(2, received[1]);
            assertEquals(3, received[2]);
            assertEquals(4, received[3]);
            assertEquals(5, received[4]);
        }
        for (int i = 0; i < num - 1; i++) {
            receivers[i].close(false);
        }
        byte[] data1 = receivers[num - 1].receiveBroadcast(5, TimeUnit.SECONDS);
        assertNull(data1);
        broadcaster.broadcast(data);
        data1 = receivers[num - 1].receiveBroadcast(5, TimeUnit.SECONDS);
        assertNotNull(data1);
        assertEquals(5, data1.length);
        assertEquals(1, data1[0]);
        assertEquals(2, data1[1]);
        assertEquals(3, data1[2]);
        assertEquals(4, data1[3]);
        assertEquals(5, data1[4]);
        receivers[num - 1].close(false);
    } finally {
        broadcaster.close(true);
    }
}
Also used : BroadcastEndpoint(org.apache.activemq.artemis.api.core.BroadcastEndpoint) JGroupsFileBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory) BroadcastEndpoint(org.apache.activemq.artemis.api.core.BroadcastEndpoint) JGroupsFileBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory) UDPBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory) BroadcastEndpointFactory(org.apache.activemq.artemis.api.core.BroadcastEndpointFactory) Test(org.junit.Test)

Example 15 with JGroupsFileBroadcastEndpointFactory

use of org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory in project activemq-artemis by apache.

the class DiscoveryTest method testJGropusChannelReferenceCounting2.

/**
 * Create one broadcaster and 50 receivers. Then stop half of the receivers.
 * Then add the half back, plus some more. Make sure all receivers receive data.
 *
 * @throws Exception
 */
@Test
public void testJGropusChannelReferenceCounting2() throws Exception {
    BroadcastEndpointFactory factory = new JGroupsFileBroadcastEndpointFactory().setChannelName("tst").setFile(TEST_JGROUPS_CONF_FILE);
    BroadcastEndpoint broadcaster = factory.createBroadcastEndpoint();
    broadcaster.openBroadcaster();
    int num = 50;
    BroadcastEndpoint[] receivers = new BroadcastEndpoint[num];
    for (int i = 0; i < num; i++) {
        receivers[i] = factory.createBroadcastEndpoint();
        receivers[i].openClient();
    }
    for (int i = 0; i < num / 2; i++) {
        receivers[i].close(false);
    }
    for (int i = 0; i < num / 2; i++) {
        receivers[i] = factory.createBroadcastEndpoint();
        receivers[i].openClient();
    }
    int num2 = 10;
    BroadcastEndpoint[] moreReceivers = new BroadcastEndpoint[num2];
    for (int i = 0; i < num2; i++) {
        moreReceivers[i] = factory.createBroadcastEndpoint();
        moreReceivers[i].openClient();
    }
    final byte[] data = new byte[] { 1, 2, 3, 4, 5 };
    broadcaster.broadcast(data);
    for (int i = 0; i < num; i++) {
        byte[] received = receivers[i].receiveBroadcast(5000, TimeUnit.MILLISECONDS);
        assertNotNull(received);
        assertEquals(5, received.length);
        assertEquals(1, received[0]);
        assertEquals(2, received[1]);
        assertEquals(3, received[2]);
        assertEquals(4, received[3]);
        assertEquals(5, received[4]);
    }
    for (int i = 0; i < num2; i++) {
        byte[] received = moreReceivers[i].receiveBroadcast(5000, TimeUnit.MILLISECONDS);
        assertNotNull(received);
        assertEquals(5, received.length);
        assertEquals(1, received[0]);
        assertEquals(2, received[1]);
        assertEquals(3, received[2]);
        assertEquals(4, received[3]);
        assertEquals(5, received[4]);
    }
    for (int i = 0; i < num; i++) {
        receivers[i].close(false);
    }
    for (int i = 0; i < num2; i++) {
        moreReceivers[i].close(false);
    }
    broadcaster.close(true);
}
Also used : BroadcastEndpoint(org.apache.activemq.artemis.api.core.BroadcastEndpoint) JGroupsFileBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory) BroadcastEndpoint(org.apache.activemq.artemis.api.core.BroadcastEndpoint) JGroupsFileBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory) UDPBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory) BroadcastEndpointFactory(org.apache.activemq.artemis.api.core.BroadcastEndpointFactory) Test(org.junit.Test)

Aggregations

JGroupsFileBroadcastEndpointFactory (org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory)17 BroadcastEndpointFactory (org.apache.activemq.artemis.api.core.BroadcastEndpointFactory)11 Test (org.junit.Test)9 DiscoveryGroupConfiguration (org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration)8 UDPBroadcastEndpointFactory (org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory)7 URI (java.net.URI)4 BroadcastEndpoint (org.apache.activemq.artemis.api.core.BroadcastEndpoint)4 JGroupsPropertiesBroadcastEndpointFactory (org.apache.activemq.artemis.api.core.JGroupsPropertiesBroadcastEndpointFactory)4 ActiveMQConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory)4 ChannelBroadcastEndpointFactory (org.apache.activemq.artemis.api.core.ChannelBroadcastEndpointFactory)3 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 NotSerializableException (java.io.NotSerializableException)2 ArrayList (java.util.ArrayList)2 JChannel (org.jgroups.JChannel)2 IOException (java.io.IOException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 BroadcastGroupConfiguration (org.apache.activemq.artemis.api.core.BroadcastGroupConfiguration)1 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)1 DiscoveryEntry (org.apache.activemq.artemis.core.cluster.DiscoveryEntry)1 DiscoveryGroup (org.apache.activemq.artemis.core.cluster.DiscoveryGroup)1