Package org.jgroups.stack

Examples of org.jgroups.stack.NakReceiverWindow$Listener


        assertNotNull(win.get(2));
    }


    public void test8() throws Exception {
        NakReceiverWindow win=new NakReceiverWindow(null, 1);
        win.add(1, new Message());
        win.add(2, new Message());
        win.add(3, new Message());
        win.add(4, new Message());
        win.add(6, new Message());

        //System.out.println("highest received=" + win.getHighestReceived() +
        //     "\nhighest_seen=" + win.getHighestSeen() +
        //     "\nhighest_delivered=" + win.getHighestDelivered());
        assertTrue(win.getHighestSeen() == 4);
    }
View Full Code Here


        assertTrue(((Integer)win.remove().getObject()).intValue() == 3);
    }


    public void test13() throws Exception {
        NakReceiverWindow win=new NakReceiverWindow(null, 1);
        win.add(1, new Message());
        win.add(2, new Message());
        win.add(3, new Message());
        win.add(4, new Message());
        assertEquals(1, win.getLowestSeen());
        assertEquals(4, win.getHighestSeen());

        win.remove();
        win.remove();
        win.add(5, new Message());
        win.add(6, new Message());
        assertEquals(1, win.getLowestSeen());
        assertEquals(6, win.getHighestSeen());
        win.stable(2);
        assertEquals(2, win.getLowestSeen());
    }
View Full Code Here


    void add(int num_msgs) {
        long start, stop;
        double time_per_msg;
        NakReceiverWindow win=new NakReceiverWindow(null, 1);
        start=System.currentTimeMillis();
        for(int i=1; i < 1 + num_msgs; i++) {
            win.add(i, new Message());
        }
        stop=System.currentTimeMillis();
        time_per_msg=(stop-start) / (double)num_msgs;
        System.out.println("-- time for " + num_msgs + " msgs: " + (stop-start) + ", " + time_per_msg + " ms/msg");
    }
