Examples of AtomicBoolean


Examples of edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean

        .createQueue(QUEUE_NAME));

    // The runnable is likely to interrupt during the session#commit, since
    // this takes the longest
    final Object starter = new Object();
    final AtomicBoolean restarted = new AtomicBoolean();
    new Thread(new Runnable() {
      public void run() {
        try {
          synchronized (starter) {
            starter.wait();
          }

          // Simulate broker failure & restart
          bs.stop();
          bs = new BrokerService();
          bs.setPersistent(true);
          bs.setUseJmx(true);
          bs.addConnector(tcpUri);
          bs.start();

          restarted.set(true);
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }).start();

    synchronized (starter) {
      starter.notifyAll();
    }
    for (int i = 0; i < MESSAGE_COUNT; i++) {
      Message message = consumer.receive(500);
      assertNotNull("No Message " + i + " found", message);

      if (i < 10)
        assertFalse("Timing problem, restarted too soon", restarted
            .get());
      if (i == 10) {
        synchronized (starter) {
          starter.notifyAll();
        }
      }
      if (i > MESSAGE_COUNT - 100) {
        assertTrue("Timing problem, restarted too late", restarted
            .get());
      }

      assertEquals(i, message.getIntProperty(PROPERTY_MSG_NUMBER));
      session.commit();
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicBoolean

            catch(Throwable t) {
                log.error("couldn't deliver OOB message " + msg, t);
            }
        }

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

        // try to remove (from the AckReceiverWindow) as many messages as possible and pass them up

        // 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 concurrent 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
        boolean released_processing=false;
        try {
            while(true) {
                List<Message> msgs=win.removeMany(processing, true, max_msg_batch_size); // remove my own messages
                if(msgs == null || msgs.isEmpty()) {
                    released_processing=true;
                    return;
                }

                for(Message m: msgs) {
                    // discard OOB msg: it has already been delivered (http://jira.jboss.com/jira/browse/JGRP-377)
                    if(m.isFlagSet(Message.OOB))
                        continue;
                    try {
                        up_prot.up(new Event(Event.MSG, m));
                    }
                    catch(Throwable t) {
                        log.error("couldn't deliver message " + m, t);
                    }
                }
            }
        }
        finally {
            // processing is always set in win.remove(processing) above and never here ! This code is just a
            // 2nd line of defense should there be an exception before win.remove(processing) sets processing
            if(!released_processing)
                processing.set(false);
        }
    }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicBoolean

        private final AtomicBoolean closed;

        public StateInputStream() throws IOException {
            super();
            this.closed = new AtomicBoolean(false);
        }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicBoolean

        public StateOutputStream(Address stateRequester, String state_id) throws IOException {
            super();
            this.stateRequester = stateRequester;
            this.state_id = state_id;
            this.closed = new AtomicBoolean(false);
        }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicBoolean

     * Tests the initial-delay argument of
     * {@link TimeScheduler#scheduleWithFixedDelay(Runnable, long, long, java.util.concurrent.TimeUnit)}
     */
    @Test(dataProvider="createTimer")
    public void testSchedulerWithFixedDelay(TimeScheduler timer) {
        final AtomicBoolean set=new AtomicBoolean(false);

        Future<?> future=timer.scheduleWithFixedDelay(new Runnable() {
            public void run() {
                set.set(true);
            }
        }, 0, 3000, TimeUnit.MILLISECONDS);

        Util.sleep(500);
        future.cancel(true);

        System.out.println("variable was set: " + set);
        assert set.get();

        future=timer.scheduleWithFixedDelay(new Runnable() {
            public void run() {
                set.set(true);
            }
        }, 300, 3000, TimeUnit.MILLISECONDS);

        Util.sleep(1000);
        future.cancel(true);

        System.out.println("variable was set: " + set);
        assert set.get();
    }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicBoolean

     */
    @Test
    public void testLateStart() throws Exception {
        final Lock lock=new ReentrantLock();
        final Condition cond=lock.newCondition();
        AtomicBoolean done=new AtomicBoolean(false);

        System.out.println("-- starting first channel");
        c1=new JChannel(PROPS);
        changeMergeInterval(c1);
        c1.setReceiver(new MyReceiver("c1", done, lock, cond));
        c1.connect("demo");

        System.out.println("-- starting second channel");
        c2=new JChannel(PROPS);
        changeMergeInterval(c2);
        c2.setReceiver(new MyReceiver("c2", done, lock, cond));
        c2.connect("demo");

        System.out.println("-- starting GossipRouter");
        router=new GossipRouter(12001, bind_addr);
        router.start();

        System.out.println("-- waiting for merge to happen --");
        long target_time=System.currentTimeMillis() + 40000;
        lock.lock();
        try {
            while(System.currentTimeMillis() < target_time && done.get() == false) {
                cond.await(1000, TimeUnit.MILLISECONDS);
            }
        }
        finally {
            lock.unlock();
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicBoolean

            catch(Throwable t) {
                log.error("couldn't deliver OOB message " + msg, t);
            }
        }

        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

        // 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 concurrent 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) {
                Tuple<List<Message>,Long> tuple=win.removeMany(max_msg_batch_size);
                if(tuple == null)
                    return;
                List<Message> msgs=tuple.getVal1();
                if(msgs.isEmpty())
                    return;

                long highest_removed=tuple.getVal2();
                if(highest_removed > 0)
                    sendAck(sender, highest_removed); // guaranteed not to throw an exception !

                for(Message m: msgs) {
                    // discard OOB msg: it has already been delivered (http://jira.jboss.com/jira/browse/JGRP-377)
                    if(m.isFlagSet(Message.OOB))
                        continue;
                    try {
                        up_prot.up(new Event(Event.MSG, m));
                    }
                    catch(Throwable t) {
                        log.error("couldn't deliver message " + m, t);
                    }
                }
            }
        }
        finally {
            processing.set(false);
        }
    }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicBoolean

        // Efficient way of checking whether another thread is already processing messages from 'sender'.
        // If that's the case, we return immediately and let the existing thread process our message
        // (https://jira.jboss.org/jira/browse/JGRP-829). Benefit: fewer threads blocked on the same lock, these threads
        // can be returned to the thread pool
        final AtomicBoolean processing=win.getProcessing();
        if(!processing.compareAndSet(false, true)) {
            return;
        }

        boolean remove_msgs=discard_delivered_msgs && !loopback;
        boolean released_processing=false;
        try {
            while(true) {
                // we're removing a msg and set processing to false (if null) *atomically* (wrt to add())
                List<Message> msgs=win.removeMany(processing, remove_msgs, max_msg_batch_size);
                if(msgs == null || msgs.isEmpty()) {
                    released_processing=true;
                    if(rebroadcasting)
                        checkForRebroadcasts();
                    return;
                }

                for(final Message msg_to_deliver: msgs) {
                    // discard OOB msg if it has already been delivered (http://jira.jboss.com/jira/browse/JGRP-379)
                    if(msg_to_deliver.isFlagSet(Message.OOB) && !msg_to_deliver.setTransientFlagIfAbsent(Message.OOB_DELIVERED))
                        continue;

                    //msg_to_deliver.removeHeader(getName()); // Changed by bela Jan 29 2003: not needed (see above)
                    try {
                        up_prot.up(new Event(Event.MSG, msg_to_deliver));
                    }
                    catch(Throwable t) {
                        log.error("couldn't deliver message " + msg_to_deliver, t);
                    }
                }
            }
        }
        finally {
            // processing is always set in win.remove(processing) above and never here ! This code is just a
            // 2nd line of defense should there be an exception before win.remove(processing) sets processing
            if(!released_processing)
                processing.set(false);
        }
    }
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicBoolean

      }
   }

   public void testStreamClose() throws Exception
   {
      final AtomicBoolean closed = new AtomicBoolean(false);
      BufferingOutputStream out = new BufferingOutputStream(new ByteArrayOutputStream()
      {
         @Override
         public void close() throws IOException
         {
            closed.set(true);
            super.close();
         }
      }, 1);
      out.close();
      assertTrue(closed.get());
      try
      {
         out.write(0);
      }
      catch (IOException ignore)
View Full Code Here

Examples of java.util.concurrent.atomic.AtomicBoolean

      // Update and save
      page.setTitle("foo");
      storage_.save(page);

      //
      final AtomicBoolean go = new AtomicBoolean(false);

      // Force a cache update with the entry that will be modified
      // when the main session is closed
    
      new Thread()
      {
         @Override
         public void run()
         {
            try
            {
               begin();
               mgr.openSession();
               storage_.getPage("portal::test::test4");
               session.close();
               end();
            }
            catch (Exception e)
            {
               throw new Error(e);
            }
            finally
            {
               go.set(true);
            }
         }
      }.start();

      //
      while (!go.get())
      {
         Thread.sleep(1);
      }

      // Save the cache should be invalidated
View Full Code Here
TOP
Copyright © 2015 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.