Package org.jgroups.stack

Examples of org.jgroups.stack.NakReceiverWindow$Listener


     *                     *received* will be returned. E.g. for [+3 +4 +5 -6 +7 +8], the highest_seqno_received is 8,
     *                     whereas the higheset_seqno_seen (deliverable) is 5.
     */
    private Range getLowestAndHighestSeqno(Address sender, boolean stop_at_gaps) {
        Range r=null;
        NakReceiverWindow win;

        if(sender == null) {
            if(log.isErrorEnabled()) {
                log.error("sender is null");
            }
            return r;
        }
        synchronized(received_msgs) {
            win=(NakReceiverWindow)received_msgs.get(sender);
        }
        if(win == null) {
            if(log.isErrorEnabled()) {
                log.error("sender " + sender + " not found in received_msgs");
            }
            return r;
        }
        if(stop_at_gaps) {
            r=new Range(win.getLowestSeen(), win.getHighestSeen());       // deliverable messages (no gaps)
        }
        else {
            r=new Range(win.getLowestSeen(), win.getHighestReceived() + 1); // received messages
        }
        return r;
    }
View Full Code Here


     * Returns the highest seqno seen from sender. E.g. if we received 1, 2, 4, 5 from P, then 5 will be returned
     * (doesn't take gaps into account). If we are the sender, we will return the highest seqno <em>sent</em> rather
     * then <em>received</em>
     */
    private long getHighSeqnoSeen(Address sender) {
        NakReceiverWindow win;
        long ret=0;

        if(sender == null) {
            if(log.isErrorEnabled()) {
                log.error("sender is null");
            }
            return ret;
        }
        if(sender.equals(local_addr)) {
            return seqno - 1;
        }

        synchronized(received_msgs) {
            win=(NakReceiverWindow)received_msgs.get(sender);
        }
        if(win == null) {
            if(log.isErrorEnabled()) {
                log.error("sender " + sender + " not found in received_msgs");
            }
            return ret;
        }
        ret=win.getHighestReceived();
        return ret;
    }
View Full Code Here

     * which is equal to the local address, garbage collect all messages <= seqno at digest[P]. Update received_msgs:
     * for each sender P in the digest and its highest seqno seen SEQ, garbage collect all delivered_msgs in the
     * NakReceiverWindow corresponding to P which are <= seqno at digest[P].
     */
    private void stable(Digest d) {
        NakReceiverWindow recv_win;
        long my_highest_rcvd;        // highest seqno received in my digest for a sender P
        long stability_highest_rcvd; // highest seqno received in the stability vector for a sender P

        if(members == null || local_addr == null || d == null) {
            if(warn)
                log.warn("members, local_addr or digest are null !");
            return;
        }

        if(trace) {
            log.trace("received stable digest " + d);
        }

        Map.Entry entry;
        Address sender;
        org.jgroups.protocols.pbcast.Digest.Entry val;
        long high_seqno_delivered, high_seqno_received;

        for(Iterator it=d.senders.entrySet().iterator(); it.hasNext();) {
            entry=(Map.Entry)it.next();
            sender=(Address)entry.getKey();
            if(sender == null)
                continue;
            val=(org.jgroups.protocols.pbcast.Digest.Entry)entry.getValue();
            high_seqno_delivered=val.high_seqno;
            high_seqno_received=val.high_seqno_seen;


            // check whether the last seqno received for a sender P in the stability vector is > last seqno
            // received for P in my digest. if yes, request retransmission (see "Last Message Dropped" topic
            // in DESIGN)
            synchronized(received_msgs) {
                recv_win=(NakReceiverWindow)received_msgs.get(sender);
            }
            if(recv_win != null) {
                my_highest_rcvd=recv_win.getHighestReceived();
                stability_highest_rcvd=high_seqno_received;

                if(stability_highest_rcvd >= 0 && stability_highest_rcvd > my_highest_rcvd) {
                    if(trace) {
                        log.trace("my_highest_rcvd (" + my_highest_rcvd + ") < stability_highest_rcvd (" +
                                stability_highest_rcvd + "): requesting retransmission of " +
                                sender + '#' + stability_highest_rcvd);
                    }
                    retransmit(stability_highest_rcvd, stability_highest_rcvd, sender);
                }
            }

            high_seqno_delivered-=gc_lag;
            if(high_seqno_delivered < 0) {
                continue;
            }

            if(trace)
                log.trace("deleting msgs <= " + high_seqno_delivered + " from " + sender);

            // garbage collect from sent_msgs if sender was myself
            if(sender.equals(local_addr)) {
                synchronized(sent_msgs) {
                    // gets us a subset from [lowest seqno - seqno]
                    SortedMap stable_keys=sent_msgs.headMap(new Long(high_seqno_delivered));
                    if(stable_keys != null) {
                        stable_keys.clear(); // this will modify sent_msgs directly
                    }
                }
            }

            // delete *delivered* msgs that are stable
            // recv_win=(NakReceiverWindow)received_msgs.get(sender);
            if(recv_win != null)
                recv_win.stable(high_seqno_delivered)// delete all messages with seqnos <= seqno
        }
    }
View Full Code Here

        }
    }
    /* ------------------- End of Interface NakReceiverWindow.Listener ------------------- */

    private void clear() {
        NakReceiverWindow win;

        // changed April 21 2004 (bela): SourceForge bug# 938584. We cannot delete our own messages sent between
        // a join() and a getState(). Otherwise retransmission requests from members who missed those msgs might
        // fail. Not to worry though: those msgs will be cleared by STABLE (message garbage collection)

        // sent_msgs.clear();

        synchronized(received_msgs) {
            for(Iterator it=received_msgs.values().iterator(); it.hasNext();) {
                win=(NakReceiverWindow)it.next();
                win.reset();
            }
            received_msgs.clear();
        }
    }
