use of org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl in project activemq-artemis by apache.
the class ActiveMQServerControlImpl method listNetworkTopology.
@Override
public String listNetworkTopology() throws Exception {
checkStarted();
clearIO();
try {
JsonArrayBuilder brokers = JsonLoader.createArrayBuilder();
ClusterManager clusterManager = server.getClusterManager();
if (clusterManager != null) {
Set<ClusterConnection> clusterConnections = clusterManager.getClusterConnections();
for (ClusterConnection clusterConnection : clusterConnections) {
Topology topology = clusterConnection.getTopology();
Collection<TopologyMemberImpl> members = topology.getMembers();
for (TopologyMemberImpl member : members) {
JsonObjectBuilder obj = JsonLoader.createObjectBuilder();
TransportConfiguration live = member.getLive();
if (live != null) {
obj.add("nodeID", member.getNodeId()).add("live", live.getParams().get("host") + ":" + live.getParams().get("port"));
TransportConfiguration backup = member.getBackup();
if (backup != null) {
obj.add("backup", backup.getParams().get("host") + ":" + backup.getParams().get("port"));
}
}
brokers.add(obj);
}
}
}
return brokers.build().toString();
} finally {
blockOnIO();
}
}
use of org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl in project activemq-artemis by apache.
the class AMQPConnectionCallback method getFailoverList.
public URI getFailoverList() {
ClusterManager clusterManager = server.getClusterManager();
ClusterConnection clusterConnection = clusterManager.getDefaultConnection(null);
if (clusterConnection != null) {
TopologyMemberImpl member = clusterConnection.getTopology().getMember(server.getNodeID().toString());
return member.toBackupURI();
}
return null;
}
use of org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl in project activemq-artemis by apache.
the class NonHATopologyTest method internalTest.
public void internalTest(boolean isNetty) throws Exception {
ActiveMQServer server = null;
ServerLocatorInternal locator = null;
try {
server = createServer(false, isNetty);
if (!isNetty) {
server.getConfiguration().getAcceptorConfigurations().add(new TransportConfiguration(NETTY_ACCEPTOR_FACTORY));
server.getConfiguration().getConnectorConfigurations().put("netty", new TransportConfiguration(NETTY_CONNECTOR_FACTORY));
ArrayList<String> list = new ArrayList<>();
list.add("netty");
Configuration config = server.getConfiguration();
config.getClusterConfigurations().add(new ClusterConnectionConfiguration().setName("tst").setAddress("jms").setConnectorName("netty").setRetryInterval(1000).setConfirmationWindowSize(1000).setMessageLoadBalancingType(MessageLoadBalancingType.ON_DEMAND).setStaticConnectors(list).setAllowDirectConnectionsOnly(true));
}
server.start();
locator = (ServerLocatorInternal) createNonHALocator(isNetty);
ClientSessionFactory factory = createSessionFactory(locator);
Topology topology = locator.getTopology();
assertEquals(1, topology.getMembers().size());
factory.close();
TopologyMemberImpl member = topology.getMembers().iterator().next();
if (isNetty) {
assertEquals(NettyConnectorFactory.class.getName(), member.getLive().getFactoryClassName());
} else {
assertEquals(InVMConnectorFactory.class.getName(), member.getLive().getFactoryClassName());
}
} finally {
try {
locator.close();
} catch (Exception ignored) {
}
try {
server.stop();
} catch (Exception ignored) {
}
server = null;
locator = null;
}
}
use of org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl in project activemq-artemis by apache.
the class QuorumManager method vote.
/**
* ask the quorum to vote within a specific quorum.
*
* @param quorumVote the vote to acquire
*/
public void vote(final QuorumVote quorumVote) {
List<VoteRunnable> runnables = new ArrayList<>();
synchronized (voteRunnables) {
if (!started)
return;
// send a vote to each node
ActiveMQServerLogger.LOGGER.initiatingQuorumVote(quorumVote.getName());
for (TopologyMemberImpl tm : clusterController.getDefaultClusterTopology().getMembers()) {
// but not ourselves
if (!tm.getNodeId().equals(clusterController.getNodeID().toString())) {
Pair<TransportConfiguration, TransportConfiguration> pair = tm.getConnector();
final TransportConfiguration serverTC = pair.getA();
VoteRunnable voteRunnable = new VoteRunnable(serverTC, quorumVote);
runnables.add(voteRunnable);
}
}
if (runnables.size() > 0) {
voteRunnables.put(quorumVote, new VoteRunnableHolder(quorumVote, runnables, runnables.size()));
for (VoteRunnable runnable : runnables) {
executor.submit(runnable);
}
} else {
quorumVote.allVotesCast(clusterController.getDefaultClusterTopology());
}
}
}
use of org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl in project activemq-artemis by apache.
the class ClusterTestBase method waitForFailoverTopology.
protected void waitForFailoverTopology(final int bNode, final int... nodes) throws Exception {
ActiveMQServer server = servers[bNode];
log.debug("waiting for " + Arrays.toString(nodes) + " on the topology for server = " + server);
long start = System.currentTimeMillis();
final int waitMillis = 2000;
final int sleepTime = 50;
int nWaits = 0;
while (server.getClusterManager() == null && nWaits++ < waitMillis / sleepTime) {
Thread.sleep(sleepTime);
}
Set<ClusterConnection> ccs = server.getClusterManager().getClusterConnections();
if (ccs.size() != 1) {
throw new IllegalStateException("You need a single cluster connection on this version of waitForTopology on ServiceTestBase");
}
boolean exists = false;
for (int node : nodes) {
ClusterConnectionImpl clusterConnection = (ClusterConnectionImpl) ccs.iterator().next();
Topology topology = clusterConnection.getTopology();
TransportConfiguration nodeConnector = servers[node].getClusterManager().getClusterConnections().iterator().next().getConnector();
do {
Collection<TopologyMemberImpl> members = topology.getMembers();
for (TopologyMemberImpl member : members) {
if (member.getConnector().getA() != null && member.getConnector().getA().equals(nodeConnector)) {
exists = true;
break;
}
}
if (exists) {
break;
}
Thread.sleep(10);
} while (System.currentTimeMillis() - start < WAIT_TIMEOUT);
if (!exists) {
String msg = "Timed out waiting for cluster topology of " + Arrays.toString(nodes) + " (received " + topology.getMembers().size() + ") topology = " + topology + ")";
log.error(msg);
logTopologyDiagram();
throw new Exception(msg);
}
}
}
Aggregations