Package org.jgroups.protocols.pbcast

Examples of org.jgroups.protocols.pbcast.NAKACK2$RetransmitTask


    public static void testStressOOB() {
        start(NUM_THREADS, NUM_MSGS, true);
    }

    private static void start(final int num_threads, final int num_msgs, boolean oob) {
        final NAKACK2 nak=new NAKACK2();
        final AtomicInteger counter=new AtomicInteger(num_msgs);
        final AtomicLong seqno=new AtomicLong(1);
        final AtomicInteger delivered_msgs=new AtomicInteger(0);
        final Lock lock=new ReentrantLock();
        final Condition all_msgs_delivered=lock.newCondition();
        final ConcurrentLinkedQueue<Long> delivered_msg_list=new ConcurrentLinkedQueue<Long>();
        final Address local_addr=Util.createRandomAddress("A");
        final Address sender=Util.createRandomAddress("B");


        nak.setDownProtocol(new Protocol() {public Object down(Event evt) {return null;}});

        nak.setUpProtocol(new Protocol() {
            public Object up(Event evt) {
                if(evt.getType() == Event.MSG) {
                    delivered_msgs.incrementAndGet();
                    NakAckHeader2 hdr=(NakAckHeader2)((Message)evt.getArg()).getHeader(NAKACK_ID);
                    if(hdr != null)
                        delivered_msg_list.add(hdr.getSeqno());

                    if(delivered_msgs.get() >= num_msgs) {
                        lock.lock();
                        try {
                            all_msgs_delivered.signalAll();
                        }
                        finally {
                            lock.unlock();
                        }
                    }
                }
                return null;
            }

            public void up(MessageBatch batch) {
                for(Message msg: batch) {
                    delivered_msgs.incrementAndGet();
                    NakAckHeader2 hdr=(NakAckHeader2)msg.getHeader(NAKACK_ID);
                    if(hdr != null)
                        delivered_msg_list.add(hdr.getSeqno());

                    if(delivered_msgs.get() >= num_msgs) {
                        lock.lock();
                        try {
                            all_msgs_delivered.signalAll();
                        }
                        finally {
                            lock.unlock();
                        }
                    }
                }
            }
        });

        nak.setDiscardDeliveredMsgs(true);
        nak.down(new Event(Event.SET_LOCAL_ADDRESS, local_addr));
        nak.down(new Event(Event.BECOME_SERVER));
        View view=View.create(local_addr, 1, local_addr, sender);
        nak.down(new Event(Event.VIEW_CHANGE, view));

        MutableDigest digest=new MutableDigest(view.getMembersRaw());
        digest.set(local_addr,0,0);
        digest.set(sender,0,0);
        nak.down(new Event(Event.SET_DIGEST, digest));

        final CountDownLatch latch=new CountDownLatch(1);
        Sender[] adders=new Sender[num_threads];
        for(int i=0; i < adders.length; i++) {
            adders[i]=new Sender(nak, latch, counter, seqno, oob, sender);
            adders[i].start();
        }

        long start=System.currentTimeMillis();
        latch.countDown(); // starts all adders

        int max_tries=30;
        lock.lock();
        try {
            while(delivered_msgs.get() < num_msgs && max_tries-- > 0) {
                try {
                    all_msgs_delivered.await(1000, TimeUnit.MILLISECONDS);
                    System.out.println("received " + delivered_msgs.get() + " msgs");
                }
                catch(InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
        finally {
            lock.unlock();
        }

        long time=System.currentTimeMillis() - start;
        double requests_sec=num_msgs / (time / 1000.0);
        System.out.println("\nTime: " + time + " ms, " + Util.format(requests_sec) + " requests / sec\n");
        System.out.println("Delivered messages: " + delivered_msg_list.size());
        if(delivered_msg_list.size() < 100)
            System.out.println("Elements: " + delivered_msg_list);

        nak.stop();

        List<Long> results=new ArrayList<Long>(delivered_msg_list);

        if(oob)
            Collections.sort(results);
View Full Code Here


    protected JChannel createChannel(String name) throws Exception {
        return new JChannel(
          new SHARED_LOOPBACK(),
          new SHARED_LOOPBACK_PING().setValue("force_sending_discovery_rsps", true),
          new MERGE3().setValue("min_interval", 1000).setValue("max_interval", 3000),
          new NAKACK2().setValue("use_mcast_xmit", false).setValue("discard_delivered_msgs", true)
            .setValue("log_discard_msgs", false).setValue("log_not_found_msgs", false),
          new UNICAST3().setValue("xmit_table_num_rows", 5).setValue("xmit_interval", 500),
          new GMS().joinTimeout(1000).setValue("print_local_addr", false).setValue("leave_timeout", 100)
            .setValue("log_view_warnings", false).setValue("view_ack_collection_timeout", 2000)
            .setValue("log_collect_msgs", false),
View Full Code Here

TOP

Related Classes of org.jgroups.protocols.pbcast.NAKACK2$RetransmitTask

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.