Package org.jgroups.stack

Examples of org.jgroups.stack.AckReceiverWindow


            entry=new Entry();
            connections.put(sender, entry);
        }
        if(entry.received_msgs != null)
            entry.received_msgs.reset();
        entry.received_msgs=new AckReceiverWindow(seqno);
        entry.recv_conn_id=conn_id;
        if(log.isTraceEnabled())
            log.trace(local_addr + ": created receiver window for " + sender + " at seqno=#" + seqno + " for conn-id=" + conn_id);
        return entry.received_msgs;
    }
View Full Code Here


            if(first) sb.append(", first");
            sb.append(')');
            log.trace(sb);
        }

        AckReceiverWindow win;
        Address send_request_for_first_seqno=null;
        synchronized(recv_table) {
            ReceiverEntry entry=recv_table.get(sender);
            win=entry != null? entry.received_msgs : null;

            if(first) {
                if(entry == null || win == null) {
                    win=createReceiverWindow(sender, entry, seqno, conn_id);
                }
                else // entry != null && win != null
                    if(conn_id != entry.recv_conn_id) {
                        if(log.isTraceEnabled())
                            log.trace(local_addr + ": conn_id=" + conn_id + " != " + entry.recv_conn_id + "; resetting receiver window");
                        win=createReceiverWindow(sender, entry, seqno, conn_id);
                    }
                    else {
                        ;
                    }
                }
            }
            else { // entry == null && win == null OR entry != null && win == null OR entry != null && win != null
                if(win == null || entry.recv_conn_id != conn_id)
                    send_request_for_first_seqno=sender; // drops the message and returns (see below)
            }
        }

        if(send_request_for_first_seqno != null) {
            sendRequestForFirstSeqno(send_request_for_first_seqno);
            return;
        }

        byte result=win.add2(seqno, msg); // win is guaranteed to be non-null if we get here
        boolean added=result > 0;
        num_msgs_received++;
        num_bytes_received+=msg.getLength();

        if(added && !msg.isFlagSet(Message.OOB))
            undelivered_msgs.incrementAndGet();

        // Cannot be replaced with if(!added), see https://jira.jboss.org/jira/browse/JGRP-1043 comment 15/Sep/09 06:57 AM

        // We *have* to do send the ACK, to cover the following scenario:
        // - A sends #3 to B
        // - B removes #3 and sends ACK(3) to A. B's next_to_remove is now 4
        // - B's ACK(3) to A is dropped by the network
        // - A keeps retransmitting #3 to B, until it gets an ACK(3)
        // -B will never ACK #3 if the 2 lines below are commented ==> endless retransmission of A's #3 !
        if(result == -1) { // only ack if seqno was < next_to_remove !
            sendAck(msg.getSrc(), seqno);
        }

        // message is passed up if OOB. Later, when remove() is called, we discard it. This affects ordering !
        // http://jira.jboss.com/jira/browse/JGRP-377
        if(msg.isFlagSet(Message.OOB)) {
            if(added)
                up_prot.up(new Event(Event.MSG, msg));
            Message oob_msg=win.removeOOBMessage();
            if(!(undelivered_msgs.get() > 0 && win.hasMessagesToRemove())) {
                if(oob_msg != null)
                    sendAckForMessage(oob_msg);
                return;
            }
        }

        final AtomicBoolean processing=win.getProcessing();
        if(!processing.compareAndSet(false, true)) {
            return;
        }

        // Try to remove (from the AckReceiverWindow) as many messages as possible as pass them up
        boolean released_processing=false;
        int num_regular_msgs_removed=0;

        // Prevents concurrent passing up of messages by different threads (http://jira.jboss.com/jira/browse/JGRP-198);
        // this is all the more important once we have a threadless stack (http://jira.jboss.com/jira/browse/JGRP-181),
        // where lots of threads can come up to this point concurrently, but only 1 is allowed to pass at a time
        // We *can* deliver messages from *different* senders concurrently, e.g. reception of P1, Q1, P2, Q2 can result in
        // delivery of P1, Q1, Q2, P2: FIFO (implemented by UNICAST) says messages need to be delivered only in the
        // order in which they were sent by their senders
        try {
            while(true) {
                List<Message> msgs=win.removeMany(processing);
                if(msgs.isEmpty()) {
                    released_processing=true;
                    return;
                }
                Message highest_removed=msgs.get(msgs.size() -1);
View Full Code Here

            entry=new ReceiverEntry();
            recv_table.put(sender, entry);
        }
        if(entry.received_msgs != null)
            entry.received_msgs.reset();
        entry.received_msgs=new AckReceiverWindow(seqno);
        entry.recv_conn_id=conn_id;
        if(log.isTraceEnabled())
            log.trace(local_addr + ": created receiver window for " + sender + " at seqno=#" + seqno + " for conn-id=" + conn_id);
        return entry.received_msgs;
    }
