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