View Full Code Here

        }
    }


    private void reset() {
        NakReceiverWindow win;

        synchronized(sent_msgs) {
            sent_msgs.clear();
            seqno=-1;
        }

        synchronized(received_msgs) {
            for(Iterator it=received_msgs.values().iterator(); it.hasNext();) {
                win=(NakReceiverWindow)it.next();
                win.destroy();
            }
            received_msgs.clear();
        }
    }
View Full Code Here

    public void start() throws IOException {
        System.out.println("num_msgs=" + num_msgs + "\ndiscard_prob=" + discard_prob);

        sender=new IpAddress("localhost", 5555);
        win=new NakReceiverWindow(sender, this, 1);
        start=System.currentTimeMillis();
        sendMessages(num_msgs);
    }
View Full Code Here

        check(win, 6, 6, 6);
    }


    public void test9() throws Exception {
        NakReceiverWindow win=new NakReceiverWindow(sender, cmd, 0);
        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("win: " + win);
        while((win.remove()) != null) ;
        win.stable(6); // 6 is ignore as it is >= highest delivered message
        System.out.println("win: " + win);
        assertNotNull(win.get(2));
        check(win, 0, 6, 4);
        win.add(5, new Message());
        check(win, 0, 6, 4);
        while((win.remove()) != null) ;
        check(win, 0, 6, 6);
        win.stable(6);
        check(win, 6, 6, 6);
    }
View Full Code Here

        check(win, 6, 6, 6);
    }


    public void testHighestDelivered() throws Exception {
        NakReceiverWindow win=new NakReceiverWindow(sender, cmd, 0);
        win.add(1, new Message());
        win.add(2, new Message());
        win.add(3, new Message());
        win.add(4, new Message());
        check(win, 0, 4, 0);
        win.add(10, new Message());
        check(win, 0, 10, 0);
        System.out.println("win: " + win);
        win.add(9, new Message());
        win.add(7, new Message());
        win.add(8, new Message());
        win.add(6, new Message());
        win.add(5, new Message());
        System.out.println("win: " + win);
        check(win, 0, 10, 0);
        while((win.remove()) != null) ;
        check(win, 0, 10, 10);
        win.stable(5);
        System.out.println("win: " + win);
        check(win, 5, 10, 10);
        win.stable(10);
        System.out.println("win: " + win);
        check(win, 10, 10, 10);
    }
View Full Code Here

        check(win, 10, 10, 10);
    }


    public void testMissingMessages() throws Exception {
        NakReceiverWindow win=new NakReceiverWindow(sender, cmd, 0);
        win.add(1, new Message());
        win.add(5, new Message());
        check(win, 0, 5, 0);
        win.add(6, new Message());
        check(win, 0, 6, 0);
        System.out.println("win: " + win);
    }
View Full Code Here

        System.out.println("win: " + win);
    }


    public void testMissingMessages2() throws Exception {
        NakReceiverWindow win=new NakReceiverWindow(sender, cmd, 0);
        win.add(1, new Message());
        win.add(5, new Message());
        check(win, 0, 5, 0);
        win.add(8, new Message());
        check(win, 0, 8, 0);
        win.add(9, new Message());
        check(win, 0, 9, 0);
        System.out.println("win: " + win);
    }
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.