Package org.jgroups.util

Examples of org.jgroups.util.List$ListEnumerator


  RspList     rsp_list;
  FlushRsp    retval=new FlushRsp();
  Digest      digest;
  long[]      min, max;
  long[]      lower[];
  List        unstable_msgs=new List();
  boolean     get_lower_msgs=false;

  highest_delivered_msgs=new long[members.size()];
  min=new long[members.size()];
  max=new long[members.size()];


  /* Determine the highest seqno (for each member) that was delivered to the application
     (i.e., consumed by the application). Stores result in array 'highest_delivered_msgs' */
  getHighestDeliveredSeqnos();

  for(int i=0; i < highest_delivered_msgs.length; i++)
      min[i]=max[i]=highest_delivered_msgs[i];


  /* Call the handleFlush() method of all existing members. The highest seqnos seen by the coord
     is the argument */
   if(log.isInfoEnabled()) log.info("calling handleFlush(" + dests + ')');
  passDown(new Event(Event.SWITCH_OUT_OF_BAND)); // we need out-of-band control for FLUSH ...
  MethodCall call = new MethodCall("handleFlush", new Object[] {dests, highest_delivered_msgs.clone()},
    new String[] {Vector.class.getName(), long[].class.getName()});
  rsp_list=callRemoteMethods(dests, call, GroupRequest.GET_ALL, 0);
   if(log.isInfoEnabled()) log.info("flush done");


  /* Process all the responses (Digest): compute a range of messages (min and max seqno) for each
     member that has to be re-broadcast; FlushRsp contains those messages. They will be re-braodcast
     by the cordinator (in the GMS protocol). */
  for(int i=0; i < rsp_list.size(); i++) {
      Rsp rsp=(Rsp)rsp_list.elementAt(i);
      if(rsp.wasReceived()) {
    digest=(Digest)rsp.getValue();
    if(digest != null) {
        for(int j=0; j < digest.highest_seqnos.length && j < min.length; j++) {
      min[j]=Math.min(min[j], digest.highest_seqnos[j]);
      max[j]=Math.max(max[j], digest.highest_seqnos[j]);
        }
        if(digest.msgs.size() > 0) {
      for(Enumeration e=digest.msgs.elements(); e.hasMoreElements();)
          unstable_msgs.add(e.nextElement());
        }
    }
      }
  } // end for-loop



  /* If any of the highest msgs of the flush replies were lower than the ones sent by this
     coordinator, we have to re-broadcast them. (This won't occur often)
     Compute the range between min and highest_delivered_msgs */
  lower=new long[min.length][]; // stores (for each mbr) the range of seqnos (e.g. 20 24): send msgs
              // 21, 22 and 23 and 24 (excluding lower and including upper range)

  for(int i=0; i < min.length; i++) {
      if(min[i] < highest_delivered_msgs[i]) {    // will almost never be the case
    lower[i]=new long[2];
    lower[i][0]=min[i];                     // lower boundary (excluding)
    lower[i][1]=highest_delivered_msgs[i]// upper boundary (including)
    get_lower_msgs=true;
      }
  }
  if(get_lower_msgs) {
      get_msgs=null;
      synchronized(get_msgs_mutex) {
    passDown(new Event(Event.GET_MSGS, lower));
    try {
        get_msgs_mutex.wait(get_msgs_timeout);
    }
    catch(Exception e) {}
      }
      if(get_msgs != null) {
    for(Enumeration e=get_msgs.elements(); e.hasMoreElements();)
        unstable_msgs.add(e.nextElement());
      }
  }
  retval.unstable_msgs=unstable_msgs.getContents();
  if(rsp_list.numSuspectedMembers() > 0) {
      retval.result=false;
      retval.failed_mbrs=rsp_list.getSuspectedMembers();
  }