View Full Code Here

        super(name);
    }

    public void setUp() throws Exception {
        super.setUp();
        win=new AckReceiverWindow(1);
    }
View Full Code Here

        super.tearDown();
    }

    public void testAdd() {
        win.reset();
        win=new AckReceiverWindow(10);
        Message msg;
        assertEquals(0, win.size());
        win.add(9, msg());
        assertEquals(0, win.size());
View Full Code Here

        assertNull(win.removeOOBMessage());
    }

    public void testDuplicates() {
        boolean rc;
        win=new AckReceiverWindow(2);
        assertEquals(0, win.size());
        rc=win.add(9, msg());
        assertTrue(rc);
        rc=win.add(1, msg());
        assertFalse(rc);
View Full Code Here

                log.trace("removed " + sender + " from previous_members as we received a message from it");
            previous_members.removeElement(sender);
        }

        Entry             entry;
        AckReceiverWindow win;
        synchronized(connections) {
            entry=(Entry)connections.get(sender);
            if(entry == null) {
                entry=new Entry();
                connections.put(sender, entry);
                if(log.isTraceEnabled())
                    log.trace(local_addr + ": created new connection for dst " + sender);
            }
            win=entry.received_msgs;
            if(win == null) {
                win=new AckReceiverWindow(DEFAULT_FIRST_SEQNO);
                entry.received_msgs=win;
            }
        }

        win.add(seqno, msg); // entry.received_msgs is guaranteed to be non-null if we get here
        num_msgs_received++;
        num_bytes_received+=msg.getLength();

        // Try to remove (from the AckReceiverWindow) as many messages as possible as pass them up
        Message  m;

        // Prevents concurrent passing up of messages by different threads (http://jira.jboss.com/jira/browse/JGRP-198);
        // this is all the more important once we have a threadless stack (http://jira.jboss.com/jira/browse/JGRP-181),
        // where lots of threads can come up to this point concurrently, but only 1 is allowed to pass at a time
        // We *can* deliver messages from *different* senders concurrently, e.g. reception of P1, Q1, P2, Q2 can result in
        // delivery of P1, Q1, Q2, P2: FIFO (implemented by UNICAST) says messages need to be delivered only in the
        // order in which they were sent by their senders
        synchronized(win) {
            while((m=win.remove()) != null)
                passUp(new Event(Event.MSG, m));
        }
        return true; // msg was successfully received - send an ack back to the sender
    }
View Full Code Here

        return true;
    }


    public void stop() {
        AckReceiverWindow win;
        if(sender_win != null) {
            sender_win.stop();
            sender_win=null;
        }
        for(Iterator it=receivers.values().iterator(); it.hasNext();) {
            win=(AckReceiverWindow)it.next();
            win.reset();
        }
        receivers.clear();
    }
