简体   繁体   中英

Why does JGroups return the same server multiple times

Ran the following sample program to see what Nodes are viewed as being in my Cluster.

import org.jgroups.JChannel;
import org.jgroups.Message;
import org.jgroups.ReceiverAdapter;
import org.jgroups.View;
import org.jgroups.util.Util;
import org.jgroups.*;

import java.io.*;
import java.util.Iterator;
import java.util.List;
import java.util.LinkedList;
import java.util.Properties;
import java.util.Vector;

public class ClusterCheck extends ReceiverAdapter
{
    JChannel channel;
    JChannelFactory channelFactory;

    String channelPropertiesPrimary;

    String user_name=System.getProperty("user.name", "n/a");
        final List<String> state=new LinkedList<String>();

    private void start() throws Exception
        {
            Properties properties = new Properties();
            FileInputStream fis = new FileInputStream( new File("myConfigfile.properties"));  
            properties.load( fis );
            channelPropertiesPrimary = properties.getProperty( "udpinfo" );
            channelFactory = new JChannelFactory();
            channel = (JChannel) channelFactory.createChannel((Object)channelPropertiesPrimary);
            channel.setOpt( Channel.VIEW, new Boolean( true ) );
            channel.setOpt( Channel.LOCAL, new Boolean( false ) );
            channel.setOpt( Channel.SUSPECT, new Boolean( true ) );
            channel.setOpt( Channel.AUTO_RECONNECT, new Boolean( true ) );
            channel.connect("myClusterName");     
            org.jgroups.View view   = channel.getView();
            if (view != null)
            {
                    System.out.println("There are " + view.getMembers().size() + " members in this Cluster");
                    Vector viewMembers      = view.getMembers();
                    for ( Iterator i = viewMembers.iterator(); i.hasNext(); )
                    {
                            System.out.println( ( i.next() ).toString() );
                    }
            }
        }

    public static void main(String[] args) throws Exception {
        new ClusterCheck().start();
    }
        public void viewAccepted(View view)
        {
            System.out.println("There are currently " + view.getMembers().size() + " members in this Cluster");
        }

        public void receive(Message msg)
        {
//              System.out.println(msg.getSrc() + ": " + msg.getObject());
        }

}

Here is part of the output I see :

 :
 :
 INFO: handling view-change up: [myServer01-59496|0] [myServer01-59496]
 There are 4 
 myServer01-21483
 7203a079-b7bb-f565-22dd-a25aeeb3eda3
 41323243-3452-abc3-569b-a5821cb4e433
 myServer01-21483
 :
 :

I understand the random numbers are the other servers, but why does it list 4 Servers in the Group but lists myServer01 twice?

Another process was running with the same Group name on the same machine.

I was expecting it to return the Node name only once no matter how many processes are running with the same group name, but it appears, JGroups finds the name of the Node for each process listening within the same Group so it is possible to have the same Node listed more than once.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM