Search in sources :

Example 6 with JGroupsFileBroadcastEndpointFactory

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

the class ConnectionFactorySerializationTest method createDiscoveryFactoryJGroupsFile.

private void createDiscoveryFactoryJGroupsFile() throws Exception {
    // Deploy a connection factory with discovery
    List<String> bindings = new ArrayList<>();
    bindings.add("MyConnectionFactory");
    JGroupsFileBroadcastEndpointFactory config = new JGroupsFileBroadcastEndpointFactory().setChannelName("myChannel").setFile("/META-INF/myfile.xml");
    DiscoveryGroupConfiguration dcConfig = new DiscoveryGroupConfiguration().setName("dg1").setRefreshTimeout(5000).setDiscoveryInitialWaitTimeout(5000).setBroadcastEndpointFactory(config);
    jmsServer.getActiveMQServer().getConfiguration().getDiscoveryGroupConfigurations().put(dcConfig.getName(), dcConfig);
    jmsServer.createConnectionFactory("MyConnectionFactory", false, JMSFactoryType.CF, dcConfig.getName(), "/MyConnectionFactory");
}
Also used : ArrayList(java.util.ArrayList) JGroupsFileBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory) DiscoveryGroupConfiguration(org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration)

Example 7 with JGroupsFileBroadcastEndpointFactory

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

the class ConnectionFactoryWithJGroupsSerializationTest method testSerialization.

// Public --------------------------------------------------------
// HORNETQ-1389
// Here we deploy two Connection Factories with JGroups discovery groups.
// The first one uses a runtime JChannel object, which is the case before the fix.
// The second one uses the raw jgroups config string, which is the case after fix.
// So the first one will get serialization exception in the test
// while the second will not.
@Test
public void testSerialization() throws Exception {
    jmsCf1 = (ActiveMQConnectionFactory) namingContext.lookup("/ConnectionFactory1");
    jmsCf2 = (ActiveMQConnectionFactory) namingContext.lookup("/ConnectionFactory2");
    try {
        serialize(jmsCf1);
    } catch (java.io.NotSerializableException e) {
    // this is expected
    }
    // now cf2 should be OK
    byte[] x = serialize(jmsCf2);
    ActiveMQConnectionFactory jmsCf2Copy = deserialize(x, ActiveMQConnectionFactory.class);
    assertNotNull(jmsCf2Copy);
    BroadcastEndpointFactory broadcastEndpoint = jmsCf2Copy.getDiscoveryGroupConfiguration().getBroadcastEndpointFactory();
    assertTrue(broadcastEndpoint instanceof JGroupsFileBroadcastEndpointFactory);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) JGroupsFileBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory) JGroupsFileBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory) BroadcastEndpointFactory(org.apache.activemq.artemis.api.core.BroadcastEndpointFactory) ChannelBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.ChannelBroadcastEndpointFactory) Test(org.junit.Test)

Example 8 with JGroupsFileBroadcastEndpointFactory

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

the class FileConfigurationParser method parseDiscoveryGroupConfiguration.

