use of org.jgroups.View in project JGroups by belaban.
the class DiagnosticsHandler method defaultHeaders.
protected String defaultHeaders() {
if (transport == null)
return "";
Address local_addr = transport.localAddress();
View view = transport.view();
int num_members = view != null ? view.size() : 0;
return String.format("local_addr=%s [ip=%s, version=%s, cluster=%s, %d mbr(s)]\n", local_addr != null ? local_addr : "n/a", transport.getLocalPhysicalAddress(), Version.description, transport.getClusterName(), num_members);
}
use of org.jgroups.View in project wildfly by wildfly.
the class ChannelCommandDispatcherFactory method viewAccepted.
@Override
public void viewAccepted(View view) {
View oldView = this.view.getAndSet(view);
if (oldView != null) {
List<Address> leftMembers = View.leftMembers(oldView, view);
if (leftMembers != null) {
this.members.keySet().removeAll(leftMembers);
}
if (!this.listeners.isEmpty()) {
Address localAddress = this.dispatcher.getChannel().getAddress();
ViewMembership oldMembership = new ViewMembership(localAddress, oldView, this);
ViewMembership membership = new ViewMembership(localAddress, view, this);
for (Map.Entry<GroupListener, ExecutorService> entry : this.listeners.entrySet()) {
GroupListener listener = entry.getKey();
ExecutorService executor = entry.getValue();
Runnable listenerTask = new Runnable() {
@Override
public void run() {
try {
listener.membershipChanged(oldMembership, membership, view instanceof MergeView);
} catch (Throwable e) {
ClusteringLogger.ROOT_LOGGER.warn(e.getLocalizedMessage(), e);
}
}
};
try {
executor.submit(listenerTask);
} catch (RejectedExecutionException e) {
// Executor was shutdown
}
}
}
}
}
use of org.jgroups.View in project wildfly by wildfly.
the class PartitionServlet method doGet.
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
boolean partition = Boolean.valueOf(request.getParameter(PARTITION));
this.log("Simulating network partitions? " + partition);
try {
if (partition) {
// Store views for future merge event
GMS gms = this.channel.getProtocolStack().findProtocol(GMS.class);
mergeViews = new HashMap<>();
this.channel.getView().getMembers().forEach(address -> mergeViews.put(address, View.create(address, gms.getViewId().getId() + 1, address)));
// Wait a few seconds to ensure everyone stored a full view
Thread.sleep(VIEWS_TIMEOUT);
// Simulate partitions by injecting DISCARD protocol
DISCARD discard = new DISCARD();
discard.setDiscardAll(true);
this.channel.getProtocolStack().insertProtocol(discard, ProtocolStack.Position.ABOVE, TP.class);
// Speed up partitioning
View view = View.create(this.channel.getAddress(), gms.getViewId().getId() + 1, this.channel.getAddress());
gms.installView(view);
} else {
this.channel.getProtocolStack().removeProtocol(DISCARD.class);
// Wait a few seconds for the other node to remove DISCARD so it does not discard our MERGE request
Thread.sleep(VIEWS_TIMEOUT);
// Since the coordinator is determined by ordering the address in org.jgroups.protocols.pbcast.Merger#determineMergeLeader
// let just all nodes send the merge..
this.log("Passing event up the stack: " + new Event(Event.MERGE, mergeViews));
GMS gms = this.channel.getProtocolStack().findProtocol(GMS.class);
gms.up(new Event(Event.MERGE, mergeViews));
mergeViews = null;
}
response.getWriter().write("Success");
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (Exception e) {
throw new ServletException(e);
}
}
use of org.jgroups.View in project JGroups by belaban.
the class DNSDiscoveryTester method runTestAndCheckIfViewWasReceived.
public boolean runTestAndCheckIfViewWasReceived(String dnsQuery, String recordType) throws Exception {
List<JChannel> channels = new ArrayList<>();
CountDownLatch waitForViewToForm = new CountDownLatch(1);
for (int i = 0; i < numberOfTestedInstances; ++i) {
DNS_PING ping = new DNS_PING();
ping.dns_resolver = dnsResolverBuilder.build();
ping.dns_query = dnsQuery;
ping.dns_record_type = recordType;
ping.dns_address = "fake.com";
Protocol[] protocols = { new TCP().setBindAddress(InetAddress.getLoopbackAddress()).setBindPort(portStart).setPortRange(1), ping, new NAKACK2(), new UNICAST3(), new STABLE(), new GMS().setJoinTimeout(timeout) };
JChannel c = new JChannel(protocols).name(String.valueOf(i + 1));
channels.add(c);
c.setReceiver(new Receiver() {
@Override
public void viewAccepted(View view) {
if (view.getMembers().size() == numberOfTestedInstances) {
waitForViewToForm.countDown();
}
}
});
c.connect("TEST");
}
boolean viewReceived = waitForViewToForm.await(timeout, unit);
channels.forEach(JChannel::close);
return viewReceived;
}
use of org.jgroups.View in project JGroups by belaban.
the class INJECT_VIEW method injectView.
@ManagedOperation(description = "Inject a view (example of view string format: A=A/B/C;B=B/C;C=C)")
public synchronized void injectView(String newView) {
try {
log.info("Received request to inject view %s", newView);
String[] perNode = newView.split(NODE_VIEWS_SEPARATOR);
String thisNodeAddress = getProtocolStack().getChannel().getAddressAsString();
for (String nodeView : perNode) {
if (nodeView.startsWith(thisNodeAddress)) {
log.info("[channel: %s] Injecting a new view: %s", thisNodeAddress, nodeView);
long viewId = getProtocolStack().getChannel().getView().getViewId().getId() + 1;
List<Address> nodes = new ArrayList<>();
for (String nodeName : nodeView.split(VIEW_SEPARATOR)[1].split(NAMES_SEPARATOR)) {
for (Map.Entry<Address, String> entry : NameCache.getContents().entrySet()) {
if (nodeName.equals(entry.getValue())) {
log.debug("[channel: %s] Found name: <%s> for address: <%s>", entry.getValue(), entry.getKey().toString());
nodes.add(entry.getKey());
break;
}
}
}
View view = new View(nodes.get(0), viewId, nodes);
GMS gms = getProtocolStack().findProtocol(GMS.class);
gms.installView(view);
log.info("[channel: %s] Injection finished of view: %s", thisNodeAddress, nodeView);
}
}
} catch (Exception e) {
log.warn(e.getMessage(), e);
}
}
Aggregations