Examples of Queue


Examples of org.jgroups.util.Queue

        queue.remove();
    }


    public static void testClear() throws QueueClosedException {
        Queue queue=new Queue();
        queue.add("one");
        queue.add("two");
        assert queue.size() == 2;
        queue.close(true);
        assert queue.size() == 2;
        queue.clear();
        assert queue.size() == 0;
        queue=new Queue();
        queue.add("one");
        queue.add("two");
        queue.clear();
        assert queue.size() == 0;
        queue.add("one");
        queue.add("two");
        assert queue.size() == 2;
        queue.clear();
        assert queue.size() == 0;
    }
View Full Code Here

Examples of org.jgroups.util.Queue

    /** Multiple threads call remove(), one threads then adds an element. Only 1 thread should actually terminate
     * (the one that has the element) */
    public static void testBarrier() throws QueueClosedException {
        RemoveOneItem[] removers=new RemoveOneItem[10];
        final Queue queue=new Queue();
        int num_dead=0;

        for(int i=0; i < removers.length; i++) {
            removers[i]=new RemoveOneItem(i, queue);
            removers[i].start();
        }

        Util.sleep(200);

        System.out.println("-- adding element 99");
        queue.add(new Long(99));
        System.out.println("-- adding element 100");
        queue.add(new Long(100));

        long target_time=System.currentTimeMillis() + 10000L;
        do {
            int num=0;
            for(int i=0; i < removers.length; i++) {
                if(!removers[i].isAlive())
                    num++;
            }
            if(num == 2)
                break;
            Util.sleep(500);
        }
        while(target_time > System.currentTimeMillis());


        for(int i=0; i < removers.length; i++) {
            System.out.println("remover #" + i + " is " + (removers[i].isAlive() ? "alive" : "terminated"));
            if(!removers[i].isAlive()) {
                num_dead++;
            }
        }

        assert num_dead == 2 : "num_dead was " + num_dead + ", but expected 2";
        queue.close(false);
    }
View Full Code Here