private void parseDiscoveryGroupConfiguration(final Element e, final Configuration mainConfig) {
    String name = e.getAttribute("name");
    long discoveryInitialWaitTimeout = getLong(e, "initial-wait-timeout", ActiveMQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT, Validators.GT_ZERO);
    long refreshTimeout = getLong(e, "refresh-timeout", ActiveMQDefaultConfiguration.getDefaultBroadcastRefreshTimeout(), Validators.GT_ZERO);
    String localBindAddress = getString(e, "local-bind-address", null, Validators.NO_CHECK);
    int localBindPort = getInteger(e, "local-bind-port", -1, Validators.MINUS_ONE_OR_GT_ZERO);
    String groupAddress = getString(e, "group-address", null, Validators.NO_CHECK);
    int groupPort = getInteger(e, "group-port", -1, Validators.MINUS_ONE_OR_GT_ZERO);
    String jgroupsFile = getString(e, "jgroups-file", null, Validators.NO_CHECK);
    String jgroupsChannel = getString(e, "jgroups-channel", null, Validators.NO_CHECK);
    // TODO: validate if either jgroups or UDP is being filled
    BroadcastEndpointFactory endpointFactory;
    if (jgroupsFile != null) {
        endpointFactory = new JGroupsFileBroadcastEndpointFactory().setFile(jgroupsFile).setChannelName(jgroupsChannel);
    } else {
        endpointFactory = new UDPBroadcastEndpointFactory().setGroupAddress(groupAddress).setGroupPort(groupPort).setLocalBindAddress(localBindAddress).setLocalBindPort(localBindPort);
    }
    DiscoveryGroupConfiguration config = new DiscoveryGroupConfiguration().setName(name).setRefreshTimeout(refreshTimeout).setDiscoveryInitialWaitTimeout(discoveryInitialWaitTimeout).setBroadcastEndpointFactory(endpointFactory);
    if (mainConfig.getDiscoveryGroupConfigurations().containsKey(name)) {
        ActiveMQServerLogger.LOGGER.discoveryGroupAlreadyDeployed(name);
        return;
    } else {
        mainConfig.getDiscoveryGroupConfigurations().put(name, config);
    }
}
Also used : JGroupsFileBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) DiscoveryGroupConfiguration(org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration) UDPBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory) JGroupsFileBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory) UDPBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory) BroadcastEndpointFactory(org.apache.activemq.artemis.api.core.BroadcastEndpointFactory)

Example 9 with JGroupsFileBroadcastEndpointFactory

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

the class FileConfigurationParser method parseBroadcastGroupConfiguration.

private void parseBroadcastGroupConfiguration(final Element e, final Configuration mainConfig) {
    String name = e.getAttribute("name");
    List<String> connectorNames = new ArrayList<>();
    NodeList children = e.getChildNodes();
    for (int j = 0; j < children.getLength(); j++) {
        Node child = children.item(j);
        if (child.getNodeName().equals("connector-ref")) {
            String connectorName = getString(e, "connector-ref", null, Validators.NOT_NULL_OR_EMPTY);
            connectorNames.add(connectorName);
        }
    }
    long broadcastPeriod = getLong(e, "broadcast-period", ActiveMQDefaultConfiguration.getDefaultBroadcastPeriod(), Validators.GT_ZERO);
    String localAddress = getString(e, "local-bind-address", null, Validators.NO_CHECK);
    int localBindPort = getInteger(e, "local-bind-port", -1, Validators.MINUS_ONE_OR_GT_ZERO);
    String groupAddress = getString(e, "group-address", null, Validators.NO_CHECK);
    int groupPort = getInteger(e, "group-port", -1, Validators.MINUS_ONE_OR_GT_ZERO);
    String jgroupsFile = getString(e, "jgroups-file", null, Validators.NO_CHECK);
    String jgroupsChannel = getString(e, "jgroups-channel", null, Validators.NO_CHECK);
    // TODO: validate if either jgroups or UDP is being filled
    BroadcastEndpointFactory endpointFactory;
    if (jgroupsFile != null) {
        endpointFactory = new JGroupsFileBroadcastEndpointFactory().setFile(jgroupsFile).setChannelName(jgroupsChannel);
    } else {
        endpointFactory = new UDPBroadcastEndpointFactory().setGroupAddress(groupAddress).setGroupPort(groupPort).setLocalBindAddress(localAddress).setLocalBindPort(localBindPort);
    }
    BroadcastGroupConfiguration config = new BroadcastGroupConfiguration().setName(name).setBroadcastPeriod(broadcastPeriod).setConnectorInfos(connectorNames).setEndpointFactory(endpointFactory);
    mainConfig.getBroadcastGroupConfigurations().add(config);
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) JGroupsFileBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) UDPBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory) BroadcastGroupConfiguration(org.apache.activemq.artemis.api.core.BroadcastGroupConfiguration) JGroupsFileBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory) UDPBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory) BroadcastEndpointFactory(org.apache.activemq.artemis.api.core.BroadcastEndpointFactory)

Example 10 with JGroupsFileBroadcastEndpointFactory

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

the class JGroupsSchema method internalNewURI.

@Override
protected URI internalNewURI(ActiveMQConnectionFactory 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)

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