Search in sources :

Example 31 with View

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);
}
Also used : Address(org.jgroups.Address) View(org.jgroups.View)

Example 32 with View

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
                }
            }
        }
    }
}
Also used : MergeView(org.jgroups.MergeView) IpAddress(org.jgroups.stack.IpAddress) Address(org.jgroups.Address) InetSocketAddress(java.net.InetSocketAddress) GroupListener(org.wildfly.clustering.group.GroupListener) DefaultExecutorService(org.jboss.as.clustering.context.DefaultExecutorService) ExecutorService(java.util.concurrent.ExecutorService) MergeView(org.jgroups.MergeView) View(org.jgroups.View) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 33 with View

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);
    }
}
Also used : ServletException(javax.servlet.ServletException) DISCARD(org.jgroups.protocols.DISCARD) Event(org.jgroups.Event) GMS(org.jgroups.protocols.pbcast.GMS) View(org.jgroups.View) ServletException(javax.servlet.ServletException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 34 with View

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;
}
Also used : TCP(org.jgroups.protocols.TCP) JChannel(org.jgroups.JChannel) ArrayList(java.util.ArrayList) Receiver(org.jgroups.Receiver) CountDownLatch(java.util.concurrent.CountDownLatch) GMS(org.jgroups.protocols.pbcast.GMS) View(org.jgroups.View) UNICAST3(org.jgroups.protocols.UNICAST3) NAKACK2(org.jgroups.protocols.pbcast.NAKACK2) STABLE(org.jgroups.protocols.pbcast.STABLE) Protocol(org.jgroups.stack.Protocol)

Example 35 with View

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);
    }
}
Also used : Address(org.jgroups.Address) ArrayList(java.util.ArrayList) GMS(org.jgroups.protocols.pbcast.GMS) Map(java.util.Map) View(org.jgroups.View) ManagedOperation(org.jgroups.annotations.ManagedOperation)

Aggregations

View (org.jgroups.View)51 Address (org.jgroups.Address)24 JChannel (org.jgroups.JChannel)14 GMS (org.jgroups.protocols.pbcast.GMS)6 Event (org.jgroups.Event)5 Receiver (org.jgroups.Receiver)5 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 ViewId (org.jgroups.ViewId)3 IOException (java.io.IOException)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 NetView (org.apache.geode.distributed.internal.membership.NetView)2 IpAddress (org.jgroups.stack.IpAddress)2 UUID (org.jgroups.util.UUID)2 java.io (java.io)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1