View Full Code Here



    public void localAddressSet(Address addr) {
        // Add own address to initial_hosts if not present: we must always be able to ping ourself !
        if(initial_hosts != null && local_addr != null) {
            List hlist;
            boolean inInitialHosts=false;
            for(Enumeration en=initial_hosts.elements(); en.hasMoreElements() && !inInitialHosts;) {
                hlist=(List)en.nextElement();
                if(hlist.contains(local_addr)) {
                    inInitialHosts=true;
                }
            }
            if(!inInitialHosts) {
                hlist=new List();
                hlist.add(local_addr);
                initial_hosts.add(hlist);
                if(log.isDebugEnabled())
                    log.debug("adding my address (" + local_addr + ") to initial_hosts; initial_hosts=" + initial_hosts);
            }
        }
View Full Code Here

            Util.sleep(500);
        }
        else {
            if(initial_hosts != null && initial_hosts.size() > 0) {
                IpAddress h;
                List hlist;
                msg=new Message(null);
                msg.putHeader(getName(), new PingHeader(PingHeader.GET_MBRS_REQ, null));
                for(Enumeration en=initial_hosts.elements(); en.hasMoreElements();) {
                    hlist=(List)en.nextElement();
                    boolean isMember=false;
                    for(Enumeration hen=hlist.elements(); hen.hasMoreElements() && !isMember;) {
                        h=(IpAddress)hen.nextElement();
                        msg.setDest(h);
                        if(trace)
                            log.trace("[FIND_INITIAL_MBRS] sending PING request to " + msg.getDest());
                        passDown(new Event(Event.MSG, msg.copy()));
View Full Code Here

    /**
     * Input is "daddy[8880],sindhu[8880],camille[5555]. Return List of IpAddresses
     */
    private List createInitialHosts(String l) throws UnknownHostException {
        List tmp=new List();
        StringTokenizer tok=new StringTokenizer(l, ",");
        String t;

        while(tok.hasMoreTokens()) {
            try {
                t=tok.nextToken();
                String host=t.substring(0, t.indexOf('['));
                int port=Integer.parseInt(t.substring(t.indexOf('[') + 1, t.indexOf(']')));
                List hosts=new List();
                for(int i=port; i < port + port_range; i++) {
                    hosts.add(new IpAddress(host, i));
                }
                tmp.add(hosts);
            }
            catch(NumberFormatException e) {
                if(log.isErrorEnabled()) log.error("exeption is " + e);
View Full Code Here

        NakReceiverWindow win;
        Message msg;
        Address dest;
        Vector new_dests;
        PbcastHeader hdr;
        List missing_msgs; // list of missing messages (for retransmission) (List of Longs)

        if(trace)
            log.trace("(from " + local_addr + ") received gossip " + gossip.shortForm() + " from " + gossip.sender);

        if(gossip == null || gossip.digest == null) {
View Full Code Here

     * <code>requester</code>
     */
    void handleXmitRequest(Address requester, Hashtable xmit_reqs) {
        NakReceiverWindow win;
        Address sender;
        List msgs, missing_msgs, xmit_msgs;
        Message msg;

        if(requester == null) {
            if(log.isErrorEnabled()) log.error("requester is null");
            return;
        }

        if(log.isInfoEnabled()) log.info("retransmission requests are " + printXmitReqs(xmit_reqs));
        for(Enumeration e=xmit_reqs.keys(); e.hasMoreElements();) {
            sender=(Address) e.nextElement();
            win=(NakReceiverWindow) digest.get(sender);
            if(win == null) {
                if(warn) log.warn("sender " + sender +
                                                         " not found in my digest; skipping retransmit request !");
                continue;
            }

            missing_msgs=(List) xmit_reqs.get(sender);
            msgs=win.getMessagesInList(missing_msgs)// msgs to be sent back to requester



            // re-send the messages to requester. don't add a header since they already have headers
            // (when added to the NakReceiverWindow, the headers were not removed)
            xmit_msgs=new List();
            for(Enumeration en=msgs.elements(); en.hasMoreElements();) {
                msg=((Message) en.nextElement()).copy();
                xmit_msgs.add(msg);
            }

            // create a msg with the List of xmit_msgs as contents, add header
View Full Code Here


        public void run() {
            GossipEntry entry;
            PbcastHeader hdr;
            List xmit_msgs;
            byte[] data;

            while(t != null && queue != null) {
                try {
                    entry=(GossipEntry) queue.remove();
View Full Code Here

     * Correction (bela April 19 2005): we access no instance variables, all vars are allocated on the stack, so
     * this method should be reentrant: removed 'synchronized' keyword
     */
    private void handleIncomingPacket(Address dest, Address sender, byte[] data, int offset, int length) {
        Message                msg=null;
        List                   l=null// used if bundling is enabled
        short                  version;
        boolean                is_message_list, multicast;
        byte                   flags;

        try {
            synchronized(in_stream) {
                in_stream.setData(data, offset, length);
                buf_in_stream.reset(length);
                version=dis.readShort();
                if(Version.compareTo(version) == false) {
                    if(warn) {
                        StringBuffer sb=new StringBuffer();
                        sb.append("packet from ").append(sender).append(" has different version (").append(version);
                        sb.append(") from ours (").append(Version.printVersion()).append("). ");
                        if(discard_incompatible_packets)
                            sb.append("Packet is discarded");
                        else
                            sb.append("This may cause problems");
                        log.warn(sb);
                    }
                    if(discard_incompatible_packets)
                        return;
                }

                flags=dis.readByte();
                is_message_list=(flags & LIST) == LIST;
                multicast=(flags & MULTICAST) == MULTICAST;

                if(is_message_list)
                    l=bufferToList(dis, dest, multicast);
                else
                    msg=bufferToMessage(dis, dest, sender, multicast);
            }

            LinkedList msgs=new LinkedList();
            if(is_message_list) {
                for(Enumeration en=l.elements(); en.hasMoreElements();)
                    msgs.add(en.nextElement());
            }
            else
                msgs.add(msg);

View Full Code Here

        retval=new Buffer(out_stream.getRawBuffer(), 0, out_stream.size());
        return retval;
    }

    private List bufferToList(DataInputStream instream, Address dest, boolean multicast) throws Exception {
        List                    l=new List();
        DataInputStream         in=null;
        int                     len;
        Message                 msg;
        Address                 src;

        try {
            len=instream.readInt();
            src=Util.readAddress(instream);
            for(int i=0; i < len; i++) {
                msg=new Message(false); // don't create headers, readFrom() will do this
                msg.readFrom(instream);
                postUnmarshallingList(msg, dest, multicast);
                msg.setSrc(src);
                l.add(msg);
            }
            return l;
        }
        finally {
            Util.close(in);
View Full Code Here

                bundling_timer=null;
            }
        }

        private void addMessage(Message msg, Address dest) { // no sync needed, never called by multiple threads concurrently
            List    tmp;
            synchronized(msgs) {
                tmp=(List)msgs.get(dest);
                if(tmp == null) {
                    tmp=new List();
                    msgs.put(dest, tmp);
                }
                tmp.add(msg);
                num_msgs++;
            }
        }
View Full Code Here

TOP

Related Classes of org.jgroups.util.List$ListEnumerator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.