Examples of org.jgroups.util.Queue

    }

    /** Multiple threads call remove(), one threads then adds an element. Only 1 thread should actually terminate
     * (the one that has the element) */
    public static void testBarrierWithTimeOut() throws QueueClosedException {
        final Queue queue=new Queue();
        RemoveOneItemWithTimeout[] removers=new RemoveOneItemWithTimeout[10];
        int num_dead=0;

        for(int i=0; i < removers.length; i++) {
            removers[i]=new RemoveOneItemWithTimeout(i, 15000, queue);
            removers[i].start();
        }

        System.out.println("-- adding element 99");
        queue.add(new Long(99));
        System.out.println("-- adding element 100");
        queue.add(new Long(100));

        long target_time=System.currentTimeMillis() + 10000L;
        do {
            int num_rsps=0;
            for(int i=0; i < removers.length; i++) {
                if(removers[i].getRetval() != null)
                    num_rsps++;
            }
            if(num_rsps == 2)
                break;
            Util.sleep(500);
        }
        while(target_time > System.currentTimeMillis());

        Util.sleep(3000);

        for(int i=0; i < removers.length; i++) {
            System.out.println("remover #" + i + " is " + (removers[i].isAlive() ? "alive" : "terminated"));
            if(!removers[i].isAlive()) {
                num_dead++;
            }
        }

        assert num_dead == 2 : "num_dead should have been 2 but was " + num_dead;

        System.out.println("closing queue - causing all remaining threads to terminate");
        queue.close(false); // will cause all threads still blocking on remove() to return
        Util.sleep(500);

        num_dead=0;
        for(int i=0; i < removers.length; i++) {
            System.out.println("remover #" + i + " is " + (removers[i].isAlive()? "alive" : "terminated"));
View Full Code Here

Examples of org.jgroups.util.Queue

    /** Multiple threads add one element, one thread read them all.
     * (the one that has the element) */

    public static void testMultipleWriterOneReader() throws QueueClosedException {
        final Queue queue=new Queue();
        AddOneItem[] adders=new AddOneItem[10];
        int num_dead=0;
        int num_items=0;
        int items=1000;

        for(int i=0; i < adders.length; i++) {
            adders[i]=new AddOneItem(i, items, queue);
            adders[i].start();
        }

        Util.sleep(500);
        while(num_items < (adders.length * items)) {
            queue.remove();
            num_items++;
        }

        Util.sleep(1000);

        for(int i=0; i < adders.length; i++) {
            System.out.println("adder #" + i + " is " + (adders[i].isAlive()? "alive" : "terminated"));
            if(!adders[i].isAlive()) {
                num_dead++;
            }
        }

        assert num_dead == 10 : "num_dead should have been 10 but was " + num_dead;
        queue.close(false); // will cause all threads still blocking on peek() to return
    }
View Full Code Here

Examples of org.jgroups.util.Queue

    /**
     * Times how long it takes to add and remove 1000000 elements concurrently (1 reader, 1 writer)
     */

    public static void testConcurrentAddRemove() throws QueueClosedException {
        final Queue queue=new Queue();
        final long   NUM=1000000;
        long         num_received=0;
        Object       ret;
        long         start, stop;

        start=System.currentTimeMillis();

        new Thread() {
            public void run() {
                for(int i=0; i < NUM; i++) {
                    try {
                        queue.add(new Object());
                    }
                    catch(QueueClosedException e) {
                    }
                }
            }
        }.start();

        while(num_received < NUM) {
            ret=queue.remove();
            if(ret != null)
                num_received++;
        }
        assert num_received == NUM;
        stop=System.currentTimeMillis();
View Full Code Here

Examples of org.jgroups.util.Queue


    /** Has multiple threads add(), remove() and peek() elements to/from the queue */

    public static void testConcurrentAccess() {
        final Queue queue=new Queue();
        final int NUM_THREADS=10;
        final int INTERVAL=5000;

        Writer[] writers=new Writer[NUM_THREADS];
        Reader[] readers=new Reader[NUM_THREADS];
        int[] writes=new int[NUM_THREADS];
        int[] reads=new int[NUM_THREADS];
        long total_reads=0, total_writes=0;


        for(int i=0; i < writers.length; i++) {
            readers[i]=new Reader(i, reads, queue);
            readers[i].start();
            writers[i]=new Writer(i, writes, queue);
            writers[i].start();
        }

        Util.sleep(INTERVAL);

        System.out.println("current queue size=" + queue.size());

        for(int i=0; i < writers.length; i++) {
            writers[i].stopThread();
        }

        for(int i=0; i < readers.length; i++) {
            readers[i].stopThread();
        }

        queue.close(false); // will cause all threads still blocking on peek() to return

        System.out.println("current queue size=" + queue.size());

        for(int i=0; i < writers.length; i++) {
            try {
                writers[i].join(300);
                readers[i].join(300);
View Full Code Here

Examples of org.mule.util.queue.Queue

        {
            throw new DispatchException(CoreMessages.objectIsNull("Endpoint"), event,
                getEndpoint());
        }
        QueueSession session = connector.getQueueSession();
        Queue queue = session.getQueue(endpointUri.getAddress());
        if (!queue.offer(event, connector.getQueueTimeout()))
        {
            // queue is full
            throw new DispatchException(VMMessages.queueIsFull(queue.getName(), queue.size()),
                    event, getEndpoint());
        }
        if (logger.isDebugEnabled())
        {
            logger.debug("dispatched MuleEvent on endpointUri: " + endpointUri);
View Full Code Here

Examples of org.objectweb.joram.client.jms.Queue

      if (refAddr == null) break;

      strbuf.setLength(0);
      strbuf.append("cluster#").append(i).append(".destName");
      if (isQueue()) {
        dest = new Queue((String) ref.get(strbuf.toString()).getContent());
      } else {
        dest = new Topic((String) ref.get(strbuf.toString()).getContent());
      }
      cluster.put((String) refAddr.getContent(), dest);
      i++;
View Full Code Here

Examples of org.objectweb.joram.client.jms.Queue

      if (key == null) break;

      strbuf.setLength(0);
      strbuf.append("cluster#").append(i).append(".destName");
      if (isQueue()) {
        dest = new Queue((String) h.get(strbuf.toString()));
      } else {
        dest = new Topic((String) h.get(strbuf.toString()));
      }
      cluster.put(key, dest);
      i++;
View Full Code Here

Examples of org.objectweb.joram.client.jms.Queue

      QueueTcpConnectionFactory.create("localhost", 16010);
    javax.jms.TopicConnectionFactory tcf =
      TopicTcpConnectionFactory.create("localhost", 16010);

    Topic tOrders = Topic.create(0);
    Queue qItems = Queue.create(0);
    Queue qCheck = Queue.create(0);
    Queue qChecked = Queue.create(0);
    Queue qBills = Queue.create(0);
    Queue qDelivery = Queue.create(0);

    // Setting access permissions:
    tOrders.setWriter(web);
    tOrders.setReader(billing);
    tOrders.setReader(inventory);
    tOrders.setReader(customer);
    qCheck.setWriter(billing);
    qCheck.setReader(control);
    qChecked.setWriter(control);
    qChecked.setReader(billing);
    qBills.setWriter(billing);
    qBills.setReader(customer);
    qItems.setWriter(inventory);
    qItems.setReader(customer);
    qDelivery.setWriter(customer);
    qDelivery.setReader(delivery);

    // Binding objects in JNDI:
    javax.naming.Context jndiCtx = new javax.naming.InitialContext();
    jndiCtx.bind("qcf", qcf);
    jndiCtx.bind("tcf", tcf);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.