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");
}
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);
}
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);
}
}
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);
}
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);
}
Aggregations