View Full Code Here

                if(hdr == null) // is probably a unicast message
                    break;
                switch(hdr.type) {
                    case SmackHeader.MCAST: // send an ack, then pass up (if not already received)
                        Long tmp_seqno;
                        AckReceiverWindow win;
                        Message ack_msg=new Message(sender);

                        ack_msg.putHeader(name, new SmackHeader(SmackHeader.ACK, hdr.seqno));
                        passDown(new Event(Event.MSG, ack_msg));

                        tmp_seqno=new Long(hdr.seqno);

                        if(log.isTraceEnabled())
                            log.trace("received #" + tmp_seqno + " from " + sender);

                        win=(AckReceiverWindow)receivers.get(sender);
                        if(win == null) {
                            addMember(sender);
                            win=new AckReceiverWindow(hdr.seqno);
                            receivers.put(sender, win);
                        }
                        win.add(hdr.seqno, msg);

                        // now remove as many messages as possible
                        while((tmp_msg=win.remove()) != null)
                            passUp(new Event(Event.MSG, tmp_msg));
                        return;

                    case SmackHeader.ACK:
                        addMember(msg.getSrc());
View Full Code Here

            if(first) sb.append(", first");
            sb.append(')');
            log.trace(sb);
        }

        AckReceiverWindow win;
        Address send_request_for_first_seqno=null;
        synchronized(recv_table) {
            ReceiverEntry entry=recv_table.get(sender);
            win=entry != null? entry.received_msgs : null;

            if(first) {
                if(entry == null || win == null) {
                    win=createReceiverWindow(sender, entry, seqno, conn_id);
                }
                else // entry != null && win != null
                    if(conn_id != entry.recv_conn_id) {
                        if(log.isTraceEnabled())
                            log.trace(local_addr + ": conn_id=" + conn_id + " != " + entry.recv_conn_id + "; resetting receiver window");
                        win=createReceiverWindow(sender, entry, seqno, conn_id);
                    }
                    else {
                        ;
                    }
                }
            }
            else { // entry == null && win == null OR entry != null && win == null OR entry != null && win != null
                if(win == null || entry.recv_conn_id != conn_id)
                    send_request_for_first_seqno=sender; // drops the message and returns (see below)
            }
        }

        if(send_request_for_first_seqno != null) {
            sendRequestForFirstSeqno(send_request_for_first_seqno);
            return;
        }

        byte result=win.add2(seqno, msg); // win is guaranteed to be non-null if we get here
        boolean added=result > 0;
        num_msgs_received++;
        num_bytes_received+=msg.getLength();

        if(added && !msg.isFlagSet(Message.OOB))
            undelivered_msgs.incrementAndGet();

        // Cannot be replaced with if(!added), see https://jira.jboss.org/jira/browse/JGRP-1043 comment 15/Sep/09 06:57 AM

        // We *have* to do send the ACK, to cover the following scenario:
        // - A sends #3 to B
        // - B removes #3 and sends ACK(3) to A. B's next_to_remove is now 4
        // - B's ACK(3) to A is dropped by the network
        // - A keeps retransmitting #3 to B, until it gets an ACK(3)
        // -B will never ACK #3 if the 2 lines below are commented ==> endless retransmission of A's #3 !
        if(result == -1) { // only ack if seqno was < next_to_remove !
            sendAck(msg.getSrc(), seqno);
        }

        // message is passed up if OOB. Later, when remove() is called, we discard it. This affects ordering !
        // http://jira.jboss.com/jira/browse/JGRP-377
        if(msg.isFlagSet(Message.OOB)) {
            if(added)
                up_prot.up(new Event(Event.MSG, msg));
            Message oob_msg=win.removeOOBMessage();
            if(!(undelivered_msgs.get() > 0 && win.hasMessagesToRemove())) {
                if(oob_msg != null)
                    sendAckForMessage(oob_msg);
                return;
            }
        }

        final AtomicBoolean processing=win.getProcessing();
        if(!processing.compareAndSet(false, true)) {
            return;
        }

        // Try to remove (from the AckReceiverWindow) as many messages as possible as pass them up
        boolean released_processing=false;
        int num_regular_msgs_removed=0;

        // Prevents concurrent passing up of messages by different threads (http://jira.jboss.com/jira/browse/JGRP-198);
        // this is all the more important once we have a threadless stack (http://jira.jboss.com/jira/browse/JGRP-181),
        // where lots of threads can come up to this point concurrently, but only 1 is allowed to pass at a time
        // We *can* deliver messages from *different* senders concurrently, e.g. reception of P1, Q1, P2, Q2 can result in
        // delivery of P1, Q1, Q2, P2: FIFO (implemented by UNICAST) says messages need to be delivered only in the
        // order in which they were sent by their senders
        try {
            while(true) {
                List<Message> msgs=win.removeMany(processing);
                if(msgs.isEmpty()) {
                    released_processing=true;
                    return;
                }
                Message highest_removed=msgs.get(msgs.size() -1);
View Full Code Here

TOP

Related Classes of org.jgroups.stack.AckReceiverWindow

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.