View Full Code Here

        PbcastHeader hdr;
        Message m, copy;
        View v;
        Vector mbrs;
        Address key;
        NakReceiverWindow win;


        switch(evt.getType()) {

            case Event.MSG:
                m=(Message) evt.getArg();
                if(m.getDest() != null && !m.getDest().isMulticastAddress()) {
                    break; // unicast address: not null and not mcast, pass down unchanged
                }
                else {      // multicast address
                    hdr=new PbcastHeader(PbcastHeader.MCAST_MSG, seqno);
                    m.putHeader(getName(), hdr);

                    // put message in NakReceiverWindow (to be on the safe side if we don't receive it ...)
                    synchronized(digest) {
                        win=(NakReceiverWindow) digest.get(local_addr);
                        if(win == null) {
                            if(log.isInfoEnabled()) log.info("NakReceiverWindow for sender " + local_addr +
                                                        " not found. Creating new NakReceiverWindow starting at seqno=" + seqno);
                            win=new NakReceiverWindow(local_addr, seqno);
                            digest.put(local_addr, win);
                        }
                        copy=m.copy();
                        copy.setSrc(local_addr);
                        win.add(seqno, copy);
                    }
                    seqno++;
                    break;
                }

            case Event.SET_DIGEST:
                setDigest((Digest) evt.getArg());
                return// don't pass down

            case Event.GET_DIGEST:  // don't pass down
                passUp(new Event(Event.GET_DIGEST_OK, getDigest()));
                return;

            case Event.GET_DIGEST_STATE:  // don't pass down
                passUp(new Event(Event.GET_DIGEST_STATE_OK, getDigest()));
                return;

            case Event.VIEW_CHANGE:
                v=(View) evt.getArg();
                if(v == null) {
                    if(log.isErrorEnabled()) log.error("view is null !");
                    break;
                }
                mbrs=v.getMembers();

                // update internal membership list
                synchronized(members) {
                    members.removeAllElements();
                    for(int i=0; i < mbrs.size(); i++)
                        members.addElement(mbrs.elementAt(i));
                }

                // delete all members in digest that are not in new membership list
                if(mbrs.size() > 0) {
                    synchronized(digest) {
                        for(Enumeration e=digest.keys(); e.hasMoreElements();) {
                            key=(Address) e.nextElement();
                            if(!mbrs.contains(key)) {
                                win=(NakReceiverWindow) digest.get(key);
                                win.reset();
                                digest.remove(key);
                            }
                        }
                    }
                }

                // add all members from new membership list that are not yet in digest
                for(int i=0; i < mbrs.size(); i++) {
                    key=(Address) mbrs.elementAt(i);
                    if(!digest.containsKey(key)) {
                        digest.put(key, new NakReceiverWindow(key, 1));
                    }
                }

                if(dynamic) {
                    gossip_interval=computeGossipInterval(members.size(), desired_avg_gossip);
View Full Code Here

     to a certain sender is looked up in a hashtable. Then, the message is added to the NakReceiverWindow.
     As many messages as possible are then removed from the table and passed up.
     */
    void handleUpMessage(Message m, PbcastHeader hdr) {
        Address sender=m.getSrc();
        NakReceiverWindow win=null;
        Message tmpmsg;
        long tmp_seqno=hdr.seqno;

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

        synchronized(digest) {
            win=(NakReceiverWindow) digest.get(sender);
            if(win == null) {
                if(warn) log.warn("NakReceiverWindow for sender " + sender +
                                                       " not found. Creating new NakReceiverWindow starting at seqno=" + tmp_seqno);
                win=new NakReceiverWindow(sender, tmp_seqno);
                digest.put(sender, win);
            }

            // *************************************
            // The header was removed before, so we add it again for the NakReceiverWindow. When there is a
            // retransmission request, the header will already be attached to the message (both message and
            // header are *copied* into delivered_msgs when a message is removed from NakReceiverWindow).
            // *************************************
            m.putHeader(getName(), hdr);
            win.add(tmp_seqno, m);


                if(log.isInfoEnabled()) log.info("receiver window for " + sender + " is " + win);

            // Try to remove as many message as possible and send them up the stack
            while((tmpmsg=win.remove()) != null) {
                tmpmsg.removeHeader(getName()); // need to remove header again, so upper protocols don't get confused
                passUp(new Event(Event.MSG, tmpmsg));
            }

            // Garbage collect messages if singleton member (because then we won't receive any gossips, triggering
            // garbage collection)
            if(members.size() == 1) {
                tmp_seqno=Math.max(tmp_seqno - gc_lag, 0);
                if(tmp_seqno <= 0) {
                }
                else {
                    if(trace) log.trace("deleting messages < " + tmp_seqno + " from " + sender);
                    win.stable(tmp_seqno);
                }
            }
        }
    }
View Full Code Here

     */
    Digest getDigest() {
        Digest ret=new Digest(digest.size());
        long highest_seqno, lowest_seqno;
        Address key;
        NakReceiverWindow win;

        for(Enumeration e=digest.keys(); e.hasMoreElements();) {
            key=(Address) e.nextElement();
            win=(NakReceiverWindow) digest.get(key);
            lowest_seqno=win.getLowestSeen();
            highest_seqno=win.getHighestSeen();
            ret.add(key, lowest_seqno, highest_seqno);
        }

        if(log.isInfoEnabled()) log.info("digest is " + ret);

View Full Code Here

    /**
     * Sets (or resets) the contents of the 'digest' table. Its current messages will be deleted and the
     * NakReceiverTables reset.
     */
    void setDigest(Digest d) {
        NakReceiverWindow win;

        long tmp_seqno=1;

        synchronized(digest) {
            for(Enumeration e=digest.elements(); e.hasMoreElements();) {
                win=(NakReceiverWindow) e.nextElement();
                win.reset();
            }
            digest.clear();


            Map.Entry entry;
            Address sender;
            org.jgroups.protocols.pbcast.Digest.Entry val;
            for(Iterator it=d.senders.entrySet().iterator(); it.hasNext();) {
                entry=(Map.Entry)it.next();
                sender=(Address)entry.getKey();
                if(sender == null) {
                    if(log.isErrorEnabled()) log.error("cannot set item because sender is null");
                    continue;
                }
                val=(org.jgroups.protocols.pbcast.Digest.Entry)entry.getValue();
                tmp_seqno=val.high_seqno;
                digest.put(sender, new NakReceiverWindow(sender, tmp_seqno + 1)); // next to expect, digest had *last* seen !
            }
        }
    }
View Full Code Here


    String printDigest() {
        long highest_seqno;
        Address key;
        NakReceiverWindow win;
        StringBuffer sb=new StringBuffer();

        for(Enumeration e=digest.keys(); e.hasMoreElements();) {
            key=(Address) e.nextElement();
            win=(NakReceiverWindow) digest.get(key);
            highest_seqno=win.getHighestSeen();
            sb.append(key + ": " + highest_seqno + '\n');
        }
        return sb.toString();
    }
View Full Code Here

    }


    String printIncomingMessageQueue() {
        StringBuffer sb=new StringBuffer();
        NakReceiverWindow win;

        win=(NakReceiverWindow) digest.get(local_addr);
        sb.append(win);
        return sb.toString();
    }
View Full Code Here

     */
    void handleGossip(Gossip gossip) {
        long my_low=0, my_high=0, their_low, their_high;
        Hashtable ht=null;
        Digest their_digest;
        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) {
            if(warn) log.warn("gossip is null or digest is null");
            return;
        }

        /* 1. If gossip sender is null, we cannot ask it for missing messages anyway, so discard gossip ! */
        if(gossip.sender == null) {
            if(log.isErrorEnabled()) log.error("sender of gossip is null; " +
                                                 "don't know where to send XMIT_REQ to. Discarding gossip");
            return;
        }

        /* 2. Don't process the gossip if the sender of the gossip is not a member anymore. If it is a newly
           joined member, discard it as well (we can't tell the difference). When the new member will be
           added to the membership, then its gossips will be processed */
        if(!members.contains(gossip.sender)) {
            if(warn) log.warn("sender " + gossip.sender +
                                                " is not a member. Gossip will not be processed");
            if(shun)
                shunInvalidGossiper(gossip.sender);
            return;
        }


        /* 3. If this gossip was received before, just discard it and return (don't process the
           same gossip twice). This prevents flooding of the gossip sender with retransmission reqs */
        while(gossip_list.size() >= max_gossip_cache) // first delete oldest gossips
            gossip_list.removeFromHead();

        if(gossip_list.contains(gossip))         // already received, don't re-broadcast
            return;
        else
            gossip_list.add(gossip.copy());      // add to list of received gossips



        /* 4. Send a HEARD_FROM event containing all members in the gossip-chain down to the FD layer.
           This ensures that we don't suspect them */
        seen_list=gossip.getSeenList();
        if(seen_list.size() > 0)
            passDown(new Event(Event.HEARD_FROM, seen_list.clone()));



        /* 5. Compare their digest against ours. Find out if some messages in the their digest are
           not in our digest. If yes, put them in the 'ht' hashtable for retransmission */
        their_digest=gossip.digest;

        Map.Entry entry;
        Address sender;
        org.jgroups.protocols.pbcast.Digest.Entry val;
        for(Iterator it=their_digest.senders.entrySet().iterator(); it.hasNext();) {
            entry=(Map.Entry)it.next();
            sender=(Address)entry.getKey();
            val=(org.jgroups.protocols.pbcast.Digest.Entry)entry.getValue();
            their_low=val.low_seqno;
            their_high=val.high_seqno;
            if(their_low == 0 && their_high == 0)
                continue; // won't have any messages for this sender, don't even re-send

            win=(NakReceiverWindow) digest.get(sender);
            if(win == null) {
                // this specific sender in this digest is probably not a member anymore, new digests
                // won't contain it. for now, just ignore it. if it is a new member, it will be in the next
                // gossips

                    if(warn) log.warn("sender " + sender + " not found, skipping...");
                continue;
            }

            my_low=win.getLowestSeen();
            my_high=win.getHighestSeen();
            if(my_high < their_high) {
                // changed by Bela (June 26 2003) - replaced my_high with my_low (not tested though !)
                if(my_low + 1 < their_low) {
                }
                else {
                    missing_msgs=win.getMissingMessages(my_high, their_high);
                    if(missing_msgs != null) {
                        if(log.isInfoEnabled())
                            log.info("asking " + gossip.sender + " for retransmission of " +
                                    sender + ", missing messages: " + missing_msgs + "\nwin for " + sender + ":\n" + win + '\n');
                        if(ht == null) ht=new Hashtable();
View Full Code Here

TOP

Related Classes of org.jgroups.stack.NakReceiverWindow$Listener

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.