Search in sources :

Example 1 with JGroupsFileBroadcastEndpointFactory

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

the class JGroupsServerLocatorSchema method internalNewURI.

@Override
protected URI internalNewURI(ServerLocator bean) throws Exception {
    DiscoveryGroupConfiguration dgc = bean.getDiscoveryGroupConfiguration();
    BroadcastEndpointFactory endpoint = dgc.getBroadcastEndpointFactory();
    String auth;
    if (endpoint instanceof JGroupsFileBroadcastEndpointFactory) {
        auth = ((JGroupsFileBroadcastEndpointFactory) endpoint).getChannelName();
    } else if (endpoint instanceof JGroupsPropertiesBroadcastEndpointFactory) {
        auth = ((JGroupsPropertiesBroadcastEndpointFactory) endpoint).getChannelName();
    } else {
        throw new NotSerializableException(endpoint + "not serializable");
    }
    String query = BeanSupport.getData(null, bean, dgc, endpoint);
    dgc.setBroadcastEndpointFactory(endpoint);
    return new URI(SchemaConstants.JGROUPS, null, auth, -1, null, query, null);
}
Also used : NotSerializableException(java.io.NotSerializableException) JGroupsPropertiesBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsPropertiesBroadcastEndpointFactory) JGroupsFileBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory) DiscoveryGroupConfiguration(org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration) URI(java.net.URI) JGroupsPropertiesBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsPropertiesBroadcastEndpointFactory) JGroupsFileBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory) BroadcastEndpointFactory(org.apache.activemq.artemis.api.core.BroadcastEndpointFactory)

Example 2 with JGroupsFileBroadcastEndpointFactory

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

the class JGroupsServerLocatorSchema method getDiscoveryGroupConfiguration.

public static DiscoveryGroupConfiguration getDiscoveryGroupConfiguration(URI uri, Map<String, String> query, String name) throws Exception {
    BroadcastEndpointFactory endpointFactory;
    if (query.containsKey("file")) {
        endpointFactory = new JGroupsFileBroadcastEndpointFactory().setChannelName(uri.getAuthority());
    } else {
        endpointFactory = new JGroupsPropertiesBroadcastEndpointFactory().setChannelName(uri.getAuthority());
    }
    BeanSupport.setData(uri, endpointFactory, query);
    DiscoveryGroupConfiguration dcConfig = new DiscoveryGroupConfiguration().setName(name).setBroadcastEndpointFactory(endpointFactory);
    BeanSupport.setData(uri, dcConfig, query);
    return dcConfig;
}
Also used : JGroupsPropertiesBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsPropertiesBroadcastEndpointFactory) JGroupsFileBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory) DiscoveryGroupConfiguration(org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration) JGroupsPropertiesBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsPropertiesBroadcastEndpointFactory) JGroupsFileBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory) BroadcastEndpointFactory(org.apache.activemq.artemis.api.core.BroadcastEndpointFactory)

Example 3 with JGroupsFileBroadcastEndpointFactory

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

the class ActiveMQResourceAdapter method createBroadcastEndpointFactory.

protected BroadcastEndpointFactory createBroadcastEndpointFactory(final ConnectionFactoryProperties overrideProperties) {
    String discoveryAddress = overrideProperties.getDiscoveryAddress() != null ? overrideProperties.getDiscoveryAddress() : getDiscoveryAddress();
    if (discoveryAddress != null) {
        Integer discoveryPort = overrideProperties.getDiscoveryPort() != null ? overrideProperties.getDiscoveryPort() : getDiscoveryPort();
        if (discoveryPort == null) {
            discoveryPort = ActiveMQClient.DEFAULT_DISCOVERY_PORT;
        }
        String localBindAddress = overrideProperties.getDiscoveryLocalBindAddress() != null ? overrideProperties.getDiscoveryLocalBindAddress() : raProperties.getDiscoveryLocalBindAddress();
        return new UDPBroadcastEndpointFactory().setGroupAddress(discoveryAddress).setGroupPort(discoveryPort).setLocalBindAddress(localBindAddress).setLocalBindPort(-1);
    }
    String jgroupsChannel = overrideProperties.getJgroupsChannelName() != null ? overrideProperties.getJgroupsChannelName() : getJgroupsChannelName();
    String jgroupsLocatorClassName = raProperties.getJgroupsChannelLocatorClass();
    if (jgroupsLocatorClassName != null) {
        String jchannelRefName = raProperties.getJgroupsChannelRefName();
        JChannel jchannel = ActiveMQRaUtils.locateJGroupsChannel(jgroupsLocatorClassName, jchannelRefName);
        return new ChannelBroadcastEndpointFactory(jchannel, jgroupsChannel);
    }
    String jgroupsFileName = overrideProperties.getJgroupsFile() != null ? overrideProperties.getJgroupsFile() : getJgroupsFile();
    if (jgroupsFileName != null) {
        return new JGroupsFileBroadcastEndpointFactory().setChannelName(jgroupsChannel).setFile(jgroupsFileName);
    }
    return null;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ChannelBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.ChannelBroadcastEndpointFactory) JChannel(org.jgroups.JChannel) JGroupsFileBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory) UDPBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory)

Example 4 with JGroupsFileBroadcastEndpointFactory

use of org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory 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 5 with JGroupsFileBroadcastEndpointFactory

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

the class DiscoveryTest method testJGropusChannelReferenceCounting1.

/**
 * Create one broadcaster and 50 receivers. Make sure broadcasting works.
 * Then stop all of the receivers, and create 50 new ones. Make sure the
 * 50 new ones are receiving data from the broadcasting.
 *
 * @throws Exception
 */
@Test
public void testJGropusChannelReferenceCounting1() 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();
    }
    try {
        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; i++) {
            receivers[i].close(false);
        }
        // new ones
        for (int i = 0; i < num; i++) {
            receivers[i] = factory.createBroadcastEndpoint();
            receivers[i].openClient();
        }
        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]);
        }
    } finally {
        for (int i = 0; i < num; i++) {
            receivers[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